Results 1 to 7 of 7

Thread: Listbox values

  1. #1
    Guest

    Question

    Güten abends.

    I could use some help on how to define a value for a ListBox choice. I've started making a little program called Message Maker, where I construct Windows dialouges.
    some example code:

    MsgBox txtMessage, ,txtTitle

    As you can see I got the values I need for the Title and the message, but I still need to know how too get a value out of a listbox and putting it in there between the commas.
    For example I have a value in a listbox called "OK", I want that value type in vbOkOnly between the commas.
    Does anybody know how to? BTW, is there any good beginners forums around?

  2. #2
    Guest

    Unhappy

    Hey!

    Guys (and girls), I really need to know how to do this, and it's quite urgent.. Maybe I should refraze the question a little
    I need to know how to make ListBox choice to put in the string = vbOkOnly in a line of code. I want it to look like this:

    Code:
    MsgBox "Message", vbOkOnly,"Title"
    Please reply, even if you don't know what the heck you're talking about, reply anyway.

  3. #3
    Member Visual Programmer's Avatar
    Join Date
    Dec 2000
    Posts
    59
    from what i understood, a think this is what you need:

    Code:
    Private Sub Command1_Click()
        If List1.Text = "vbOkOnly" Then
            MsgBox "message", vbOKOnly, "Title"
        Else
            If List1.Text = "VbYesNo" Then
                MsgBox "Message", vbYesNo, "title"
                'etc........
            End If
        End If
    End Sub
    VP/Sonic taking on the (vb) world, one post at a time.

  4. #4
    Guest

    Thumbs up Danke schön

    Thanks for the tip, there's gonna be alot o Ifs, do you think I can do it with the Select Case thingie? I'll just go ahead and try it.

  5. #5
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Sure, why not?
    Code:
    Select Case List1.Text
        Case "vbOkOnly"
            MsgBox "message", vbOKOnly, "Title"
        Case "VbYesNo"
                MsgBox "Message", vbYesNo, "title"
    End Select
    A tip for Visual Programmer:
    ElseIf
    Code:
    Private Sub Command1_Click()
        If List1.Text = "vbOkOnly" Then
            MsgBox "message", vbOKOnly, "Title"
        ElseIf List1.Text = "VbYesNo" Then
                MsgBox "Message", vbYesNo, "title"
                'etc........
        End If
    End Sub
    Have fun both of you
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  6. #6
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Actually, you don't need to test with Ifs or Select Case. Whatever the user selected in the listbox can be read with the Listbox's Text property (or with the List array property). In other words, you can reference the user's selection either as
    List1.Text
    - or -
    List1.List(List1.ListIndex)

    So your code can be;
    Code:
    MsgBox "message", List1.Text, "Title"
    "It's cold gin time again ..."

    Check out my website here.

  7. #7
    Guest

    Wink

    Hello,

    Try this code in the ListBox click event:

    Select Case lst1.ListIndex
    Case 0
    MsgBox "message", vbOKOnly, "Title"
    Case 1
    MsgBox "message", vbOKCancel, "Title"
    End Select
    End Sub

    Use the AddItem method in the FormLoad event to fill
    the ListBox with vbOKOnly,vbOKCancel, etc. Then just
    click on the one you want to use.

    Good luck





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