Page 1 of 1 1
Topic Options
#25290 - 2002-07-17 08:24 PM Basic Functions - Script Errors
Jeremy Vyska Offline
Fresh Scripter

Registered: 2002-07-17
Posts: 9
Loc: Boston, MA
I've been using KiXtart for years now... But recently (after upgrading), I've been getting "Script Error: eprected expression" anytime I have tried to use:

- Left
- Right
and
-Split

It's getting to be quite a problem. Is there a good way to troubleshoot what's going on here?

Jeremy

Top
#25291 - 2002-07-17 08:25 PM Re: Basic Functions - Script Errors
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Jeremy,

Welcome to the board.

Can you post some of your code that is of concern?

Also:
What version of Kixtart are you using?
What OS Versions?

Thanks,

Kent

[ 17 July 2002, 20:26: Message edited by: kdyer ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#25292 - 2002-07-17 08:35 PM Re: Basic Functions - Script Errors
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Have you checked your syntax?
_________________________
There are two types of vessels, submarines and targets.

Top
#25293 - 2002-07-17 08:36 PM Re: Basic Functions - Script Errors
Jeremy Vyska Offline
Fresh Scripter

Registered: 2002-07-17
Posts: 9
Loc: Boston, MA
I've tried in under:

-Windows 2000, running 3.54
-Windows XP, running 4.02

Same trouble. Hence why I am puzzled

One code piece: (Split troubles)

code:
IF OPEN(1,$InputFile) = 2
CLS
? "File " + $InputFile + " does not exist that can be found."
QUIT
ENDIF
OPEN(2,$OutputFile,5)
WHILE @ERROR = 0
$Line = READLINE(1)
IF SUBSTR($Line, 1, 3) = "SDQ"
$Segment = Split($Line, "*")
$Pos = 0
FOR EACH $Element in $Segment
$Pos = $Pos + 1
SELECT
CASE 3 OR 5 OR 7 OR 9 OR 11 OR 13 OR 15 OR 17 OR 19 OR 21
WRITELINE(2, $Element + CHR(13) + Chr(10))
ENDSELECT
NEXT
ENDIF
LOOP

And I also had trouble with this little bugger before I replaced LEFT's and RIGHT's with SUBSTR:

code:
BREAK ON
; Draw the grid and box for the screen, plus the title
CLS
small
Color b+/n
BOX (0,0,24,79,GRID)
Color b/n
BOX (4,11,21,70,Å)
Color g+/n
BOX (3,10,20,69,FULL)

Color w+/n
AT (5,13) "EDI Splitter 1.0 - By Jeremy Vyska"
Color n/n
AT (22, 13) " * Where path is current path, file names are sufficient "

; We allow the savvy to enter command line parameters if they want,
; otherwise, we ask

IF ($InputFile + ".") = "."
AT (18,15) "Please enter your source filename and path:"
AT (19,15) "> "
GETS $InputFile
ENDIF

; Add the set input file to the option list

Color n/n
BOX (18,15,19,68," ")
AT (7,15) "Input:"
AT (7,28) $InputFile

; Now let's do the same thing for the output file...

Color w+/n
IF ($OutputFile + ".") = "."
AT (18,15) "What name for the resulting file?"
AT (19,15) "> "
GETS $OutputFile
ENDIF

Color n/n
BOX (18,15,19,68," ")
AT (8,15) "Output:"
AT (8,28) $OutputFile
AT (23,1) " "

; Now, how do they want the file?

Color w+/n
IF ($Format + ".") = "."
AT (18,15) "What format for the resulting file? (E)DI/(C)SV/(O)ne Line Only"
AT (19,15) "> "
GET $Format
$Format = UCASE($Format)
ENDIF

Color n/n
BOX (18,15,19,68," ")
AT (9,15) "Format:"
AT (9,28) $Format
AT (23,1) " "



Color w+/n
IF ($SegTerm + ".") = "."
AT (18,15) "What is the Segment Terminator?"
AT (19,15) "> "
GETS $SegTerm
ENDIF

Color n/n
BOX (18,15,19,68," ")
AT (10,15) "SegTerm:"
AT (10,28) $SegTerm
AT (23,1) " "

Color w+/n
IF ($ElTerm + ".") = "."
AT (18,15) "What is the Element Terminator?"
AT (19,15) "> "
GETS $ElTerm
ENDIF

Color n/n
BOX (18,15,19,68," ")
AT (11,15) "El. Term:"
AT (11,28) $ElTerm
AT (23,1) " "


; Open files

AT (22,13) "Processing..."

AT (22,27) "Opening Files"
IF OPEN(1,$InputFile) = 2
CLS
? "File " + $InputFile + " does not exist that can be found."
QUIT
ENDIF
OPEN(2,$OutputFile,5)

; Process files

$TempLine = "Temp"

IF ($Format = "E") OR ($Format = "O")
WHILE (@ERROR = 0) OR (LEN($TempLine > 2))
$TempLine = READLINE(1)
$NextLine = 1
WHILE $NextLine > 0
$X = INSTR($TempLine,$SegTerm)
IF $X > 0
$Garbage = WRITELINE(2, SUBSTR($TempLine, 1, $X))
IF $Format = "E"
$Garbage = WRITELINE(2, Chr(13) + Chr(10))
ENDIF
$TempLine = SUBSTR($TempLine, $X + 1, LEN($TempLine) - $X)
ENDIF
IF $X = 0
$Garbage = WRITELINE(2, $TempLine)
$NextLine = 0
ENDIF
LOOP
LOOP
ENDIF

IF $Format = "C"

ENDIF

CLOSE(1)
CLOSE(2)

Color g+/n
BOX (3,10,20,69,FULL)

Color w+/n
AT (5,13) "Navision Modifier 1.0 - By Jeremy Vyska"
Color n/n
AT (22, 13) " * Where path is current path, file names are sufficient "

Color w+/n
AT (7, 15) "Process Complete"
Color g+/n

AT (23,1) " "


Top
#25294 - 2002-07-18 03:43 PM Re: Basic Functions - Script Errors
Jeremy Vyska Offline
Fresh Scripter

Registered: 2002-07-17
Posts: 9
Loc: Boston, MA
So... any thoughts as to why

code:
 $Segment = Split($Line, "*") 

wouldn't work?

Top
#25295 - 2002-07-18 03:59 PM Re: Basic Functions - Script Errors
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
The SPLIT function does work as advertised. What is the exact error message generated by KiXtart or what is the exact reason that you believe that the SPLIT function is not working?
Put a ? ''+@ERROR+' - '+@SERROR right after your SPLIT to display any error message generated.
_________________________
There are two types of vessels, submarines and targets.

Top
#25296 - 2002-07-18 04:00 PM Re: Basic Functions - Script Errors
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
A couple of observations - may not fix your problem, but I've found before that you may get failures on lines where the error is in fact elsewhere in the script.

  • Quit takes an optional parameter. Sometimes it is not so optional and causes errors [Wink] . Get into the habit of returning an exit code i.e. Quit 0. The "EndIf" following the Quit may be interpreted as the exit code.
  • Your CASE statement is not constructed correctly. Each element should be an expression. I think you mean:
    code:
    Case $Pos=3 OR $Pos=5 OR ...


Top
#25297 - 2002-07-18 04:07 PM Re: Basic Functions - Script Errors
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Actually, the CASE is constructed correctly (it is syntactically correct) but it will always evaluate to true since e.g. '3' is not false. Anyway, I assume you rather want to do what Richard is proposing.
_________________________
There are two types of vessels, submarines and targets.

Top
#25298 - 2002-07-18 05:04 PM Re: Basic Functions - Script Errors
Jeremy Vyska Offline
Fresh Scripter

Registered: 2002-07-17
Posts: 9
Loc: Boston, MA
OK, I appreciate the help you guys are giving. I've changed the script to:

code:
IF OPEN(1,$InputFile) = 2
CLS
? "File " + $InputFile + " does not exist that can be found."
ENDIF
OPEN(2,$OutputFile,5)
WHILE @ERROR = 0
$Line = READLINE(1)
IF SUBSTR($Line, 1, 3) = "SDQ"
$Segment = Split($Line, "*")
$Pos = 0
FOR EACH $Element in $Segment
$Pos = $Pos + 1
SELECT
CASE $Pos=3 OR $Pos=5 OR $Pos=7 OR $Pos=9 OR $Pos=11 OR $Pos=13 OR $Pos=15 OR $Pos=17 OR $Pos=19 OR $Pos=21
$nul = WRITELINE(2, $Element + CHR(13) + Chr(10))
ENDSELECT
NEXT
ENDIF
? "Loop"
LOOP
? @ERROR+' - '+@SERROR
CLOSE(2)
CLOSE(1)

The error feedback is "-300" when I run it. Looking it up, this means:

300 The oplock request is denied. ERROR_OPLOCK_NOT_GRANTED

What in the heck is all that about?

Top
#25299 - 2002-07-18 05:10 PM Re: Basic Functions - Script Errors
Jeremy Vyska Offline
Fresh Scripter

Registered: 2002-07-17
Posts: 9
Loc: Boston, MA
OOPS!

OK, I figured out the 300 error. Had my source file open. But, with the above code, I get the following text as output:

code:
O:\editools>kix32 sdq.kix $inputFile=clean.txt $outputFile=SDQ.txt

Loop
Loop
Loop
Loop
Loop
Loop
Loop
Loop
Loop
Loop
Loop
Loop
Loop
Loop
Loop
Loop
Loop
Loop
Loop
Loop
Loop
Loop
Loop
LoopScript error : expected expression !.
$Segment = Split($Line, "*")


O:\editools>

Thoughts?

Here's a sample of the source file, too:

code:
ISA*00*          *00*          *08*925485US00     *ZZ*355800GF       *020430*2214*:*00403*850000217*0*P*>~
GS*PO*925485US00*355800GF*20020430*2214*850000217*X*004030~
ST*850*0001~
BEG*00*SA*7200421407**20020501~
CUR*BY*USD~
REF*DP*00019~
REF*MR*0037~
REF*IA*355800190~
FOB*CC*OR*PAWTUCKET RI RI~
ITD*05*15*****65~
DTM*001*20020506~
DTM*010*20020501~
PID*S*08*VI*FL~
TD5*O****SRG~
N9*L1*SPECIAL INSTRUCTIONS~
MTX**NO PRETICKET~
MTX**==============================IF MULTIPLE DESTINATIONS HAVE~
MTX**THE SAME SHIP DATE, PLEASE SHIP TO FURTHEST DESTINATION~
MTX**FIRST AND CLOSEST DESTINATIONSLAST.~
MTX**==============================~
N1*FR*WAL-MART STORES, INC.~
N1*SU*GENERAL FABRICS CO~
PO1*001*360*EA*2.32*LE*IN*001911016*UP*731875115062*VN*1264*BO*NAVY*IZ*44/45~
PO4*12~
SDQ*EA*UL*0078742002224*12*0078742003955*12*0078742004112*12*0078742004501*12*0078742004525*12*0078742004563*12*0078742007878*12*0078742007915*12*0078742010182*12*0078742012070*12~
SDQ*EA*UL*0078742013251*12*0078742013381*12*0078742015309*12*0078742016139*12*0078742016597*24*0078742018478*12*0078742019475*12*0078742019772*12*0078742020327*12*0078742020662*12~
SDQ*EA*UL*0078742021416*12*0078742023236*12*0078742024271*12*0078742024400*12*0078742024820*12*0078742024868*12*0078742025322*12*0078742027371*12*0078742034003*12~
AMT*1*835.2~
PO1*002*288*EA*2.32*LE*IN*001911023*UP*731875115079*VN*1264*BO*HUNTER*IZ*44/45~
PO4*12~
SDQ*EA*UL*0078742002224*12*0078742002415*12*0078742003955*12*0078742004563*12*0078742007878*12*0078742007915*12*0078742008035*12*0078742009254*12*0078742013251*12*0078742014098*12~
SDQ*EA*UL*0078742015262*12*0078742015392*12*0078742016665*12*0078742018478*12*0078742019475*12*0078742020662*12*0078742021416*12*0078742022024*12*0078742022536*12*0078742023236*12~
SDQ*EA*UL*0078742024165*12*0078742024448*12*0078742026022*12*0078742033945*12~


Top
#25300 - 2002-07-18 05:15 PM Re: Basic Functions - Script Errors
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
the codes syntax is not checking the error as wanted.

change lines:
OPEN(2,$OutputFile,5)
WHILE @ERROR = 0
$Line = READLINE(1)

to:
OPEN(2,$OutputFile,5)
$Line = READLINE(1)
WHILE @ERROR = 0

and add
$Line = READLINE(1)

between '? "loop"' and 'loop':
? "Loop"
$Line = READLINE(1)
LOOP

that should fix one error...

cheers,
_________________________
!

download KiXnet

Top
#25301 - 2002-07-18 05:16 PM Re: Basic Functions - Script Errors
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
I suspect that the error is in the line before '$Segment = Split($Line, "*")', namely 'IF SUBSTR($Line, 1, 3) = "SDQ"', and that $Line is empty when that particular error occurs.
_________________________
There are two types of vessels, submarines and targets.

Top
#25302 - 2002-07-18 05:19 PM Re: Basic Functions - Script Errors
Jeremy Vyska Offline
Fresh Scripter

Registered: 2002-07-17
Posts: 9
Loc: Boston, MA
Good thoughts, but same results. $Line is being populated correctly and going into the SPLIT function, that substring of $Line does properly come out as 'SDQ'
Top
#25303 - 2002-07-18 06:13 PM Re: Basic Functions - Script Errors
Jeremy Vyska Offline
Fresh Scripter

Registered: 2002-07-17
Posts: 9
Loc: Boston, MA
Continuing funky-ness.

I thought perhaps the problem is with the variable not be declared as an array ahead of time.

When I added "DIM $Segment[20]", I swear, it came back with "Script Error: Unknown Command !"

What in the world is going on here?

Top
#25304 - 2002-07-18 06:24 PM Re: Basic Functions - Script Errors
Jeremy Vyska Offline
Fresh Scripter

Registered: 2002-07-17
Posts: 9
Loc: Boston, MA
And, I cut and paste the examples from the Split documentation and got the same error. Grr...
Top
#25305 - 2002-07-19 09:37 AM Re: Basic Functions - Script Errors
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Try this, it works for me with your data. You may need to change the "For...Next" loop to suit the data that you actually want to extract.

code:
$InputFile="testdata.txt"
$OutputFile="Extract.txt"

; ----------------
; Open input file.
; ----------------
If OPEN(1,$InputFile)
"Cannot open input file " $InputFile " for reading." ?
"ERROR: " @ERROR " - " @SERROR ?
Quit 1
EndIf

; -----------------
; Open Output file.
; -----------------
If OPEN(2,$OutputFile,5)
"Cannot open input file " $OutputFile " for writing." ?
"ERROR: " @ERROR " - " @SERROR ?
$nul=Close(1)
Quit 1
EndIf

; -------------------------
; Read all lines from input
; -------------------------
$Line = READLINE(1)
While @ERROR = 0
$Segment = Split($Line, "*")
$SegmentSize=Ubound($Segment)
IF $Segment[0] = "SDQ"
For $Pos = 3 to $SegmentSize Step 2
If $Segment[$Pos] <> ""
If WriteLine(2, $Segment[$Pos] + @CRLF)
"Cannot write to output file " $InputFile ?
"ERROR: " @ERROR " - " @SERROR ?
Quit 1
EndIf
EndIf
Next
EndIf
$Line = READLINE(1)
Loop
; ---------------------------
; Close open file descriptors
; ---------------------------
$nul=Close(2)
$nul=Close(1)


Top
#25306 - 2002-07-19 03:12 PM Re: Basic Functions - Script Errors
Jeremy Vyska Offline
Fresh Scripter

Registered: 2002-07-17
Posts: 9
Loc: Boston, MA
That looks like a sweet script! Thanks, but..

Same problem.

No lie - the processor kicks out the line with Split. I can't figure it out for the life of me. Makes me worried about if login scripts will work correctly on this machine if they ever need to become more complicated.

Top
#25307 - 2002-07-19 03:20 PM Re: Basic Functions - Script Errors
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Everything in your posts indicate you're not running KiX 4. Perhaps you multiple versions on your path and you're picking up the wrong one. What does @KIX return?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#25308 - 2002-07-19 03:22 PM Re: Basic Functions - Script Errors
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
I have the same suspicion since he has KiXtart 3.x and 4.x installed on various computers.

Jeremy, you NEED 4.x for your script to run, so clean up your compuyres and get rid of any 3.x instance of KiXtart.
_________________________
There are two types of vessels, submarines and targets.

Top
#25309 - 2002-07-22 12:14 AM Re: Basic Functions - Script Errors
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

For information about upgrading see
Kix upgrade: what are those new features? can upgrade be done without any danger?
greetings.
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 867 anonymous users online.
Newest Members
JimDunn, fgarcia, Viginette, ManuvdWielNL, Sir_Barrington
17890 Registered Users

Generated in 0.111 seconds in which 0.063 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org