Hi All,

I am facing a strange problem!

I have two numeric values (captured from text boxes) which I am trying to
add and it works fine for positive numbers. When one of them is negative, an
error is thrown by foxpro that there is data type mismatch.

I had debugged the application and checked the type of both the values. The
negative value was shown as 'C' type by the debugger. However, when I tried
the following statement,
TYPE(txt_box.value)
'N' was returned, but the debugger continued to show the value as 'C' type.

The idea was to convert the value to 'N' if it were 'C' type before
attempting to add the two values. But, I am not able to do this since
TYPE(txt_box.value) returns 'N' though it is considered as 'C'.

Anybody knows how to get over this problem?

Is it a bug in foxpro 8?

Thanks,
kd

RE: Negative numbers shown as 'C' type by Mark

Mark
Wed Feb 16 04:55:05 CST 2005

Hi KD,
You might want to check the type of the your underlying fields - if there
are controlsources.
If there are no controlsources you might want to check the VALUE of your
textbox when initiating it, e.g. txtBox.Value = 0 to be sure it returns
numeric values.
There is no bug as code below shows

CLEAR

CREATE TABLE mytable (nField1 N(5), nField2 N(5))
INSERT INTO mytable (nField1, nField2) VALUES (124, -1010)

oForm = NEWOBJECT("Form1")
oForm.Show
READ EVENTS
RETURN

DEFINE CLASS Form1 AS Form
Caption = " Numbers "
Name = "Form1"

ADD OBJECT txtPosNumber as txtBox1
ADD OBJECT txtNegNumber as txtBox2
ADD OBJECT txtSum as txtBox3
ADD OBJECT cmdSumAll as cmdSum

PROCEDURE Unload
CLOSE ALL
CLEAR EVENTS
ENDPROC

ENDDEFINE

DEFINE CLASS txtBox1 AS TextBox
Left = 12
Top = 24
ControlSource = "nField1"
EndDefine

DEFINE CLASS txtBox2 AS TextBox
Left = 12
Top = 48
ControlSource = "nField2"
EndDefine

DEFINE CLASS txtBox3 AS TextBox
Left = 12
Top = 72
ControlSource = "nField1 + nField2"
EndDefine

DEFINE CLASS cmdSum AS CommandButton
Left = 120
Top = 24
Height = 24
Caption = "Calculate"

PROCEDURE Click()
ThisForm.Refresh()
ENDPROC

EndDefine

hth
Mark


"kd" wrote:

> Hi All,
>
> I am facing a strange problem!
>
> I have two numeric values (captured from text boxes) which I am trying to
> add and it works fine for positive numbers. When one of them is negative, an
> error is thrown by foxpro that there is data type mismatch.
>
> I had debugged the application and checked the type of both the values. The
> negative value was shown as 'C' type by the debugger. However, when I tried
> the following statement,
> TYPE(txt_box.value)
> 'N' was returned, but the debugger continued to show the value as 'C' type.
>
> The idea was to convert the value to 'N' if it were 'C' type before
> attempting to add the two values. But, I am not able to do this since
> TYPE(txt_box.value) returns 'N' though it is considered as 'C'.
>
> Anybody knows how to get over this problem?
>
> Is it a bug in foxpro 8?
>
> Thanks,
> kd
>
>
>

Re: Negative numbers shown as 'C' type by Bernhard

Bernhard
Wed Feb 16 05:07:29 CST 2005

Hi kd,

> The idea was to convert the value to 'N' if it were 'C' type before
> attempting to add the two values. But, I am not able to do this since
> TYPE(txt_box.value) returns 'N' though it is considered as 'C'.
>
> Is it a bug in foxpro 8?
No, it is not a bug, it is normal behavior of Foxpro since last millenium ;-)
Maybe you test the type by:
VARTYPE(txt_box.value)
or by
TYPE("txt_box.value")

Regards
Bernhard Sander