-
March 10th, 2011, 01:38 AM
#1
VB6 Combo Box Arrays/Info to Labels Help
Hey guys,
First of all I'm not sure if this is in the right section, or whether someone has answered something like this already, but i've looked almost everywhere and am not sure how to do this.
Basically what i have is a combo box with a list of names and 3 labels on my form. The labels are for 'firstname', 'lastname' and 'age'
The combo box has names in it e.g.
Jake S
Paul G
Peter J
I would like certain values/info to show up in the 3 labels when a name is chosen
e.g. when Jake S is chosen:
(Combo1): Jake S (label1):Jake (label2):Smith (label3):17
when Peter J is chosen:
(Combo1): Peter J (label1):Peter (label2):John (label3):16 etc
Anyone able to help with sample code of what i need to do this? Do i need a comma delimited file or something? Help Please
-
March 10th, 2011, 02:36 AM
#2
Re: VB6 Combo Box Arrays/Info to Labels Help
You need Arrays.
Start a new project, Add a combobox to your form, add a Command button to your form, then add Three labels to your form.
Open the Code Window ( By pressing F7 ), then copy this :
Code:
Option Explicit
Private arrNames(2) As String 'Names array
Private arrSurnames(2) As String 'Surnames array
Private arrAge(2) As String 'Age array
Private Sub Command1_Click()
'Show corresponding item from combobox, via its index
Label1.Caption = arrNames(Combo1.ListIndex)
Label2.Caption = arrSurnames(Combo1.ListIndex)
Label3.Caption = arrAge(Combo1.ListIndex)
End Sub
Private Sub Form_Load()
'Store 3 values in Names array
arrNames(0) = "Jake"
arrNames(1) = "Paul"
arrNames(2) = "Peter"
'Store 3 values in Surnames array
arrSurnames(0) = "Smith"
arrSurnames(1) = "Gerber"
arrSurnames(2) = "John"
'Store 3 values in Age array
arrAge(0) = "17"
arrAge(1) = "20"
arrAge(2) = "16"
End Sub
As simple as that
-
March 10th, 2011, 03:58 AM
#3
Re: VB6 Combo Box Arrays/Info to Labels Help
Awesome! Thanks so much. Btw, is there a way to do this without the command button? and also, do i need to change anything (except for adding each diff label/array etc) if i'm adding extra information to be showed?
Again, thanks a lot
-
March 10th, 2011, 04:12 AM
#4
Re: VB6 Combo Box Arrays/Info to Labels Help
OH and if i want to add a lot of names to it, is there a way around having all that code in the form_load etc? Or will i just have to add each name/details to it?
I saw something about comma delimited files, but not sure how they work exactly :P
-
March 18th, 2011, 02:20 AM
#5
Re: VB6 Combo Box Arrays/Info to Labels Help
Depending on the amount of names, surnames and ages, yes a comma delimited file could work. I'm thinking here, because we are dealing with 3 different types of information, that you should rather consider an INI file instead - much easier to organise, much more professional as well at the end of the day. Does that sound like a plan?
Hannes
Tags for this Thread
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
|