Click to See Complete Forum and Search --> : Addition +


Bear11
August 3rd, 2002, 10:12 AM
Hi !

Can anyone help me with this ?


When I try to have my application to count so will it answer as follows " An error was encountered running this program. Type Missmatch C2" Well I know that C2 is my textbox and I use the following code:

General Declaration:
Option Explicit

Private C1
Private C2

Private Sub txtC1_Change()
C1=txtC1.Text
C2=txtC2.Text

CSumma=(C1*1)+(C2*1)
txtCSumma.Text=CSumma

(and so on)

I had to use paranthesis becuse otherwise the plus sign worked as an & sign and 2+2 was 22 instead of 4.

I think that this has somthing to do with the datatype Variant that is (what I have understand" the one and only in CE programming, but how do I change it and how can I get the paranthesis to disapper.

I work in Palm Size PC 2.11 and EVB 3.0

Bjorn

undiwahn
August 6th, 2002, 04:44 PM
The + sign acts as a & because you're implicitly declaring C1 and C2 to be strings, by taking the text of the textboxes. I know you can declare them to be Ints,

Private C1 as Integer

Then when you take the value, use the Val function

C1 = Val( txtC1.Text )

(Same for C2)

Then when you add them, I believe it should know to do integer math instead of string concantenation.

Bear11
August 7th, 2002, 06:01 AM
when i try your suggestion so will the emulator only say "Variable is undefined 'Val' ".

In VB 6.0 works the Val function. But in the Embedded version is it the wrong way i think. Or is there a way to declare the Val function as well?


Bjorn