View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
[email protected] kudruu@gmail.com is offline
external usenet poster
 
Posts: 10
Default Sum , multiply betwenn 2 comboboxes

On Apr 17, 3:52 pm, Carlos wrote:
I have 2 combboxes in a user form,

txtprice = 5
txtqty = 2

And i want in the third combobox to display the result of the multiplication
of ( txtprice * txtqy )

And in another user form i want to the same but instead of multiplicacion I
want to divide the 2 combboxes.

Actually I did it, but i get an error wich says "Type Mismatch"?
Can anybody help me.

Thanks


You're probably getting a type mismatch because your comboboxes are
not being recognized as integers.
I've found that declaring an integer variable for each combobox works
well, that way you can also set the value of your last one. Although
are there fixed prices? If not then why not use a regular textbox?
For example:
Dim txtpriceVar, txtqtyVar as Integer
On Error GoTo Int_fix
txtpriceVar = Me.txtprice.Value 'assuming txtprice is the name of your
combobox
txtqtyVar = Me.txtqty.Value
Int_fix: MsgBox("Make sure you have inputed an integer!")
Exit Sub
Me.third_combo_box.Value = txtpriceVar * txtqtyVar
Me.fourth_combo_box.Value = txtpriceVar / txtqtyVar

With this you are guaranteed not to have the type mismatch. You could
put an error handler before your integer declarations to insure that
the person inputing information has not entered any spaces or non-
integers.
I just ran into this error today and, though I may be wrong, it
appears as if Excel strips off the space when you set it as an
integer. I was comparing two different text boxes that were
"supposed" to have integers in them and even when I printed out their
values agreed with each other, but I still got the type mismatch, so I
implemented the integer variables.
Hope this helps.

Andrew