View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Adding Combobox Values

the value, whether numeric in nature or not is usually stored as a string
when it is in the combobox and or a textbox

The + operator has a dual capability to act as a concatenation operator when
placed between string values.

demo'd from the immediate window:
? 1 + 2
3
? "1" + "2"
12

the 12 is a string and the result of the concatenation of 1 and 2.

If you use the val as Bob pointed out, it should convert the string values
to numbers

? val("1") + val("2")
3

Just some added info probably not an issue he Val stops evaluating when
it hits a non numeric character. It considers a comma to be such a non
numeric character:
? val("1,000.2") + val("2,000.4")
3

Note that you should apply Val to the value of the textbox as well.

note that you can replace
ComboBox6.List(ComboBox6.ListIndex, 0)

with

Combobox6.Value

If Val(Combobox6.Value) + _
Val(Combobox8.Value) + _
Val(Combobox10.Value) + _
Val(Combobox12.Value) + _
Val(Combobox14.Value)
Val(TextBox47.Value) then


--
Regards,
Tom Ogilvy



"Corey" wrote in message
...
Still no values???

I am trying to set a vbyesno prompt if textbox47 < the sum of the listed
combobox values selected.
If the textbox47 value is less(<) than the sum of the comboboxes then a
msgbox(vbyesno) prompts the user to either carry on or modify to suit.
But even though the values of the comboboxes is greater () than the
textbox47 value i STILL get the msgbox(vbyesno)


End of commandbutton code:
~~~~~~~~~ Code ~~~~~~~~~~~~~~~~~
If ComboBox6.List(ComboBox6.ListIndex, 0) +
ComboBox8.List(ComboBox8.ListIndex, 0) +
ComboBox10.List(ComboBox10.ListIndex, 0) +
ComboBox12.List(ComboBox12.ListIndex, 0) +
ComboBox14.List(ComboBox14.ListIndex, 0) TextBox47.Value Then
GoTo thisspot
Else

ans = MsgBox("You have Not Chosen a Combination of Lengths long enough" &
vbCrLf & vbCrLf & vbTab & " to make up the Final Length Requirement.",
vbyesno, " ....")
If ans = vbYes Then GoTo thisspot
If ans = vbNo Then
MsgBox "Please Modify the Selected Values," & vbCrLf & vbCrLf & "and try
again.", , " ...."
Exit Sub
End If
thisspot:
Unload Me
Sheets("Main").Select
Range("A1").Activate
End If
End Sub
~~~~~~~~ End Code ~~~~~~~~~~~~~~~~


Did i miss something easy ?

Corey....


"Bob Phillips" wrote in message
...
Maube they are all strings. Try

If Val(ComboBox6.Value) + Val(ComboBox8.Value) + Val(ComboBox10.Value) +
Val(ComboBox12.Value) _ Val(ComboBox14.Value) TextBox47.Value Then


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Corey" wrote in message
...
I have a problem with adding up the values selected in some comboboxes.

the code I was using that is NOT working is:
If ComboBox6.List(ComboBox6.ListIndex, 0) +
ComboBox8.List(ComboBox8.ListIndex, 0) +
ComboBox10.List(ComboBox10.ListIndex, 0) +
ComboBox12.List(ComboBox12.ListIndex, 0) +
ComboBox14.List(ComboBox14.ListIndex, 0) TextBox47.Value Then

Is there a problem with the above?

I get NIL Value from it.
The list Index is correct for each.
Corey....