Valhalla Legends Forums Archive | Visual Basic Programming | Bug annoying me!

AuthorMessageTime
GoSu_KaOs
Ok, ths is another messed up code that I need help with.
I want this code to add everything from Combo1 to Saved.txt.
When the Combo Box has stuff added, and I type something thats not in Saved.txt, then hit Save, the new and old items are added to Saved.txt.

If the Load_Form() loads "Item1" to the combo box, then I click on "Item1", then I type "Item2" in the combo box and hit Save, the "Item1" is replaced by "Item2".

How can I prevent this?

This is the code I used:

[code]Pirvate Sub Save_Click()

Dim i As Integer
Combo1.AddItem Combo1.Text
    Close #1 ' Closes the file just incase it's already open.
      Open (App.Path & "\Saved.txt") For Output As #1
        For a = 1 To Combo1.ListCount
        Print #1, Combo1.List(i)
        Next i
    Close #1

End If

Private Sub Form_Load()

Close #1

    Open (App.Path & "\Saved.txt") For Input As #1
 
    Dim z As String
    On Error Resume Next
        Do
          Input #1, z
          Combo1.AddItem (z)
          Loop Until EOF(1)
        Close #1

End If[/code]
December 3, 2004, 2:26 AM
Quarantine
If I read correctly you need to open a file for append
December 3, 2004, 2:41 AM
drivehappy
Try:

[code]
Print #1, Combo1.List(i-1)
[/code]
December 3, 2004, 3:57 AM
LivedKrad
Warrior is right, you'll need to append to add items into a file while preserving the old. And another note, would that loop cause problems if you're using an undeclared variable as an increment counter? Also, maybe the problem is that "Pirvate" isn't a valid status for an event? :P

What is interesting though is that you seem to be adding everything that currently exists in the file, into the Combobox. Try this: place a few items into the text file row by row. Put in about, 5. Then run your program. Do not add a new item. Click the "Save" button, and see if the items are still there. If they are, then you know all you'd have to do is use the Append option.
December 4, 2004, 3:10 PM

Search