Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Operator/Operand mismatch

Status
Not open for further replies.

PrintNET

MIS
Sep 30, 2002
30
0
0
US
This is probably very simple but how do you assign the value of one variable to another? Or test if the values of a variable match?
I tried IF assignmentid = temp
and to copy values classid = tempclassid

but for both i get operator/operand mismatches
 
Hi

If you want specify, if it is a local variable or a (Global) Public variable..

LOCAL A2
or
PUBLIC A2

** Make the value A1 into A2
STORE A1 TO A2
or simply..
A2 = A1

When you use IF it is an evaluation of variables .. not an assignment.

IF A1 = A2
MESSAGEBOX("The Value of A1 is equal to A2")
ELSE
MESSAGEBOX("The Value of A1 is not equal to A2")
ENDIF

:)

ramani :)
(Subramanian.G)
 
Both values should be of the same data type. You can't assign a value of 'Dave' (Character) to a variable nCounter, if nCounter is for instance, 0 (numeric), without reinitializing it first.
That's one 'flaw' with Foxpro. No strict data typing.
You can initialize a variable with:
STORE 0 TO SomeVar
-then-
STORE 'Dave' TO SomeVar

And not get an error. But if the variable has already been initialized, you can't reassign a different data typed value to it:
STORE 0 TO SomeVar
-then-
SomeVar = 'Dave' &&... produces error

Hope I make sense.


-Dave S.-
[cheers]
Even more Fox stuff at:
 
Sorry, let me add some more for the second part:
Or test if the values of a variable match?

"=" can mean compare the value or it can mean assign the right value to the left value. In either case, the variables must be the same data type or you will get the error.
So, to display the variable's data type, use something like:
Code:
IF VARTYPE(assignmentid) = VARTYPE(temp)
   IF assignmentid = temp
      WAIT WINDOW "They're the same"
   ELSE
      WAIT WINDOW "They're different"
ELSE
   WAIT WINDOW "They're different data types"
ENDIF


-Dave S.-
[cheers]
Even more Fox stuff at:
 
temp is a value from a combo box which looks at a column of intergers. For some reason the value of the combo box is character string instead. Just about 6 spaces and then the number. I want it to be integer instead. Is that possible?
 
Don't mean to nitpick, Dave, but

STORE 0 TO SomeVar
SomeVar = 'Dave'

works just fine for me.

Jim
 
PrintNet,

To deal with the character data as a number, use the VAL() function:

xx = " 6"

if 6=Val(xx)
wait window "It Matches"
endif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top