• Log in or sign up for an account here: https://www.sythe.org/login

Combo box addressing need help!

Visual Basic Matt

Apprentice
Joined
Jan 29, 2008
Sythe Gold
56
Messages
647
Location
Evurar
Combo box addressing need help!
Im making a part in my program where is saves visited adresses the only part i need help with is saving them heres what i got.

How do i make this work? I took it from my note book in my program.

Code:
Private Sub Form_Load()
Open App.Path & "\pages.dat" For Input As #1
    Do While Not EOF(1)
        If Combo1.Text = "" Then
            Line Input #1, inputline
            Combo1.Text = inputline
        Else
            Line Input #1, inputline
            Combo1.Text = Combo1.Text & vbCrLf & inputline
        End If
    Loop
Close #1
End Sub

Private Sub Form_Unload(Cancel As Integer)
Open App.Path & "\pages.dat" For Output As #1
    Print #1, Combo1.Text
Close #1
End Sub

When you visit web pages it will keep track of them.
I know how to add the pages visited to the combo but how do i save each line of the combo box to the pages.dat document? And how do i get it to load it all. Please tell me how to code this.
Thank you. :)
 
Combo box addressing need help!
You almost had it.

You just needed to loop through the items saved in the combo box. Please excuse the mess, it's been a long time since I coded anything in VB6 and I wrote this free hand.


Code:
Private Sub Form_Load()
Dim strBuff As String
On Error GoTo err
    Open App.Path & "\pages.dat" For Input As #1
        Do Until EOF(1)
            Line Input #1, strBuff
            If strBuff <> "" Then Combo1.AddItem strBuff
        Loop
    Close #1
    
err:
'If err.Number = 53 Then 'File not found
End Sub

Private Sub Form_Unload(Cancel As Integer)
Dim i As Integer
    Open App.Path & "\pages.dat" For Output As #1
        For i = 0 To Combo1.ListCount
            Print #1, Combo1.List(i)
        Next i
    Close #1
End Sub
 
Combo box addressing need help!
You almost had it.

You just needed to loop through the items saved in the combo box. Please excuse the mess, it's been a long time since I coded anything in VB6 and I wrote this free hand.


Code:
Private Sub Form_Load()
Dim strBuff As String
On Error GoTo err
    Open App.Path & "\pages.dat" For Input As #1
        Do Until EOF(1)
            Line Input #1, strBuff
            If strBuff <> "" Then Combo1.AddItem strBuff
        Loop
    Close #1
    
err:
'If err.Number = 53 Then 'File not found
End Sub

Private Sub Form_Unload(Cancel As Integer)
Dim i As Integer
    Open App.Path & "\pages.dat" For Output As #1
        For i = 0 To Combo1.ListCount
            Print #1, Combo1.List(i)
        Next i
    Close #1
End Sub
I would like to point out in your comment
Code:
'If err.Number = 53 Then 'File not found
Wouldn't be smart to use, if you did indeed use it; "magic numbering" of anything, be it keycodes or errors, leads to confusion.

Also, with your file output. I am no Visual Basic professional (indeed I haven't used it for a very long time) though I do remember what is called FreeFile (I'm not sure what you would define it as. It doesn't look like a function, but it wouldn't be a keyword).

Code:
Dim file = FreeFile
Open App.Path & "\pages.dat" For Input As file
' ...
Close file

Not sure if that is correct, though there is something called FreeFile which is probably best used. What if #1 was already in use, for example?
 
Combo box addressing need help!
Yup correct on both accounts swan, thankyou for pointing those out :P
But handling errors based on the numbers can give a better error handler, instead of having Msgbox "Error lol" you can customize a response based on the error generated.

Granted there are times when you can skip having the error numbers, but user friendly error handling is valued in commercial programs.
 
Combo box addressing need help!
Yup correct on both accounts swan, thankyou for pointing those out :P
But handling errors based on the numbers can give a better error handler, instead of having Msgbox "Error lol" you can customize a response based on the error generated.

Granted there are times when you can skip having the error numbers, but user friendly error handling is valued in commercial programs.
Doesn't the language offer an Error class or at least a series of functions to work with?

Ah yes, Covey - I forgot VB didn't support dynamic initialization.
 
Runescape Gamblingrunescape gambling
Back
Top