Lantica Software Support Center
Lantica Software Home Page
Order Sesame Getting Started Support Center Contact Us Company Downloads Q&A ™  
Search

Knowledgebase Home

Alternative commands for the Q&A compatible commands: GOTO, STOP, RETURN and GOSUB

While constructs such as GOTO, STOP, RETURN, and GOSUB are provided in Sesame for Q&A compatibility, their use is strongly deprecated. They create code that is both dangerous and difficult to follow. It is extremely difficult to determine what your code is doing when it contains multiple exit points and/or jumps around using GOTO.

  • Using the STOP command halts your program, essentially slamming on the breaks, where it is encountered in your program. This is a sure way to destabilize the state of your Layout and make sure that you never know what your code is actually doing. Instead of STOP, use a failure flag to prevent your code from continuing if something bad happens. (See NotifyForm() in the Sesame User Guide. This command, used in conjunction with the OnFormExit event can allow you to set a flag that allows or prevents saving the record.)

The following is a "flag" routine that determines whether a record is ready to be finalized, posted, etc.:

var vFlag as Int
var vMsg as String
var vCrLf as String

	vCrLf = @Newline()
	vFlag = 1
	vMsg = ""
	If OrderDate < @Date Then 
	{
		vFlag = 0
		vMsg = vMsg + vCrLf + "Invalid Order Date" 
	}
	If CustomerName = "" Then 
	{
		vFlag = 0
		vMsg = vMsg + vCrLf + "Blank Customer Name" 
	}
	If Item Count < 1 Then 
	{
		vFlag = 0
		vMsg = vMsg + vCrLf + "No Items on Order" 
	}
	If vFlag = 0 Then
	{
		@MsgBox(vMsg, "", "")
	}

Note that the message does not display if everything checks out okay (if the vFlag variable still contains "1" at the end of the routine).

GOTO is often one of the first programming commands used by an application programmer. It is also one of the most misused commands. It is not simply a way to move the cursor to a different element; it is a programming command that actually transfers programming control from where you are to somewhere else. Any code following GOTO will not run.Rather than using GOTO and RETURN, write a procedure instead. With Sesame, there is no long any reason to trick one of your layout elements (LE's) into acting like a subroutine.
While you can use GOTO to jump to labels in your code, or move to a different LE, you should avoid doing so. Instead, use ThrowFocus. (For more on the ThrowFocus command, see page 418 of the Sesame Programming Guide.) ThrowFocus also transfers both programming control and focus to another element, but allows the current code to finish running before doing so.
GOTO and ThrowFocus are often used to help guide the user into the correct path through the Form. They are also used to impose restriction on the user as to where they can go and what they must do to produce valid data. Unfortunately, in actual day-to-day use, the "correct" path can change as procedural requirements change, and navigation based on data validation can create traps that force users to actually enter invalid data to escape.
Do not use multiple RETURN statements. Have a single Return statement at the end of your Function. Programming that does include multiple Return statements is very difficult to debug and maintain. Keep your Return value in a variable and only Return at the end of your Function. Use conditionals to make sure that only the desired parts of your code run, rather than returning in several places.
Techniques such as ThrowFocus and NotifyForm used in place of navigation traps can reduce user frustration without risking data integrity What NOT to do:
GOSUB LastName
If LastName = "Jones"
{
	GOTO FirstName
}
State = "MA"
Country = "Jones"

What to do instead:

Var vLName as String

vLName = SetLastName()
If vLName = "Jones"
{
	ThrowFocus(FirstName)
}
Else
{
	State = "MA"
	Country = "USA"
}

Properties ID: 000233   Views: 1362   Updated: 13 years ago
Filed under:
Q&A Translation
Programming

Copyright Lantica Software, 2003-2025 All rights reserved