Results 1 to 13 of 13

Thread: [RESOLVED] combo box variable question

  1. #1

    Thread Starter
    Hyperactive Member LawnNinja's Avatar
    Join Date
    Aug 2006
    Posts
    446

    Resolved [RESOLVED] combo box variable question

    Ok, I have a combo box with numbers in it (1-9). I have a richtextbox that draws the text from the combobox when you press a command button. I want it so.

    1=v
    2=b
    3=f
    4=o
    5=r
    6=u
    7=m
    8=s
    9=9

    That way, when you select 5 lets just say...you'll get r in your richtextbox after you press the command button. I dont want to put v,b,f,o,r,u,m,s, and 9 in the the combobox because the actual text that 1-9 actually is way to long. I think you use variables to do this . Does anyone know how to do this?

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: combo box variable question

    Store the text information in an array.

    Dim aData(1 to 9 ) as String
    aData(1) = "V" 'or whatever you want.
    aData(2) = "B"

    The array elements correspond to the values in the Combobox. To load the RTB control

    RichTextBox.Text = aData(Clng(ComboBox.Text))

  3. #3
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: combo box variable question

    This would be a bit faster/simplier:
    VB Code:
    1. Dim aData(8) As String
    2.  
    3. 'set the elements...
    4.  
    5. RichTextBox1.Text = aData(Combo1.ListIndex)

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: combo box variable question

    How about associating combo's items with ASCII codes:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4. Dim i%
    5.  
    6.     For i = 1 To 26
    7.         Combo1.AddItem i
    8.     Next i
    9.     Text1.Text = ""
    10.  
    11. End Sub
    12.  
    13. Private Sub Combo1_Click()
    14.     Text1.Text = Text1.Text & Chr(Combo1.ListIndex + 65)
    15. End Sub

  5. #5

    Thread Starter
    Hyperactive Member LawnNinja's Avatar
    Join Date
    Aug 2006
    Posts
    446

    Re: combo box variable question

    Sorry I didn't explain it better but heres what I want

    I want it so in my combobox it has

    alt
    heading
    speed
    .......
    ......


    so on and so forth.

    I want:

    'alt' to be 'vbforums'
    'heading' to be 'rocks'

    when I add it to a richtextbox.

    I usually use:
    Code:
    & combobox1.text &
    What would I use instead of the above code? How would I do it what I said?

  6. #6

    Thread Starter
    Hyperactive Member LawnNinja's Avatar
    Join Date
    Aug 2006
    Posts
    446

    Re: combo box variable question

    * Bump

    If I didn't explain myself better tell me.
    Last edited by LawnNinja; Nov 27th, 2006 at 04:40 PM.

  7. #7
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: combo box variable question

    Quote Originally Posted by LawnNinja
    ... I want:

    'alt' to be 'vbforums'
    'heading' to be 'rocks'

    when I add it to a richtextbox...
    What do you mean with "I want" 'alt' to be 'vbforums'...?

  8. #8
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: combo box variable question

    Whether you have words or numbers in the combobox, use the solutions already posted.

    VB Code:
    1. Private aData(1) As String
    2.  
    3. Private Sub Form_Load()
    4.     Combo1.AddItem "alt"
    5.     aData(0) = "vbforums"
    6.  
    7.     Combo1.AddItem "heading"
    8.     aData(1) = "rocks"
    9. End Sub
    10.  
    11. Private Sub Combo1_Click()
    12.     RichTextBox1.Text = aData(Combo1.ListIndex)
    13. End Sub

  9. #9

    Thread Starter
    Hyperactive Member LawnNinja's Avatar
    Join Date
    Aug 2006
    Posts
    446

    Re: combo box variable question

    Ok I will post a piece of my app to help try to explain myself. I want it so when you press my command button instead of adding alt or any of the others I want it to input somthing else.
    For instance,
    ------------------------------------------------------------------
    alt=<<altitude variable define>>
    heading=<<Way to point ()>>
    ..........................
    ..........................

    so when I select alt in the combobox and press the command button it will add <<altitude variable define>> not alt to my richtextbox. I also want this for all the rest.....
    Attached Files Attached Files

  10. #10

    Thread Starter
    Hyperactive Member LawnNinja's Avatar
    Join Date
    Aug 2006
    Posts
    446

    Re: combo box variable question

    brucevde is doesn't apear to do anything when I select them from my combobox...

  11. #11

    Thread Starter
    Hyperactive Member LawnNinja's Avatar
    Join Date
    Aug 2006
    Posts
    446

    Re: combo box variable question

    Ow wait, problem at my end, thanks works great but how do you make it work with the vblines function? I usually use
    Code:
    & combo1.text &
    What would I use instead to get it to use the adata instead?

  12. #12
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: combo box variable question

    The selected item in a combo is in the .ListIndex property, so you can use:
    VB Code:
    1. ... &  aData(Combo1.ListIndex) & ...

  13. #13

    Thread Starter
    Hyperactive Member LawnNinja's Avatar
    Join Date
    Aug 2006
    Posts
    446

    Re: combo box variable question

    Thanks Eveyone

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