Results 1 to 5 of 5

Thread: More newbie stuff

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    6
    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

  2. #2
    Addicted Member
    Join Date
    Jul 2000
    Location
    California
    Posts
    154
    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



  3. #3

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    6

    Smile

    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.
    So....I'm new

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    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
  •  



Click Here to Expand Forum to Full Width