Page 1 of 2 12>
Topic Options
#193419 - 2009-04-14 03:08 PM Multiple Scripts and Parsing
crmsonknight Offline
Fresh Scripter

Registered: 2009-03-20
Posts: 17
Loc: NH USA
I am trying to write a script that will call or shell to another script based on @USERID then return back to the original script. However, I need to parse part of that userid and use that to base which script it calls. Is there a way to do this?


Thank you all in advance!!!

Top
#193420 - 2009-04-14 03:14 PM Re: Multiple Scripts and Parsing [Re: crmsonknight]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Do you have any code you're playing with (real or pseudo) that will give us a better idea of what you need?

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#193421 - 2009-04-14 03:32 PM Re: Multiple Scripts and Parsing [Re: Glenn Barnas]
crmsonknight Offline
Fresh Scripter

Registered: 2009-03-20
Posts: 17
Loc: NH USA
; UserID Settings
Select
Case @USERID = "601"
Call "NODE601.kix"
Case @USERID = "602"
Call "NODE602.kix"
Case @USERID = "603"
Call "NODE603.kix"
Case 1
? "Warning! Unknown User"
? "Please Call The Help Desk!"
EndSelect

The full username is 601Agent_01 or 601Mgr_01 and I'd like to parse the first 3 numbers off of it.

Top
#193422 - 2009-04-14 03:42 PM Re: Multiple Scripts and Parsing [Re: crmsonknight]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
This should get you started.

 Code:
;Get the 1st, 2nd and 3rd character of the user id.
$id = SubStr(@USERID, 1, 3)

;See if the $id variable holds valid data.
If $id = "601" Or $id = "602" Or $id = "603"
	Call "NODE" + $id + ".kix"
Else
	? "Warning! Unknown User"
	? "Please Call The Help Desk!"
EndIf


Oh and btw please use code tags when posting code. The formatting will be preserved that way so it is easier to read especially with large scripts.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#193427 - 2009-04-14 05:06 PM Re: Multiple Scripts and Parsing [Re: Mart]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Another tactic, which eliminates coding changes as new "nodes" are added:
 Code:
$File = 'NODE' + Left(@USERID, 3) + '.kix'
If Exist($File)
  Call $File
Else
  'Warning! Unknown user' @CRLF 'Please contact the help desk!' ?
EndIf

Adding a new script "NODE###.kix" is all you need to do to support another group of users.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#193428 - 2009-04-14 05:37 PM Re: Multiple Scripts and Parsing [Re: Glenn Barnas]
crmsonknight Offline
Fresh Scripter

Registered: 2009-03-20
Posts: 17
Loc: NH USA
Thanks Guys!!!!!! Those are perfect!!!
Top
#193429 - 2009-04-14 05:56 PM Re: Multiple Scripts and Parsing [Re: crmsonknight]
crmsonknight Offline
Fresh Scripter

Registered: 2009-03-20
Posts: 17
Loc: NH USA
Do you guys know if the variables stored in sub scripts are still valid in the main script? If I call script node601.kix from login.kix and I use a variable in node601.kix, can i make a call to it in login.kix. I think I would but just want to be sure!
Thanks!

Top
#193430 - 2009-04-15 12:05 AM Re: Multiple Scripts and Parsing [Re: crmsonknight]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
To be sure, declare the var as a global in your main script. Don't leave things to chance by not declaring them.

Works great, actually.. I declare $PROCNAME as a global in my main script. Subscripts immediately set $PROCNAME="myname" and load some UDFs. Each UDF in a subscript begins with "MyName", so I can make calls (via Exec) like this:
 Code:
$Fn = $MyName + '_Init()'
Exec($Fn)

This initializes the module, which often calls other functions from the sub-script. I have an app that dynamically loads and defines specific capabilities in this way - add a file, you add functionality. Delete a file, remove functionality.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#193439 - 2009-04-15 03:28 PM Re: Multiple Scripts and Parsing [Re: Glenn Barnas]
crmsonknight Offline
Fresh Scripter

Registered: 2009-03-20
Posts: 17
Loc: NH USA
Ok...I'm a bit new to scripting....How do you declare things as globals?
Top
#193441 - 2009-04-15 04:00 PM Re: Multiple Scripts and Parsing [Re: crmsonknight]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Global $VarName
vs
Dim $VarName

Undeclared vars default to globals and will get you into trouble. ALWAYS declare your vars via GLOBAL or DIM commands.

Use of $=SetOption('Explicit', 'On') will prevent the script from running with undeclared vars. There are several SetOption settings that will enforce good coding habits, including NoVarsInStrings and NoMacrosInStrings. WrapAtEOF is also recommended for console scripts.

Use of KGen (or at least the Sanity() UDF) will report all undeclared vars.

KGen is part of the Kix-Dev package on my web site, and includes the Sanity feature. It's a UDF resolver (kind of like a linker).

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#193442 - 2009-04-15 04:31 PM Re: Multiple Scripts and Parsing [Re: Glenn Barnas]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
 Originally Posted By: Glenn Barnas

....
WrapAtEOF is also recommended for console scripts.
....


WrapAtEOL would be even better \:D

Sorry Glenn, just rattling your chain.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#193444 - 2009-04-15 04:43 PM Re: Multiple Scripts and Parsing [Re: Mart]
crmsonknight Offline
Fresh Scripter

Registered: 2009-03-20
Posts: 17
Loc: NH USA
ok...let me say I'm way new to scripting and still do not understand what you are saying guys...dumb it down for me please...looks like i need the spoon feeding...sorry
Top
#193445 - 2009-04-15 04:56 PM Re: Multiple Scripts and Parsing [Re: crmsonknight]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
LOL

If you do not declare the variables at the top of your script then KiXtart assumes that they are to be used as Global variables. So the variables can be used in the master script and child scripts until the kix32 or wkix32 session is ended by you or when the script is finished.

Declaring the variables will save you some headaches.

If you use Dim $var1, $var2, $var3 at the top of your script then the variables are available to the script that decaled them using the DIM command. If you replace DIM by GLOBAL then they are available for the master and all child scripts.

Using SetOption("Explicit","On") will tell kix that all variables MUST be declared and if they are not the script just wont run. This is just one of the little helpers to move to best practice scripting.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#193451 - 2009-04-16 04:49 AM Re: Multiple Scripts and Parsing [Re: Mart]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
EOL - yeah - right . . . Really meant "EOFL", since that damn Line was really getting on my nerves all day. ('specially with the damn chain rattling all the time!!) \:D

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#193452 - 2009-04-16 04:57 AM Re: Multiple Scripts and Parsing [Re: crmsonknight]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Sir Crimson

You might want to take a look at this post for a recent discsussion about coding style, variable declarations, and use of the (correct) SetOption parameters such as NoMacrosInStrings, NoVarsInStrings, and (my personal favorite) WrapAtEOL! ;\)

There are some other discussions and code critiques on the board that will help you understand why having a consistent coding style will help you, as well as the reasons for declaring vars and setting options in your scripts - especially as they get more complex.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#193496 - 2009-04-17 06:45 PM Re: Multiple Scripts and Parsing [Re: Glenn Barnas]
crmsonknight Offline
Fresh Scripter

Registered: 2009-03-20
Posts: 17
Loc: NH USA
ok, i think i'm starting to understand... so if I do the following:
SetOption("Explicit","On")
Global $NODE
Global $Cache
then call the var $Cache or $NODE later in the script....?
If I call a child script from a main, how do i get it to return to the main script? In the child, I've got several different goto's and what I was thinking was that if I have a tag in the main called common and in the child say goto common that should work right?

Top
#193498 - 2009-04-17 08:00 PM Re: Multiple Scripts and Parsing [Re: crmsonknight]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Using GOTO is bad on many levels. Lets say, for example, that I said "GOTO Post-109423" to get your answer. Where would you reply? That thread?, this original thread? or some other thread entirely?

GOSUB is a little bit better, and a good way to get used to functions. I could say "GOSUB Post-109423" to get more info, but when you're done reading that post, RETURN to the original post. GOSUB calls a SUBROUTINE by name that performs some task and returns to the original location (line following the gosub, actually). GOSUBs are OK, but you can't exchange data with them. They are part of the main program and have no isolation of variable names or data. Subroutines MODIFY THE ORIGINAL DATA.

Functions are the best because they provide a completely isolated environment - you can pass data to a function and it will get a COPY of the data. It can perform calculations and manipulate that data any way it wants without affecting the original data. You can return a COPY of the function's data back to the main program (where it can replace its copy with the modified data if you choose). Functions can also return result codes via EXIT, which can be checked by examining @ERROR, making it easy to tell if a function did its job successfully or not.

I'll post some code that will provide a few simple examples later this evening.. You should get the concept more clearly from those.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#193499 - 2009-04-17 08:07 PM Re: Multiple Scripts and Parsing [Re: Glenn Barnas]
crmsonknight Offline
Fresh Scripter

Registered: 2009-03-20
Posts: 17
Loc: NH USA
Thank you I appreciate your time and input. This is what I'm trying to do.

 Code:
If @USERID = "601Mgr_03" GOTO RM601C
endif

:RM6010
writevalue ("HKEY_CURRENT_USER\Environment", "Station", "601100", "REG_SZ")
writevalue ("HKEY_CURRENT_USER\Environment", "Extension", "601100", "REG_SZ")
writevalue ("HKEY_CURRENT_USER\Control Panel\Mouse", "SwapMouseButtons", "1", "REG_SZ")
goto Common

:Common
writevalue ("HKEY_CURRENT_USER\Environment", "Formcache", "C:\Cache\cache%station%", "REG_SZ")
writevalue ("HKEY_CURRENT_USER\Environment", "Extension", %Ext%, "REG_SZ")
goto end

Top
#193500 - 2009-04-17 08:08 PM Re: Multiple Scripts and Parsing [Re: crmsonknight]
crmsonknight Offline
Fresh Scripter

Registered: 2009-03-20
Posts: 17
Loc: NH USA
ok to my last post I realize my userid doesn't match...it's a snippit of what i'm trying to do....assume that userid is the same as the tag RM6010 please.
Top
#193501 - 2009-04-17 08:14 PM Re: Multiple Scripts and Parsing [Re: crmsonknight]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Dependent on how many users that need custom settings...

 Code:
Select
  Case @UserID = "601MGR_03"
    writevalue ("HKEY_CURRENT_USER\Environment", "Station", "601100", "REG_SZ")
    writevalue ("HKEY_CURRENT_USER\Environment", "Extension", "601100", "REG_SZ")
    writevalue ("HKEY_CURRENT_USER\Control Panel\Mouse", "SwapMouseButtons", "1", "REG_SZ")
  Case @UserID = "602MGR_01"
    writevalue ("HKEY_CURRENT_USER\Environment", "Station", "601100", "REG_SZ")
    writevalue ("HKEY_CURRENT_USER\Environment", "Extension", "601100", "REG_SZ")
    writevalue ("HKEY_CURRENT_USER\Control 
  Case 1
    ;Maybe write to a log file or just do nothing
EndSelect

LoadCommon()

Function LoadCommon()
  writevalue ("HKEY_CURRENT_USER\Environment", "Formcache", "C:\Cache\cache%station%", "REG_SZ")
  writevalue ("HKEY_CURRENT_USER\Environment", "Extension", %Ext%, "REG_SZ")
  $Function = @Error
EndFunction


Edited by Gargoyle (2009-04-17 08:15 PM)
Edit Reason: bad copy/paste
_________________________
Today is the tomorrow you worried about yesterday.

Top
Page 1 of 2 12>


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

Who's Online
0 registered and 657 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.083 seconds in which 0.034 seconds were spent on a total of 14 queries. Zlib compression enabled.

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