Saving and Retrieving Info From File and Populating List Box

Posted on 2005-04-04
Medium Priority
Last Modified: 2010-05-02
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.


Question by:alangsk
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Assisted Solution

dr_binks earned 200 total points
ID: 13704714
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

LVL 32

Accepted Solution

Robberbaron (robr) earned 300 total points
ID: 13706600

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.
    open "filename" for input as #fhn

Author Comment

ID: 13712149
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.
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 13715496
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
        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

Author Comment

ID: 13726980
Thank you to both dr binks and robberbaron!

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question