• Welcome to Valhalla Legends Archive.
 

Bug annoying me!

Started by GoSu_KaOs, December 02, 2004, 08:26 PM

Previous topic - Next topic

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:

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

Warrior

If I read correctly you need to open a file for append
Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?

drivehappy

Try:


Print #1, Combo1.List(i-1)


LivedKrad

#3
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.