Normal Topic Global Code Programming Error (Read 1113 times)
Justin_ICC
Junior Member
**
Offline



Posts: 95
Joined: Feb 5th, 2004
Global Code Programming Error
May 6th, 2004 at 2:45pm
Print Post Print Post  
I have been having a strange problem when translating a command buttons code into a subroutine in the global code so it can be reused.

I had a piece of code that would take the values from a series of unbound elements and create a new record in a subform and insert those values with some hidden key fields.  When I translated it to the global code I changed the program to use parameters instead of layout element names and variables for the name of the subform. I am getting some strange error messages.

The subroutine starts by asking for the values to be inserted and it also asks for a Type variable - this is how it determines which form is the source/destination. I had it set the variables based on this type variable and if the parameter was outside of the range it would display a message box:

Code
Select All
vTemp = @MSGBOX("","Invalid Note Type!","");

I get the follow error message:
Error while parsing module " Global Code: Create Note":
Symbol Expected [}], symbol found [Identifier].
Line 32, position 25: [Identifier: Invalid]
vNoteNum = @MsgBox"","Invalid note Type!","");
                                ^ (pointing at invalid)
 



The only way I could get it to compile was to remove the text and use the following:

Code
Select All
vTemp = @MSGBOX("","Invalid Note Type!","");
 



I then got an error message on the next line using quotes:

Code
Select All
      if @Len(@FormFieldValue(vNoteDatabase,"Notes",vLoop)) < 2 then

This is the error message I got:
Error while parsing.....
Symbol Expected [}], symbol found [Identifier].
Line 52, position 48: [Identifier: Notes]
  if @Len(@formFieldValue(vNotesDatabase,"Notes",vLoop)) < 2 then
                                                             ^ (point it at start of vLoop)
 



Anyone have any ideas?
  
Back to top
 
IP Logged
 
Justin_ICC
Junior Member
**
Offline



Posts: 95
Joined: Feb 5th, 2004
Re: Global Code Programming Error
Reply #1 - May 6th, 2004 at 3:05pm
Print Post Print Post  
I just noticed one other problem that may prevent me from using this code. It seems like there is not Application level global code. This means i'll have to create the same program on each form.

Is there any way around this? I don't like having 84 lines of code duplicated on each form its being used on. This means that if there is a bug i'll have to remember to fix it on each form.

Any comments from the sesame team?
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Global Code Programming Error
Reply #2 - May 6th, 2004 at 3:08pm
Print Post Print Post  
Justin,

If you take a closer look at your error message, you will see that you are missing an opening parentheses after @MsgBox.
Code
Select All
 Error while parsing module " Global Code: Create Note":
Symbol Expected [}], symbol found [Identifier].
Line 32, position 25: [Identifier: Invalid]
vNoteNum = @MsgBox"","Invalid note Type!","");
					  ^ (pointing at invalid)  



You may have some other such syntax errors that are causing your compile errors. The syntax error may appear before the line shown in the error. Look for unmatched parentheses or curly braces or quote marks. If you are unable to track it down, please post the entire subroutine, so we can get help you spot the problem.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Global Code Programming Error
Reply #3 - May 6th, 2004 at 3:11pm
Print Post Print Post  
Quote:
I just noticed one other problem that may prevent me from using this code. It seems like there is not Application level global code. This means i'll have to create the same program on each form.

Is there any way around this? I don't like having 84 lines of code duplicated on each form its being used on. This means that if there is a bug i'll have to remember to fix it on each form.

Any comments from the sesame team?


There is not currently an application global code area. Code is attached to Forms, Reports and Mass Updates.

Future Sesame versions may include the ability to have an application wide global code area, or some sort of "include" capability.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Justin_ICC
Junior Member
**
Offline



Posts: 95
Joined: Feb 5th, 2004
Re: Global Code Programming Error
Reply #4 - May 6th, 2004 at 3:20pm
Print Post Print Post  
Thanks, I got another really strange error. I copied a piece of code from one form to another and all it does it check if it is a new record and update and it is complaining about the @isnew command. the code compiles on one form but not the other, here is that code:

Code
Select All
Form :: On Form Entry

///////////////////////////////////////////////////////////////////////////////////////
//  Disable Create Record in Update Mode
///////////////////////////////////////////////////////////////////////////////////////
If @ISNEW AND @Update
{
	ResultSetCurrentPosition(@ResultSetTotal() - 1);
}
 



I'll post the other code that i'm having problems in another message.
  
Back to top
 
IP Logged
 
Justin_ICC
Junior Member
**
Offline



Posts: 95
Joined: Feb 5th, 2004
Re: Global Code Programming Error
Reply #5 - May 6th, 2004 at 3:21pm
Print Post Print Post  
Here is the broken code:

Code
Select All
////////////////////////////////////////////////////////////////////////////////////////
//					   Create a New Note on a file.
// Parameters:
// vDate    - Date of Note
// vTime    - Time of Note
// vCol     - User entering Note
// vNote    - The Note
// vAcctNum - Account Number, DB#, Clt#, etc.
// vType    - Account Type - 0 = DB#, 1 = Clt#
////////////////////////////////////////////////////////////////////////////////////////

Subroutine CreateNote (	vDate as Date, vTime as Time, vCol as string, vNote as string, vAcctNum as Int, vType as Int )
// Declare Variables
var vCnt as Int		// Number of Notes for the record
var vLoop As Int	// Loop Variable for Notes
var vNoteNum as Double	// Current (in loop) Note's number
var vMaxTotal as Double // Maximum Note Number
var vNewNoteNum	as Int	// Note Number for New Record
var vUnusedNote as Int	// Flag as to whether or not there is an existing note.

var vNoteDatabase as string	// Stores which Database to work with notes.
var vNoteAcctName as string	// Stores which field to use for the Key field

if vType = 0 then
{	vNoteDatabase = "Collector Notes";
	vNoteAcctName = "DB#"; }
else if vType = 1 then
{	vNoteDatabase = "Sales Notes";
	vNoteAcctName = "CltKey; }
else
{
vNoteNum = @MSGBOX("","Invalid Note Type!","");

STOP;
}

// initialize current, maximum, and unused line numbers
vNoteNum = 0;
vMaxTotal = 0;
vUnusedNote = 0;

// retrieve number of notes from vNoteDatabase
vCnt = @FormResultSetTotal(vNoteDatabase);

// start at the first note
vLoop = 1;

// loop through all notes
while vLoop <= vCnt
{
	// if there is an unused note line (typicall first note) - flag it
	if @Len(@FormFieldValue(vNoteDatabase,"Notes",vLoop)) < 2 then
									^
	{
		if vLoop > vUnusedNote then
		{ vUnusedNote = vLoop; }
	};

	// get the note num of current note and put it into vMyTotal
	vNoteNum = @ToNumber(@FormFieldValue(vNoteDatabase,"NoteNum", vLoop));

	// if Current Note Number is > Highest Note Number
	if vNoteNum > vMaxTotal then
	{
		// set Max note number to current note number
		vMaxTotal=vNoteNum
	}
	vLoop = vLoop + 1;
}

// if there is an unused note line available use it, otherwise create a new record.
if vUnusedNote = 0 then
{	vNewNoteNum = vUnusedNote; }
else
{	vNewNoteNum = @FormNewRecord(vNoteDatabase); }

FormFieldValue(vNoteDatabase,"DateNote",vNewNoteNum,vDate);
FormFieldValue(vNoteDatabase,"TimeNote",vNewNoteNum,vTime);
FormFieldValue(vNoteDatabase,"Usr",vNewNoteNum,vCol);
FormFieldValue(vNoteDatabase,"Notes",vNewNoteNum,vNote);
FormFieldValue(vNoteDatabase,vNoteAcctName,vNewNoteNum,vAcctNum);
FormFieldValue(vNoteDatabase,"NoteNum",vNewNoteNum,vMaxTotal+1);

End Subroutine
 

  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Global Code Programming Error
Reply #6 - May 6th, 2004 at 3:40pm
Print Post Print Post  
1. You have an unclosed quote on the following line.
vNoteAcctName = "CltKey;

2. I STRONGLY recommend that you write your code to use a conditional instead of STOP.

3. You may find it easier to debug your code if you use a consistent bracing style. I know I would.  Wink

Re: @IsNew
Nothing is jumping out at me. What error do you get? Double-click on the error and see where it goes.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Justin_ICC
Junior Member
**
Offline



Posts: 95
Joined: Feb 5th, 2004
Re: Global Code Programming Error
Reply #7 - May 6th, 2004 at 3:59pm
Print Post Print Post  
Thanks, sometimes all it needs is a second set of eyes. I had forgotten to move those 2 braces down. When I fixed that problem it fixed the @isnew bug as well. Strange how a bug in one set of code breaks another.

Thanks a lot, i've been scratching my head over that one. And I do plan on removing the stop I just put that in for now as a quick exit.
  
Back to top
 
IP Logged