Page 1 of 1 1
Topic Options
#148848 - 2005-09-30 12:09 AM Tokenize data file
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
I am working on a script (just beginning it) that will have several data files that it will read from. I would like to tokenize (for lack of a better term) the data, yet still be readable by kix. Is there a best practice / udf for something like this?
_________________________
Today is the tomorrow you worried about yesterday.

Top
#148849 - 2005-09-30 12:36 AM Re: Tokenize data file
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Great question ... I would say depends ... what is the nature of this data file ? Is the formatting something you have control over ?
Top
#148850 - 2005-09-30 12:45 AM Re: Tokenize data file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
if you can make the data look like script, then, it should go fine.
_________________________
!

download KiXnet

Top
#148851 - 2005-09-30 12:49 AM Re: Tokenize data file
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
I have complete control of the data file as I will be writing it as well.

The nature of the data is "canned responses" to user input.

The reason for obsufication (sp) of the data files is that I don't want anyone changing the responses.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#148852 - 2005-09-30 12:57 AM Re: Tokenize data file
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Well then, I would have to offer this simple solution (like lonk says), create a response file containing simple $variables, and INCLUDE it into your script ... might look like:

Code:

[responses.kix]
$Welcome = 0
$EULA = 1
$Company = "Acme Corp"
$Name = "John Joe"



etc, etc add nausium ...

A more advanced strategy might be to use XML embedded inside a function (kinda the way we do for Kixforms bitmap resources) ...

Code:

[responses.kix]

Function Responses()

$Responses = "
<xml>
<answer1>yes</answer1>
<answer2>no</answer2>
<answer3>yes</answer3>
</xml>
"

EndFunction



So then in your main, you include the reponse file, then call the function to return the XML string, then use the XML COM object to parse the answers ... like I said - kinda sophisticated and maybe over-the-top (idk)


-Shawn

Top
#148853 - 2005-09-30 01:01 AM Re: Tokenize data file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
if you can do the file like:
$response1 = "the response data"

or array or whatever...
you can then tokenize that and then call the file and use the var defined in it.
_________________________
!

download KiXnet

Top
#148854 - 2005-09-30 01:05 AM Re: Tokenize data file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
dad, your answer was so much.... longer.
and you still were faster.
nice.
_________________________
!

download KiXnet

Top
#148855 - 2005-09-30 01:25 AM Re: Tokenize data file
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Since I don't know XML...

If I did something like this
Code:

;Filename = Data.kix
$ansArray["go home","stay here","take a break","etc","etc"]


and then in the script I could do (and I have never used include so my syntax may be incorrect)
Code:

Include Data.kix
If $result = 7
$text = $ansarray[1]
endif



Then I would tokenize the whole script and it would do wonderfull things for my life in general
_________________________
Today is the tomorrow you worried about yesterday.

Top
#148856 - 2005-09-30 01:28 AM Re: Tokenize data file
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Your array syntax looks a little dodgey ... but otherwise yesim.
Top
#148857 - 2005-09-30 03:01 AM Re: Tokenize data file
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
I was just typing away, but you are correct the array syntax is incorrect. I will make sure that I don't code it that way.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#148858 - 2005-09-30 03:26 AM Re: Tokenize data file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
btw, is it cold up there?
_________________________
!

download KiXnet

Top
#148859 - 2005-09-30 04:13 AM Re: Tokenize data file
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
You could also use the ROT13 udf that most users wouldn't have a clue what it was.
Top
#148860 - 2005-09-30 05:16 AM Re: Tokenize data file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
unless they read the script and find out.
_________________________
!

download KiXnet

Top
#148861 - 2005-09-30 08:10 AM Re: Tokenize data file
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
I really should update my profile, I no longer live in Alaska. Now I live Arizona where we expect a low tonight of around 80F.

As for the ROT13, I have used that in other scripts and it works really well, and is basic enough to implement till you get to the special characters, but I wrote a routine to fix that as well (have to post it tomorrow when I get back to work (vpn is down )
_________________________
Today is the tomorrow you worried about yesterday.

Top
#148862 - 2005-09-30 09:59 AM Re: Tokenize data file
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Quick fix for character sets causing you a problem is simply to convert to two-character hex representation of the ASCII value - this way you only have 0-9,A-F in your strings.

The down-side is that it doubles the size of your data, but where it is short enough that's rarely important. In your case you probably aren't going to exceed the file block size, so you won't be using any additional disk.

Top
#148863 - 2005-09-30 05:23 PM Re: Tokenize data file
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Actually I ended up mistyping what I really meant.

When doing a "sendkey" and you have special characters in the string then I have UDF that I use to ensure that they pass correctly.

Code:

Function CheckString ($letters)
for $i= 1 to Len($letters)
$a = Substr($letters, $i, 1)
Select
Case $a = "+"
$a = "{+}"
Case $a = "^"
$a = "{^}"
Case $a = "~"
$a = "{~}"
Case $a = "("
$a = "{(}"
Case $a = ")"
$a = "{)}"
Case $a = "{"
$a = "{{}"
Case $a = "}"
$a = "{}}"
EndSelect
$s = $s+$a
Next
$checkstring = $s
EndFunction

_________________________
Today is the tomorrow you worried about yesterday.

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 2419 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.071 seconds in which 0.028 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