Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Regular Coder
    Join Date
    Jan 2004
    Location
    Georgia
    Posts
    306
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Visual Basic: dropdown menus

    I need to know how to put info into a dropdown box i have created and put what the user selects from the list in a textbox i have made
    ~Designer's Toolz~

  • #2
    Super Moderator sage45's Avatar
    Join Date
    May 2002
    Posts
    1,060
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Are you talking vbscript or VB???

    Is the option list generated dynamically or known???

    -sage-
    HTML & CSS Forum Moderator

    "If you don't know what you think you know, then what do you know."
    R.I.P. Derrick Thomas #58
    1/1/1967 - 2/8/2000

  • #3
    Regular Coder
    Join Date
    Jan 2004
    Location
    Georgia
    Posts
    306
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry for not making this clear. anyway this is vb not vbscript. Basicaly im making a html editor and im going to use drop down boxes to insert tags into a text box...
    ~Designer's Toolz~

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    1,137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you basically put it in the form onload part or anywhere you want to add the items.

    dropdownname.additem "boo"

    or

    dropdownname.additem boo

    you can also use the with statement
    Code:
    with dropdownname
            .additem "h"
            .additem "g"
            .additem "e"
            .additem "4"
            .additem "o"
    
    end with
    scroots
    Spammers next time you spam me consider the implications:
    (1) that you will be persuaded by me(in a legitimate mannor)
    (2)It is worthless to you, when i have finished

  • #5
    Regular Coder
    Join Date
    Jan 2004
    Location
    Georgia
    Posts
    306
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry i dont understand.....this is my first vb program and your gonna have to explain every detail..sorry
    ~Designer's Toolz~

  • #6
    New Coder
    Join Date
    Jan 2004
    Location
    Boston, MA
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Here's the short and sweet.

    Real quickly, your dropdown is referred to as a Combo box you add whatever you want it to display with the following code. Assume you named your combo box "cmbMyShortList":

    Code:
    cmbMyShortList.AddItem "Books"
    cmbMyShortList.AddItem "Cars"
    cmbMyShortList.AddItem "Computers"
    Put this code somewhere in your Form_Load Handler.

    Then you would put something like this into your cmbMyShortList_Change event handler:

    Code:
    txtMyFavorites = txtMyFavorites & cmbMyShortList.Text
    Now I don't know if that last part works quite right, but I do know that the first block of code works great.

  • #7
    Super Moderator sage45's Avatar
    Join Date
    May 2002
    Posts
    1,060
    Thanks
    0
    Thanked 13 Times in 13 Posts
    If however, you are generating a dynamic list as opposed to a static list, I would use the following:

    Code:
    Option Explicit
    'Global Variables
    
    Public Sub LoadCombo(Combo As ComboBox, FileSpec As String, Section As String)
        On Error GoTo Errors
        Dim strRet As String, strRetVal As String, lngBufLen As Long, lngRet As Long
        Combo.Clear
        Do
            lngBufLen = lngBufLen + 1024
            strRet = String$(lngBufLen, vbNullChar)
            lngRet = GetPrivateProfileStringA(Section, vbNullString, "", strRet, lngBufLen, FileSpec)
        Loop Until lngRet < lngBufLen - 2
        strRet = Left$(strRet, lngRet - 1)
        
        Dim strArray() As String
        strArray = Split(strRet, vbNullChar)
        For lngRet = 0 To UBound(strArray)
            Combo.AddItem strArray(lngRet)
        Next lngRet
        Combo.ListIndex = 0
    Errors:
        If Err.Number <> 0 Then
            MsgBox ("Error #:" & Str(Err.Number) & Err.Description)
            Exit Sub
        End If
    End Sub
    
    LoadCombo cboList1, Path + "/tmp1.tmp", "INISection"
    Con to this is it uses a file... However, I have used it successfully where I have created and populated a file with the information dynamically then called the information into the combo box with the code above...

    HTH,

    -sage-
    HTML & CSS Forum Moderator

    "If you don't know what you think you know, then what do you know."
    R.I.P. Derrick Thomas #58
    1/1/1967 - 2/8/2000

  • #8
    Regular Coder
    Join Date
    Jan 2004
    Location
    Georgia
    Posts
    306
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok lets start over here and ill explain every detail


    i want to be able to select an HTML code from a list in a combo box(Combo3) and it paste what you select from that combo box(Combo3) into a RichTextBox (rtfText)



    help me please, this is my first program. im gonna need more help after i get this worked out, thank you all very much.
    ~Designer's Toolz~

  • #9
    Senior Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    1,137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    double click on the combo box and then pick onchange from the dropdown.

    enter the following

    rtfText=rtfText + Combo3


    to add an item to the drop down, double click on the form and then pick onLod from the list in the code editor and then just add in

    Combo3.additem "Item1"
    Combo3.additem "Item2"
    Combo3.additem "Item3"
    Combo3.additem "Item4"


    scroots
    Spammers next time you spam me consider the implications:
    (1) that you will be persuaded by me(in a legitimate mannor)
    (2)It is worthless to you, when i have finished

  • #10
    Regular Coder
    Join Date
    Jan 2004
    Location
    Georgia
    Posts
    306
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you so much. It adds to the list but now theres a problem.



    compile error:
    Assignment To Constant not permitted.



    and it points me to...




    Private Sub Combo3_Change()
    rtfText = rtfText + Combo3
    End Sub



    and highlights what i have underlined:

    Private Sub Combo3_Change()
    rtfText = rtfText + Combo3
    End Sub
    ~Designer's Toolz~

  • #11
    Super Moderator sage45's Avatar
    Join Date
    May 2002
    Posts
    1,060
    Thanks
    0
    Thanked 13 Times in 13 Posts
    The compiler is saying you can't assign the information to a Constant...

    A constant is just what it's name implies, Constant, not changing... Variables are allowed to be modified and changed through the process of the application...

    Try using:

    Dim rftText As String

    HTH,

    -sage-
    HTML & CSS Forum Moderator

    "If you don't know what you think you know, then what do you know."
    R.I.P. Derrick Thomas #58
    1/1/1967 - 2/8/2000

  • #12
    Senior Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    1,137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    look in your code for

    Const rtfText

    as that is setting it as a constant wheras it doesn't need to be as its a textbox on a page and doesn't need to be declared.

    scroots
    Spammers next time you spam me consider the implications:
    (1) that you will be persuaded by me(in a legitimate mannor)
    (2)It is worthless to you, when i have finished

  • #13
    Regular Coder
    Join Date
    Jan 2004
    Location
    Georgia
    Posts
    306
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i tried using:

    Dim rftText As String

    no errors, but it doesnt add what you select in the dropdown to the text box...



    i looked in my code for Const rtfText and didnt see that.


    Maybe I should point out my textbox and my combo boxes are on two seperate forms.



    what now?
    Thanks
    ~Designer's Toolz~

  • #14
    Super Moderator sage45's Avatar
    Join Date
    May 2002
    Posts
    1,060
    Thanks
    0
    Thanked 13 Times in 13 Posts
    In that case then, on the form where your combo box resides, use this:

    frmname.rtfText = frmname.rtfText + Combo3

    Where 'frmname' is the name of the form that rtfText is residing on...

    HTH,

    -sage-
    HTML & CSS Forum Moderator

    "If you don't know what you think you know, then what do you know."
    R.I.P. Derrick Thomas #58
    1/1/1967 - 2/8/2000

  • #15
    Regular Coder
    Join Date
    Jan 2004
    Location
    Georgia
    Posts
    306
    Thanks
    0
    Thanked 0 Times in 0 Posts
    that still doesnt work :-\


    thanks
    ~Designer's Toolz~


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •