(VB 2005) Read from txt

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dreadful
    New Member
    • Feb 2007
    • 2

    #1

    (VB 2005) Read from txt

    I've got multiple Text Boxes and when I click a Button the TextBoxes.Text writes inside of a .txt file.
    It works fine, exactly how I want it to look:

    Code:
    FileOpen(1, "C:\Blah\Blah\Blah\Test01.txt", OpenMode.Output)
    PrintLine(1, TextBox1.Text)
    PrintLine(1, TextBox2.Text)
    PrintLine(1, TextBox3.Text)
    FileClose(1)
    This is what I see when I open the .txt file (example, not actual values):
    Code:
    1234
    567
    89
    That's good, it's exactly how i want things to look.
    Now for I can't figure out...
    I want to, let's say, have:
    Label4.Text = [1st line of the .txt file]
    Label5.Text = [2nd line of the .txt file]
    Label6.Text = [3rd line of the .txt file]
    But things get screwy when i use:
    Code:
    FileOpen(1, "C:\Blah\Blah\Blah\Test01.txt", OpenMode.Input)
    Label4.Text = InputString(1, 4)
    Label5.Text = InputString(1, 3)
    Label5.Text = InputString(1, 2)
    FileClose(1)
    It takes into account [Return] as 2 characters long and doesn't display things how I'd like to see them.
    Each row will be 1,2,3 or 4 characters long, so using "InputStrin g(1, 4)" for taking the first 4 characters wont always be acurate.

    Any chance there's a way to say:
    Label4.Text = [Row1, Column1-4]
    Label5.Text = [Row2, Column1-4]
    Label6.Text = [Row3, Column1-4]
    and if theres only 2 characters on the line, only display 2 characters?
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    You can read the line of text into another string and use other functions to get what you want such as Left(mystr, 4) or Right(mystr, 3)

    Comment

    • Dreadful
      New Member
      • Feb 2007
      • 2

      #3
      Alright! I've got the things working how I want it so far! But now another twist. I've got 3 clumps of data I'd like to save to one single file. So I would kind of like to see my .txt file to look like:
      Code:
      Data Set 1
      123
      456
      789
      
      Data Set 2
      987
      654
      321
      
      Data Set 3
      147
      258
      369
      The thing is, I will only be saving one 'Data Set' at a time and I don't want to overwrite the existing other 2 data sets. The way I've got mine set up will overwrite the entire document with the 'Data Set' I'm currently trying to save. So when I click [Save Set 2], the .txt file will be completely erased and only save 'Data Set 2'. I'd like to only change '987' '654' '321' when I select Save and leave the rest of the file in tact. I'd appreciate any more help from someone, thank you in advance!

      Comment

      Working...