CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2014
    Posts
    1

    New to VB, I need a better way to add Combo Boxes.

    I am new to Visual Basic, and at the moment I am making a program that will calculate the amount of miles I drive from store to store (picking up items from store to store as a job). I have 6 Combo Boxes, each with the same locations that can be chosen. Also, I have a data table that shows the miles from each location. (Example : If I was in Houston, it would take X amount of miles to get to San Antonio, Y amount of Miles to get to Austin, etc. And If I was in Austin, it would take X amount of miles to get to Houston, and Y amount of Miles to get to San Antonio, etc.) I only know the "If Then" statements to complete this, but to put this for every combo box, it is a lot of typing, and I am sure there is a faster way.

    Is anyone able to help me on this? I hope I explained it clear enough.

    Many Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: New to VB, I need a better way to add Combo Boxes.

    Use an ARRAY() of Comboboxes, and dynamically add each one. Could use the same code, then iterate and add the totals
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: New to VB, I need a better way to add Combo Boxes.

    Use a function that looks for the data in your data table and call it from the combobox click event, you can also add the other combo boxes to the handles clause so that all of them are handled by the same event if need be so you only need to write the code once.
    Always use [code][/code] tags when posting code.

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

Featured