|
-
Nov 23rd, 2006, 06:42 PM
#1
Thread Starter
Hyperactive Member
[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?
-
Nov 23rd, 2006, 07:00 PM
#2
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))
-
Nov 23rd, 2006, 07:03 PM
#3
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)
-
Nov 23rd, 2006, 07:16 PM
#4
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
-
Nov 26th, 2006, 05:15 PM
#5
Thread Starter
Hyperactive Member
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?
-
Nov 27th, 2006, 04:36 PM
#6
Thread Starter
Hyperactive Member
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.
-
Nov 27th, 2006, 04:38 PM
#7
Re: combo box variable question
 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'...?
-
Nov 27th, 2006, 05:14 PM
#8
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
-
Nov 27th, 2006, 05:25 PM
#9
Thread Starter
Hyperactive Member
-
Nov 27th, 2006, 05:31 PM
#10
Thread Starter
Hyperactive Member
Re: combo box variable question
brucevde is doesn't apear to do anything when I select them from my combobox...
-
Nov 27th, 2006, 10:08 PM
#11
Thread Starter
Hyperactive Member
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?
-
Nov 28th, 2006, 12:36 PM
#12
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) & ...
-
Dec 1st, 2006, 10:43 PM
#13
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|