Saving and Retrieving Info From File and Populating List Box

I am creating a web browser and would like to populate a list box using an external file (i.e. text file).  However, I would like to store the information as follows:  Nickname, URL Address, Scroll Pos X, Scroll Pos Y.  This way when scrolling to a certain position on a certain page, I will be able to save that position.  When I click the favorites command button, I would like it to populate the text box from this file only showing the nickname.  Then when the nickname is selected, it would navigate to the url and to the scroll position.  The navigation and scroll position part I can do, but how can I write and read in this format.  Please help.

Thanks,

Kyle
alangskAsked:
Who is Participating?
 
Robberbaron (robr)Connect With a Mentor Commented:

VB uses commas to separate fields in text files.

And you should use  

  write #1,Nickname, URLAddress, ScrollPosX, ScrollPosY

as this surrounds text with quotes so that the text can contain commas. ie "test1,2,3","http://ssd.com",1234,5678

I think you may have to use the .tag property when loading the listbox as this can assocoiate additional information with the list item.
        list1.additem nickname
        list1(list1.listindex).tag=url & ";" & scrollx & ";" & scrolly

you can then split the tag apart when a list item is selected.


To remove a posible error, you should create a new filehandle to open the file as #1 may already be in use somewhere.
    fhn=freefile
    open "filename" for input as #fhn
      .....    
0
 
dr_binksConnect With a Mentor Commented:
open "filename" for output as #1
  ''you can loop here if you want
  print #1 Nickname, URLAddress, ScrollPosX, ScrollPosY
close #1


open "filename" for input as #1
    ''you can loop here if you want
  input #1 Nickname, URLAddress, ScrollPosX, ScrollPosY
close #1

using the commas when writting will put the data on the same line and split it with tabs (I think its tabs)

hope that helps

~Binks
0
 
alangskAuthor Commented:
robberbaron,
How do you split the tag apart when the item is selected?  I got it to read the text file, but how do I split the tag now so that I can do something with it?  Thanks for the help.
0
 
Robberbaron (robr)Commented:
If you are using VB6, I think the split function is available.

I'm on VB5 and have written a Parse function to do this.
'---------
Function Parse(inputline As String, sepchar As String, outarray() As String) As Integer

    Dim a As Integer, cnt As Integer, lastchar As Integer
    Dim skipspace As Boolean
   
    'add a separator to end of string to ack as
    '   end marker
    inputline = inputline + sepchar
    cnt = 0
    'count number of sepchars
    For a = 1 To Len(inputline)
        If Mid$(inputline, a, Len(sepchar)) = sepchar Then
            cnt = cnt + 1
        End If
    Next a
   
    'redimesion the array large enough to hold max
    '  possible chunks, separated by at least one
    '  sepchar
    ReDim outarray(cnt)
   
    lastchar = 0: cnt = 0: skipspace = False
    a = 1
    Do
        If Mid$(inputline, a, Len(sepchar)) = sepchar And Not skipspace Then
            If a - lastchar > 1 Then
                'found a chunk
                cnt = cnt + 1 'add to chunk counter
                outarray(cnt) = Trim(Mid$(inputline, lastchar + 1, a - lastchar - 1))
            End If
            lastchar = a  'update last found
         ElseIf Mid$(inputline, a, 1) = Chr$(34) Then
            skipspace = Not (skipspace)
        End If
        a = a + 1
    Loop While a <= Len(inputline)
           
    ReDim Preserve outarray(cnt)
   
    Parse = cnt
   
End Function
0
 
alangskAuthor Commented:
Thank you to both dr binks and robberbaron!
0
All Courses

From novice to tech pro — start learning today.