Adblock breaks this site

Combo box addressing need help!

Discussion in 'Programming General' started by Visual Basic Matt, Jun 16, 2008.

  1. Visual Basic Matt

    Visual Basic Matt Apprentice

    Joined:
    Jan 29, 2008
    Posts:
    647
    Referrals:
    2
    Sythe Gold:
    56
    Discord Unique ID:
    223154494878253056
    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. :)
     
  2. Jazz00006

    Jazz00006 Apprentice
    Visual Basic Programmers

    Joined:
    Aug 26, 2005
    Posts:
    807
    Referrals:
    0
    Sythe Gold:
    0
    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
     
  3. Visual Basic Matt

    Visual Basic Matt Apprentice

    Joined:
    Jan 29, 2008
    Posts:
    647
    Referrals:
    2
    Sythe Gold:
    56
    Discord Unique ID:
    223154494878253056
    Combo box addressing need help!

    Thank you very much now i can move on with my project!
     
  4. Swan

    Swan When They Cry...
    Retired Global Moderator

    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner
    Combo box addressing need help!

    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?
     
  5. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    Combo box addressing need help!

    Swan, you're close
    Code:
    Dim intFileNum as Integer
    intFileNum = FreeFile
     
  6. Jazz00006

    Jazz00006 Apprentice
    Visual Basic Programmers

    Joined:
    Aug 26, 2005
    Posts:
    807
    Referrals:
    0
    Sythe Gold:
    0
    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.
     
  7. Swan

    Swan When They Cry...
    Retired Global Moderator

    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner
    Combo box addressing need help!

    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.
     
< Need up to date hiscores lookup! | Benchmark test - VB6/VC6/Delphi6/Java >


 
 
Adblock breaks this site