6 Replies - 34253 Views - Last Post: 05 October 2010 - 08:55 AM Rate Topic: -----

#1 bbaer22  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-May 07

Combo Box in Visual Basic 6

Posted 21 May 2007 - 12:10 PM

I am writing a little program (calculator) in which I have a combo box with materials and their values. Such as: Glass 1.80 or LH67 1.79. My problem is that I don't know how to pick something in the drop down box and only have the numeric values enter into the equation. I get an error every time because the words (glass or LH67) are being picked as well.
Is This A Good Question/Topic? 0
  • +

Replies To: Combo Box in Visual Basic 6

#2 tody4me  Icon User is offline

  • Banned
  • member icon

Reputation: 12
  • View blog
  • Posts: 1,398
  • Joined: 12-April 06

Re: Combo Box in Visual Basic 6

Posted 21 May 2007 - 12:33 PM

what you want then is to grab the selected item and then the value on the right hand side of the space. So you want something like
right$(combobox1.selectedvalue,instrrev(combobox1.selectedvalue, chr$(32))


The syntax may not be 100%, but the logic is all there. Basically you are wanting the last index of the character 32 (space) and grab the value on the right hand side of it. This will not work for Glass 1.80 1.90, cause it would only grab the 1.90 and leave the 1.80 alone. This WILL work also for the LH67 example.
Was This Post Helpful? 0
  • +
  • -

#3 bbaer22  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 21-May 07

Re: Combo Box in Visual Basic 6

Posted 22 May 2007 - 08:38 AM

View Posttody4me, on 21 May, 2007 - 12:33 PM, said:

what you want then is to grab the selected item and then the value on the right hand side of the space. So you want something like
right$(combobox1.selectedvalue,instrrev(combobox1.selectedvalue, chr$(32))


The syntax may not be 100%, but the logic is all there. Basically you are wanting the last index of the character 32 (space) and grab the value on the right hand side of it. This will not work for Glass 1.80 1.90, cause it would only grab the 1.90 and leave the 1.80 alone. This WILL work also for the LH67 example.



Thanks----however, I have tried this in every way I can think of and I'm still not getting it to work. Pretty new to programming----any other ideas? Or could you help me with the proper syntax :)
Was This Post Helpful? 0
  • +
  • -

#4 jeff_sibal  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 24
  • Joined: 02-April 07

Re: Combo Box in Visual Basic 6

Posted 24 September 2007 - 12:24 AM

do you still want the code on combo box?
reply this message if you still need it and I will be glad to help you sir.

jeff sibal
philippines

View Postbbaer22, on 21 May, 2007 - 12:10 PM, said:

I am writing a little program (calculator) in which I have a combo box with materials and their values. Such as: Glass 1.80 or LH67 1.79. My problem is that I don't know how to pick something in the drop down box and only have the numeric values enter into the equation. I get an error every time because the words (glass or LH67) are being picked as well.

Was This Post Helpful? 0
  • +
  • -

#5 HalSilverman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-September 10

Re: Combo Box in Visual Basic 6

Posted 26 September 2010 - 11:35 AM

View Postjeff_sibal, on 23 September 2007 - 11:24 PM, said:

do you still want the code on combo box?
reply this message if you still need it and I will be glad to help you sir.

jeff sibal
philippines

View Postbbaer22, on 21 May, 2007 - 12:10 PM, said:

I am writing a little program (calculator) in which I have a combo box with materials and their values. Such as: Glass 1.80 or LH67 1.79. My problem is that I don't know how to pick something in the drop down box and only have the numeric values enter into the equation. I get an error every time because the words (glass or LH67) are being picked as well.



Yes, I would love to see the code because I am having the same problem. I am trying to use the selected value from the combobox in an equation.

Thanks

Hal Silverman, NewBe

This post has been edited by HalSilverman: 26 September 2010 - 11:36 AM

Was This Post Helpful? 0
  • +
  • -

#6 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,796
  • Joined: 26-March 09

Re: Combo Box in Visual Basic 6

Posted 26 September 2010 - 12:19 PM

Depending on when you want to collect the data, you could use something like below.

This is based on clicking a button once you have made your selection, but should be easy enough for you to add to the combobox event if necessary.

Private Sub Command1_Click()
' Declare an array of string type
Dim astrdata() As String

    ' Split the combobox string at the space.
    astrdata = Split(Combo1.Text, " ")
    
    ' display the different elements of the array
    MsgBox "Value of " & astrdata(0) & " is : " & astrdata(1)

End Sub



Just to note that the data is extracted as a string.

If you want to do calculations with it, you will need to validate and cast it as the relevant numeric type.

Hope that helps.

This post has been edited by maj3091: 26 September 2010 - 12:20 PM

Was This Post Helpful? 0
  • +
  • -

#7 Dixion  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 15-September 10

Re: Combo Box in Visual Basic 6

Posted 05 October 2010 - 08:55 AM

View Postbbaer22, on 21 May 2007 - 11:10 AM, said:

I am writing a little program (calculator) in which I have a combo box with materials and their values. Such as: Glass 1.80 or LH67 1.79. My problem is that I don't know how to pick something in the drop down box and only have the numeric values enter into the equation. I get an error every time because the words (glass or LH67) are being picked as well.


What I do is: on the controls for the combobox go to ItemData and make sure they are from 0 - # (if 9 items then 0,1,2,3,4,5,6,7,8)
change the sub into a click instead of change.

private sub combo1_click()
if combo1.listindex = 0 then
msgbox "hello 0"
elseif combo1.listindex = 1 then
msgbox "hello"
end if

Change the msgbox for the code you want like assigning variables the value of the item you want.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1