Author | Message | Time |
---|---|---|
ramu_s | Hi I am very new to VB, I want to develop a combo box or list box - when ever the user want to add the item to the combo box or list box- they have to type the item in the below text box then pressing the command button- it have to save in the combo/list box. I am using the following code Private Sub Command1_Click() Combo1.AddItem (Text1.Text) End Sub This adding the item in the combo box but when I close and reopen all gone!!!!! But I know through form load we can add item but the normal user want to enter the item in the text box and save in the combo box Any one can help me please ramu_s@hotmail.com Regards Ramu | August 26, 2004, 12:34 PM |
The-Rabid-Lord | When the form is unloaded it must be written to a file, like a text file named combo.txt or something. There should be code around to do it. | August 26, 2004, 5:22 PM |
ramu_s | Hi Meh Thanks, is it possible to explain me more? :- pls Regards Ramu | August 27, 2004, 2:07 AM |
Eli_1 | Let me break down his explination... Kinda. :P [code] On Form Load() Open up the text file, containing the items, for input Do Store the next line, in the text file, in a buffer If the buffer isn't empty, add it to the listbox Loop until EOF (end of file) Close the text file End Sub . . . Allow the user to add items to the listbox . . . On Form Unload() Open the text file for output For i = 0 to the amount of items in the listbox - 1 Print the item(i) to the text file Next i Close the text file End Sub [/code] | August 27, 2004, 2:29 AM |
ramu_s | Thanks Kinda Will try based on your help, I don't how far I can reach!!!! Thanks again Ramu | August 27, 2004, 3:31 AM |
SPY-3 | [quote author=ramu_s link=board=31;threadid=8377;start=0#msg77390 date=1093523694] Hi I am very new to VB, I want to develop a combo box or list box - when ever the user want to add the item to the combo box or list box- they have to type the item in the below text box then pressing the command button- it have to save in the combo/list box. I am using the following code Private Sub Command1_Click() Combo1.AddItem (Text1.Text) End Sub This adding the item in the combo box but when I close and reopen all gone!!!!! But I know through form load we can add item but the normal user want to enter the item in the text box and save in the combo box Any one can help me please ramu_s@hotmail.com Regards Ramu [/quote] if you want the easiest way then add this to a module Public Sub LoadList(List As ListBox, FileLocation As String) Dim sText As String Dim LoadTheList LoadTheList = FreeFile On Error GoTo Make: Open FileLocation For Input As #LoadTheList Do Until EOF(1) Input #LoadTheList, sText sText = Replace(sText, "%Comma/", ",") List.AddItem sText Loop Close #LoadTheList Exit Sub Make: Dim MakeTheList MakeTheList = FreeFile Open FileLocation For Output As #MakeTheList Close #MakeTheList LoadList List, FileLocation End Sub Public Sub SaveList(List As ListBox, SaveTo As String) Dim sText As String Dim SaveTheList SaveTheList = FreeFile Open SaveTo For Output As #SaveTheList For x = 0 To List.ListCount - 1 sText = Replace(List.List(x), ",", "%Comma/") Print #SaveTheList, sText Next x Close #SaveTheList End Sub then call on it like this Private Sub Form_Load() LoadList combo1, app.path & "\somefile.txt" End Sub Private Sub Form_Unload() savelist combo1, app.path & "\somefile.txt" End Sub if you do this then you will be able to have the form save things and load things when it opens/closes hope this helps. | August 27, 2004, 12:39 PM |