Page 1 of 1 1
Topic Options
#140287 - 2005-05-25 06:49 PM Help with Readline Loop
Fugazi Offline
Starting to like KiXtart

Registered: 2001-04-23
Posts: 142
Loc: Pace, Fl.
One thing that has always bothered me is piping out plain text files from KiXtart. I am working on this encoding routine to encode the output to file. The problem I am having is that this is only reading the first line of the test file that I am trying to encode. I am going to work on areader after I get this completed. I only have this setup for Alpha Numeric at this time specialty characters are not available yet.

Code:
Break on
Dim $a,$b,$c,$sTestInfo,$sInfo,$sEncode,$sScanInfo
$a=1
Open (1,"c:\temp\test.txt",5)
Open (2,"c:\temp\testinfo.txt",2)
$aLCase='a','b','c','d','e','f','g','h','i','j','k','l',
'm','n','o','p','q','r','s','t','u','v','w','x','y','z',' ',
'1','2','3','4','5','6','7','8','9','0',
'~','!','@','#','$','%','^','&','*','(',')','_',
'+','?','>','<',':','"','}','{','|','\',']','[','=','-',',','.','/'
$aEncode='57e4','3216','96DD','774F','G44s','nX19','56x4','Y13n','k4T0','o319','J439','7KYL','x324',
'39e6','G491','2c3B','9ZiN','4qT7','E976','0Ob4','3nX4','1m43','D9I1','07QZ','07Qz','fx3J','X1x5','x4X9',
'Gg76','954N','TX1A','GWAH','4q33','xtZ0','K1n3','j517','ZN3x'
$sTestinfo=ReadLine (2)
While $Stestinfo <>""
Do
$sScaninfo=SubStr ($sTestinfo,$a,1)
For Each $sInfo in $aLCase
$b=$b+1
If $sInfo=$sScaninfo AND $bSkip=0
For Each $sEncode in $aEncode
$c=$c+1
If $c=$b
WriteLine (1,$sEncode)
$sEncode=""
$bSkip=1
EndIf
Next
EndIf
Next
$bSkip=0
$b=0
$c=0
?$sScaninfo
$a=$a+1
Until $sScanInfo=""
$sTestInfo= ReadLine (2)
WriteLine (1,@CRLF)
Loop
Close (1)
Close (2)
Exit 0



With this code KiXtart KiXass translates to:

J439k4T007QZ0Ob457e44qT70Ob4X1x5J439k4T007QZ57e4E976E976
_________________________
I haven't failed. I just found another way that did not work.

Top
#140288 - 2005-05-25 07:09 PM Re: Help with Readline Loop
NeedANewJob Offline
Fresh Scripter

Registered: 2005-04-01
Posts: 23
Try putting the $a=1 at the top of your While Loop.
Top
#140289 - 2005-05-25 08:21 PM Re: Help with Readline Loop
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Made some adjustments to take advantage of ascan(). But had to comment out the non alpha-numeric elements of your array.

Code:

Dim $a,$sTestInfo,$sEncode,$sScanInfo,$index
$a=1
$ = Open (1,"c:\test.txt",5)
$ = Open (2,"c:\testinfo.txt")
$aLCase='a','b','c','d','e','f','g','h','i','j','k','l',
'm','n','o','p','q','r','s','t','u','v','w','x','y','z',' ',
'1','2','3','4','5','6','7','8','9','0';,
;'~','!','@','#','$','%','^','&','*','(',')','_',
;'+','?','>','<',':','"','}','{','|','\',']','[','=','-',',','.','/'
$aEncode='57e4','3216','96DD','774F','G44s','nX19','56x4','Y13n','k4T0','o319','J439','7KYL','x324',
'39e6','G491','2c3B','9ZiN','4qT7','E976','0Ob4','3nX4','1m43','D9I1','07QZ','07Qz','fx3J','X1x5','x4X9',
'Gg76','954N','TX1A','GWAH','4q33','xtZ0','K1n3','j517','ZN3x'
$sTestinfo=ReadLine (2)
While @error = 0
$a = 1
Do
$sScaninfo=SubStr ($sTestinfo,$a,1)
$index = ascan($aLCase,$sScaninfo)
if $index > -1
$ = WriteLine (1,$aEncode[$index])
else
$ = Writeline(1,$sScaninfo)
EndIf
$a=$a+1
Until $sScanInfo=""

$ = WriteLine (1,@CRLF)
$sTestInfo= ReadLine (2)
Loop
$ = Close (1)
$ = Close (2)
Exit 0


Top
#140290 - 2005-05-25 10:19 PM Re: Help with Readline Loop
Fugazi Offline
Starting to like KiXtart

Registered: 2001-04-23
Posts: 142
Loc: Pace, Fl.
Quote:

$index = ascan($aLCase,$sScaninfo)
if $index > -1
$ = WriteLine (1,$aEncode[$index])
else
$ = Writeline(1,$sScaninfo)
EndIf





Just want to make sure that I understand your modifications in using the Ascan function.

$index = ascan($aLCase,$sScaninfo)

Is a numeric value with 0 starting as the first numeric value? This counts out the $aLCase until the $sScanInfo is found.

$ = WriteLine (1,$aEncode[$index])

Will take $aEncode and scan the array to the $index value so if $index = 2 the script will write the 3rd element in the $aEncode array?
_________________________
I haven't failed. I just found another way that did not work.

Top
#140291 - 2005-05-26 02:54 AM Re: Help with Readline Loop
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Yep, that is correct. The logic is really no different than how you had it. But if you're going to use arrays, you might as well take full advantage of the built-in functionality designed for them.

Btw, as NewJob pointed out, you were not resetting the value of $a, which in turn was probably hosing up your substr. I also changed the while loop to check @error (returned by the readline function) as opposed to checking for an empty string.

Top
#140292 - 2005-05-26 03:43 PM Re: Help with Readline Loop
Fugazi Offline
Starting to like KiXtart

Registered: 2001-04-23
Posts: 142
Loc: Pace, Fl.
Thanks for the help on this maciep.
_________________________
I haven't failed. I just found another way that did not work.

Top
#140293 - 2005-05-26 05:39 PM Re: Help with Readline Loop
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
no problem, glad i could help
Top
Page 1 of 1 1


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

Who's Online
0 registered and 484 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.052 seconds in which 0.023 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