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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

do case problem

Status
Not open for further replies.

Vandolfph

Programmer
Jan 28, 2016
4
PH
here is my code in the interactivechange of a textbox using do case statement and
my problem is when i input "2.25" the messagbox on the button popup.
but the "2.25" is in the conditions above the otherwise.

is there wrong in the code?


Code:
DO CASE 
CASE this.Value="inc" OR this.Value="INC" OR this.Value="Inc" OR this.Value="Incomplete" OR this.Value="INCOMPLETE" OR this.Value="incomplete" 
	replace grade WITH "Inc"
	thisform.grdTor_table.Refresh

CASE this.Value="drp" OR this.Value="DRP" OR this.Value="Drp" OR this.Value="Dropped" OR this.Value="DROPPED" OR this.Value="dropped"
	replace grade WITH "Drp"
	thisform.grdTor_table.Refresh

CASE val(this.Value ) = 5 
	replace grade WITH "5.00"
	thisform.grdTor_table.Refresh

CASE val(this.Value) = 3  OR val(this.Value) = 3.0
	replace grade WITH "3.00"
	thisform.grdTor_table.Refresh

CASE val(this.Value) = 2.75
	replace grade WITH "2.75"
	thisform.grdTor_table.Refresh

CASE VAL(this.Value) =2.5 OR val(this.Value)=2.50
	replace grade WITH "2.50"
	thisform.grdTor_table.Refresh

CASE val(this.Value) =2.25
	replace grade WITH "2.25"
	thisform.grdTor_table.Refresh

CASE val(this.Value) = 2  OR val(this.Value)= 2.0 
	replace grade WITH "2.00"
	thisform.grdTor_table.Refresh

CASE val(this.Value) =1.75
	replace grade WITH "1.75"
	thisform.grdTor_table.Refresh

CASE val(this.Value) = 1.5 OR val(this.Value)=1.50
	replace grade WITH "1.50"
	thisform.grdTor_table.Refresh

CASE VAL(this.Value)= 1.25
	replace grade WITH "1.25"
	thisform.grdTor_table.Refresh

CASE val(this.Value)=1 OR val(this.Value)<= 1.0
	replace grade WITH "1.0"
	thisform.grdTor_table.Refresh
OTHERWISE
	MESSAGEBOX("Invalid Grade.",16,"Input error")
	this.Value=""
	RETURN 
ENDCASE
 
How about putting a breakpoint at the top and step through the code?
Interactivechange runs when you just type 2 already, it runs with every key pressed (like keypress)
You may want to put this into the valid event instead and only check, after you're finished entering the value.

Bye, Olaf.
 
Check the value of SET POINT
If SET POINT is set to ",", the you must enter 2,25 not 2.25

Code:
PUBLIC ofrm
SET POINT TO ","
ofrm = CREATEOBJECT("MyForm")
ofrm.Show()

DEFINE CLASS MyForm as Form
	ADD OBJECT txt as textbox
	PROCEDURE txt.InterActiveChange
		ACTIVATE SCREEN
		? VAL(This.Value)
	ENDPROC
ENDDEFINE

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania

 
I would perhaps think interactive change was the wrong place to have a refresh action, but I would rewrite
your code to look like this:

Code:
PRIVATE m.Flag
m.Flag = .t.
DO CASE 
CASE UPPER(LEFT(this.Value,3))="INC"
	replace grade WITH "Inc"
CASE UPPER(LEFT(this.Value,3)="DRP" OR UPPER(This.Value="DROPPED")
	replace grade WITH "Drp"
CASE val(this.Value ) == 5 
	replace grade WITH "5.00"
CASE val(this.Value) == 3  
	replace grade WITH "3.00"
CASE val(this.Value) == 2.75
	replace grade WITH "2.75"
CASE VAL(this.Value) == 2.5 
	replace grade WITH "2.50"
CASE val(this.Value) == 2.25
	replace grade WITH "2.25"
CASE val(this.Value) == 2  
	replace grade WITH "2.00"
CASE val(this.Value) == 1.75
	replace grade WITH "1.75"
CASE val(this.Value) == 1.5 
	replace grade WITH "1.50"
CASE VAL(this.Value) == 1.25
	replace grade WITH "1.25"
CASE val(this.Value) <= 1
	replace grade WITH "1.0"
OTHERWISE
	MESSAGEBOX("Invalid Grade.",16,"Input error")
	m.Flag = .f.
	this.Value=""
ENDCASE 
IF m.Flag
	thisform.grdTor_table.Refresh
ENDIF
RETURN


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
Griff, no need for == with numeric values, that only helps for string comparison.
 
Why was he (the OP) doing checks for 2.5 and 2.50?

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
I get the impression this particular input might be better off as a drop down/combo, it's got a nicely
limited number of possibilities and would remove the need for the error message

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Not tested. Pls try & alter as per your need.
Valid Event.
Code:
OutString=IIF(UPPER(this.value)="INC","Inc",;
IIF(UPPER(this.value)="DRO","Drp",;
IIF(VAL(this.value)=5,"5.00",;
IIF(VAL(this.value)=3,"3.00",;
IIF(VAL(this.value)=2.75,"2.75",;
IIF(VAL(this.value)=2.5,"2.50",;
IIF(VAL(this.value)=2.25,"2.25",;
IIF(VAL(this.value)=2,"2.00",;
IIF(VAL(this.value)=1.75,"1.75",;
IIF(VAL(this.value)=1.5,"1.5",;
IIF(VAL(this.value)=1.25,"1.25",;
IIF(VAL(this.value)=1,"1.00","0.00"))))))))))))
IF OutString="0.00"
	MESSAGEBOX("Invalid Grade.",16,"Input error")
	this.Value=""
	RETURN .F.
ELSE
	replace grade WITH OutString
	thisform.grdTor_table.Refresh
ENDIF
 
I agree with you, Griff. And the relevant values should come from a table, and not be hard coded.
 
The answer to your question is the otherwise branch, especially this line of code:
Code:
this.Value=""

Explanation.
When you type 2.25:
1) You type "2"
This.Value becomes "2"
InteractiveChange evaluates This.value and find an acceptable value (2), and replace the table accordingly

2) you type "."
This.Value becomes "2."
InteractiveChange evaluates This.value and find an acceptable value (2), and replace the table accordingly

3) You type "2" (the first decimal)
This.Value becomes "2.2"
InteractiveChange evaluates This.value and find an unacceptable value (2.2), goes to the otherwise branch, shows the messagebox and clears this.value

You must change the logic. You can place your entire code in another event, like lostfocus() or valid(), or only the otherwise branche

P.S.
Your code can be shortened this way:
Code:
DO CASE 
CASE LOWER(this.Value)="inc" OR LOWER(this.Value)="incomplete" 
	replace grade WITH "Inc"
	thisform.grdTor_table.Refresh

CASE LOWER(this.Value)="drp" OR LOWER(this.Value)="dropped"
	replace grade WITH "Drp"
	thisform.grdTor_table.Refresh

CASE INLIST(val(this.Value), 5, 3, 2.75, 2.5, 2.25, 2, 1.75, 1.5, 1.25, 1)
	replace grade WITH TRANSFORM(VAL(this.Value), "9.99")
	thisform.grdTor_table.Refresh

CASE val(this.Value)<= 1.0
	replace grade WITH "1.0"
	thisform.grdTor_table.Refresh

OTHERWISE
	MESSAGEBOX("Invalid Grade.",16,"Input error")
	this.Value=""
	RETURN 
ENDCASE


Respectfully,
Vilhelm-Ion Praisach
Resita, Romania

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top