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

CODE ERROR - TROUBLE SHOOT 2

Status
Not open for further replies.

spysab

IS-IT--Management
Jun 13, 2019
27
PH
Hi guyz!

What is the possible reason why this code is having an error in 1 FORM but perfectly working in another?
this code is the one which is working perfectly. (deleting entries)

Code:
#define CMSG 	"Are you sure you want to delete customer ("+ALLTRIM(customers.company)+")?"
#define MB_YESNO	4
#define MB_QUESTION	32
#define IDYES 	6
#define IDNO	7

IF MESSAGEBOX(CMSG, MB_YESNO+MB_QUESTION, "Delete Customer") = IDYES
	DELETE
	SKIP
	IF EOF()
		GO BOTTOM
	ENDIF
	this.Refresh()
ENDIF

this code below is exactly the same other the name of the form which is joborders

Code:
#define CMSG 	"Are you sure you want to delete job order ("+ALLTRIM(joborders.jobno)+")?"
#define MB_YESNO	4
#define MB_QUESTION	32
#define IDYES 	6
#define IDNO	7

IF MESSAGEBOX(CMSG, MB_YESNO+MB_QUESTION, "Delete Job Order") = IDYES
	DELETE
	SKIP
	IF EOF()
		GO BOTTOM
	ENDIF
	this.Refresh()
ENDIF

im having an eror "Function argument value, type or count is invalid"

i really cant understand why exactly the same code works fine in a form but does not on the other.


 
joborders.hobno likely is numeric/integer. You can only ALLTRIM() a string type value.

That's the downside of constants using functions: The error is reported at the line with the meessagebox, which would be okay under the precondition CMSF is character. But it's an expression. That's compiled in this line and the compiler reports an error in this line.

Bye, Olaf.

Olaf Doschke Software Engineering
 
I agree with Olaf. Given that the only line of code that is different is the very first one, it seems likely that that is where the error lies. And the fact that that line contains a function call, and the error mesage refers to a function, it is almost certain that the problem is with the ALLTRIM().

An easy solution would be to change this:>

Code:
#define CMSG "Are you sure you want to delete job order ("+ALLTRIM(joborders.jobno)+")?"

to this:

Code:
#define CMSG "Are you sure you want to delete job order ("+ALLTRIM(TANSFORM((joborders.jobno))+")?"

A better solution would be to remove that first #DEFINE completely:

Code:
#define MB_YESNO	4
#define MB_QUESTION	32
#define IDYES 	6
#define IDNO	7

lcMessage = "Are you sure you want to delete job order ("+ALLTRIM(TRANSFORM(joborders.jobno))+")?"
            && change this line according to the type of record you are deleting

IF MESSAGEBOX(lcMessage, MB_YESNO+MB_QUESTION, "Delete Job Order") = IDYES
 DELETE
 SKIP
 IF EOF()
   GO BOTTOM
 ENDIF
 this.Refresh()
ENDIF

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike!


Thank you! Problems is fixed!

Thank you Thank you
 
By the way, there is the foxpro.h header file you're even allowed to distribute and which contains constants like the Messagebox constants and many many more. Use that.

It also limits itself to use #define for constants. There's more viable uses and some tricky, which are kind of neat, but usage like that is not helpful, it just causes head scratches to figure out the fault, especially when the defines are outsourced in a header file or you even start having header files including other header files. And that is recommendable to manage constants by topic or library and still have general constants available everwhere without any redefintion.

In your case. Even if jobno would be a character field, this whole construct depends on the alias joborders being in use bfore the constant appears in source code. That's also true, if you write that code directly into a line "lcMessage = ..." as Mike suggested, but it is much more obvious, then.

Bye, Olaf.


Olaf Doschke Software Engineering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top