Combo Box

Two Combo box send result to Label

Page 1 of 1

3 Replies - 1392 Views - Last Post: 01 April 2010 - 01:12 PM Rate Topic: -----

#1 velaphi  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 55
  • Joined: 20-July 08

Combo Box

Posted 01 April 2010 - 09:35 AM

I'm trying to write a program that will calculate the Distance between the two combo box, and the results must be on the label


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim intRow As Integer
        Dim intCol As Integer
        Dim mintDistance(,) As Integer = {{75, 90}, {9, 25}, {23, 56}, {6, 12}}


        If ComboBox1.SelectedIndex <> -1 And ComboBox2.SelectedIndex <> -1 Then
            intRow = ComboBox1.SelectedIndex
            intCol = ComboBox2.SelectedIndex


            Label1.Text = CStr(mintDistance(intRow, intCol))
        Else
            MessageBox.Show("Select Departure and Destination", "Choose Cities", MessageBoxButtons.OK, MessageBoxIcon.Information)
            ComboBox1.Focus()
        End If

This post has been edited by PsychoCoder: 01 April 2010 - 09:55 AM
Reason for edit:: Added code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Combo Box

#2 MajorWalrus  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 115
  • Joined: 22-April 09

Re: Combo Box

Posted 01 April 2010 - 09:54 AM

What sort of trouble are you having? What sort of errors are you getting?

I haven't tried your code, but it looks like one problem might be your variable declarations. I believe the ComboBox.SelectedIndex should be passed to a long data type, not an integer.

Good luck!
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Combo Box

Posted 01 April 2010 - 09:55 AM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:


  • Post the code you're having problems with (DONE)
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#4 velaphi  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 55
  • Joined: 20-July 08

Re: Combo Box

Posted 01 April 2010 - 01:12 PM

Thank you Guys, i've made a mistake by not filling the property Combo Box with the name of the cities. The code is working 100%. Thank you for your contribution.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1