Results 1 to 10 of 10

Thread: Need help with several things about text files

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Need help with several things about text files

    Okay. lets say in a text file, i have:
    10/10/10, 11/12/13, 10/20/21,
    all on one line. how can i get it to do the following:
    1)Seperate each date and put it into a listbox
    2)Seperate each date and put it into a variable

    I am stuck... Please help. Also, is there a way in vb6 to export several listboxes to a spreadsheet file? if so, how? Thanks!
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Need help with several things about text files

    Try this:

    vb Code:
    1. Private Sub Command1_Click()
    2. Dim str As String
    3. Dim i As Integer
    4. Dim entry As String
    5. ff = FreeFile
    6.  
    7. Open App.Path & "\test.txt" For Input As #ff
    8. For i = 0 To Len(ff) + 1
    9. Input #ff, entry
    10. List1.AddItem entry
    11. str = entry
    12. Next i
    13. MsgBox (str)
    14. Close #ff
    15. End Sub
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: Need help with several things about text files

    o.o What the heck... Okay. I want multiple entries... Not just one.. Like if i had multiple dates... And on top of that, have no idea what that codes does... Well.. Have some idea. What does the Len(ff) do?
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  4. #4
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Need help with several things about text files

    Quote Originally Posted by Gamemaster1494 View Post
    o.o What the heck... Okay. I want multiple entries... Not just one.. Like if i had multiple dates... And on top of that, have no idea what that codes does... Well.. Have some idea. What does the Len(ff) do?
    Have you tested the code? It works with multiple entries! The len(ff) is the maximum number of entries in the file.

    Edit:

    To change the number of entries that appear, change the 1 to a different number. Say you have 30 entries in the file change the number "1" to "29". This value is the iteration value for the for cycle meaning how many times do you want it to run.
    Last edited by Nightwalker83; Oct 3rd, 2010 at 08:24 PM. Reason: Adding more!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: Need help with several things about text files

    Yeah. it works... now how can i make it do that at certain entries? Like if the txt file had:
    Jacob
    Pouring
    Noway
    10/10/10, 10/11/10, 10/12/10,
    OkayIGetIt

    Only have it to do it at line 4? and do something else for the others?
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  6. #6
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Need help with several things about text files

    You could add this code just before the next.

    vb Code:
    1. If i = 4 Then
    2. List1.AddItem entry
    3. str = entry
    4. End If
    Last edited by Nightwalker83; Oct 3rd, 2010 at 09:12 PM. Reason: Fixed spelling!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: Need help with several things about text files

    Okay. So what code is it that separates it?
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  8. #8
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Need help with several things about text files

    The conditional statement checks to see which value of entry you you want to add to the list box and if the value matches it adds it to the list box.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: Need help with several things about text files

    um... okay.... Hmmm.... So... How would i get it to where like the txt file says:
    10/10/10, 21/10/10, 21/11/10
    for example. and i want
    variable(1) = 10/10/10, variable(2) = 21/10/10, variable(3) = 21/11/10
    Is there a way to do that?
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  10. #10
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Need help with several things about text files

    Try this:
    vb Code:
    1. Private Sub Command1_Click()
    2. Dim x As Integer
    3. Dim sInputArr() As String
    4. Dim i As Integer
    5. Dim a As Integer
    6. Dim entry As String
    7. ff = FreeFile
    8.  
    9. Open App.Path & "\test.txt" For Input As #ff
    10. For i = 0 To Len(ff) + 5
    11. Input #ff, entry
    12.    If i = 3 Or i = 4 Or i = 5 Then
    13.    List1.AddItem entry
    14. 'Split up the String into the Array
    15.    If InStr(entry, ",") Then   'More than 1 word, so split
    16.       sInputArr = Split(entry, ",")
    17.    Else
    18.       ReDim sInputArr(i) 'Only 1 word, so place it in the Array
    19.       sInputArr(i) = entry
    20.       MsgBox (sInputArr(i))
    21.          End If
    22. End If
    23. Next i
    24. Close #ff
    25. End Sub
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width