[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 :ehh: . Does anyone know how to do this? :confused:
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))
Re: combo box variable question
This would be a bit faster/simplier:
VB Code:
Dim aData(8) As String
'set the elements...
RichTextBox1.Text = aData(Combo1.ListIndex)
Re: combo box variable question
How about associating combo's items with ASCII codes:
VB Code:
Option Explicit
Private Sub Form_Load()
Dim i%
For i = 1 To 26
Combo1.AddItem i
Next i
Text1.Text = ""
End Sub
Private Sub Combo1_Click()
Text1.Text = Text1.Text & Chr(Combo1.ListIndex + 65)
End Sub
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:
What would I use instead of the above code? How would I do it what I said? ;)
Re: combo box variable question
* Bump
If I didn't explain myself better tell me.
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'...?
Re: combo box variable question
Whether you have words or numbers in the combobox, use the solutions already posted.
VB Code:
Private aData(1) As String
Private Sub Form_Load()
Combo1.AddItem "alt"
aData(0) = "vbforums"
Combo1.AddItem "heading"
aData(1) = "rocks"
End Sub
Private Sub Combo1_Click()
RichTextBox1.Text = aData(Combo1.ListIndex)
End Sub
1 Attachment(s)
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..... :thumb:
Re: combo box variable question
brucevde is doesn't apear to do anything when I select them from my combobox...
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 What would I use instead to get it to use the adata instead?
Re: combo box variable question
The selected item in a combo is in the .ListIndex property, so you can use:
VB Code:
... & aData(Combo1.ListIndex) & ...
Re: combo box variable question