|
-
Nov 13th, 2000, 11:54 AM
#1
Thread Starter
New Member
This is what I have so far and it works for adding an item to the combo box however it doesnt save. Once the program is restarted the item added to the box is gone...Help.
Any help is appreciated for another newbie.
Private Sub Combo1_Click()
Dim Message, Title, Default, retval, MyValue
If Combo1.Text = "OTHER" Then
Message = "Enter Item to add" ' Set prompt.
Title = "Adding an Item" ' Set title.
Default = "" ' Set default.
' Display message, title, and default value.
MyValue = InputBox(Message, Title, Default)
Combo1.AddItem MyValue
End If
-
Nov 13th, 2000, 12:09 PM
#2
Addicted Member
You need to save the item to a file,
And when you start the program load the combo box with the stuff in the file here's some code
Private Sub Combo1_Click()
Dim Message, Title, Default, retval, MyValue
If Combo1.Text = "Combo1" Then
Message = "Enter Item to add" ' Set prompt.
End If
Title = "Adding an Item" ' Set title.
Default = "" ' Set default.
' Display message, title, and default value.
MyValue = InputBox(Message, Title, Default)
Combo1.AddItem MyValue
Open "c:\mytestfile.txt" For Output As 1
Print #1, MyValue
Close
End Sub
Private Sub Form_Load()
Open "c:\mytestfile.txt" For Input As 1
Do While Not EOF(1)
Input #1, MyValue
Combo1.AddItem MyValue
Loop
Close
End Sub
-
Nov 13th, 2000, 12:42 PM
#3
While Bjwbell's suggestion is one way of doing it, data for comboboxes, listboxes, etc are usually saved in a database. Think about what you would have to do if you had 10 comboboxes.
-
Nov 13th, 2000, 02:44 PM
#4
Thread Starter
New Member
Thanks for the replies I suspected it may require a database of some kind, however I thought, as it's going to be quite a small program, with only a limited amount of input needed in each list or combobox that there might be an easy solution. Guess I've got some more learning to do.
Thanks.
-
Nov 13th, 2000, 03:04 PM
#5
Databases are not hard to use and so I suggest you take the plunge. You'll find that many of your programs will need a database and it's better to start with what you say is a small program. BTW, there are basically two ways to use databases. One way is via databound controls and the other is via ADO or DAO. While the databound controls are the easiest to begin with, my suggestion is to use ADO because the problem with the databound controls is that while they do a lot of work for you, you will eventually come to something that they can't do, and you may already have a large program that has been built around them. Consider that "one man's opinion" since I'm sure there are people out there who have had no problems with the databound controls.
On another subject, you should change your Dim Message, Title, Default, retval, MyValue line. That line defines four variables with a type of Variant, and variants are both large and slow. Better would be:
Dim strMessage As String
Dim strTitle As String
Dim strDefault As string
'Dim retval As ??? (you don't seem to use this one)
Dim strMyValue As String
Note that I've added "str" to the names so you'll know without having to think about it that they are strings. (Other prefixes are int, lng, dbl, cbo, etc.)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|