CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2011

    Question 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

  2. #2
    Join Date
    Jul 2001
    Sunny South Africa

    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 :

    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

  3. #3
    Join Date
    Mar 2011

    Resolved 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

  4. #4
    Join Date
    Mar 2011

    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

  5. #5
    Join Date
    Jul 2001
    Sunny South Africa

    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?


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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.