Page 1 of 1 1
Topic Options
#76296 - 2003-08-08 09:20 AM Execute() variable functions
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
Guys,

I use an Ini file to do stuff. Each section is a function in my script.
How can I start the functions???

I tried:
code:
$rc=SetOption('NoVarsInStrings','ON')

$Sections=Split(ReadProfileString($KiXLogonIni,'',''),Chr(10))
For Each $Section In $Sections
If $Section
$rc=Execute('$rc=$section()')
EndIf
Next

But no go...
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#76297 - 2003-08-08 09:25 AM Re: Execute() variable functions
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
ummm, just a guess

do try


$rc=SetOption('NoVarsInStrings','ON')

$Sections=Split(ReadProfileString($KiXLogonIni,'',''),Chr(10))
For Each $Section In $Sections
If $Section
$rc=Execute('$$rc=' + $section + '()')
EndIf
Next


[ 08. August 2003, 09:26: Message edited by: Jochen ]
_________________________



Top
#76298 - 2003-08-08 09:29 AM Re: Execute() variable functions
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
[Frown] [Frown]

Results in:

ERROR : undefined variable [$]!
Script: Y:\KiXLogon\KiXLogon.kix
Line : 0
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#76299 - 2003-08-08 09:36 AM Re: Execute() variable functions
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
need to test then if workload allows...

Hmmm ... actually i think this was tried before, not sure though [Confused]
_________________________



Top
#76300 - 2003-08-08 09:40 AM Re: Execute() variable functions
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Patick,

Think you would need something like:

code:
[functions]
AddNum=1
SubNum=1

and this:

code:
$rc=SetOption('NoVarsInStrings','ON')

$Sections=Split(ReadProfileString("c:\t.ini",'functions',''),Chr(10))
For Each $Section In $Sections
If $Section
$rc=Execute('$$rc=' + $section + '()')
EndIf
Next

Function AddNum()
?"In AddNum"
EndFunction

Function SubNum()
?"In SubNum"
EndFunction


Top
#76301 - 2003-08-08 09:44 AM Re: Execute() variable functions
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
I had success with this :


break on

$KiXlogonIni = @scriptdir + '\KiXLogon.ini'


$rc=SetOption('NoVarsInStrings','ON')

$Sections=Split(ReadProfileString($KiXLogonIni,'',''),Chr(10))
For Each $Section In $Sections
If $Section
$rc=Execute('$$rc=' + $section + '()')
EndIf
Next

"end"
get $

function test()
"test" ?
endfunction

function test1()
"test1" ?
endfunction

function test2()
"test2" ?
endfunction


KiXlogon.Ini :

code:
 [test]
[test1]
[test2]

not sure though if you wanted this!

Hey, Good morning Shawn [Eek!]
Is this Insomnia ?
_________________________



Top
#76302 - 2003-08-08 09:45 AM Re: Execute() variable functions
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
I do this in an IE based GUI application to call events in the scripts.

Each of the functions in my script registers itself, then IE fires an event which is the function - if the function is registered it is called using execute.

So, it is possible and does work. I suspect that the combination of NoVarsInStrings an doubling up the "$" is the problem.

Try this:
code:
$rc=SetOption('NoVarsInStrings','ON')

$Sections=Split(ReadProfileString($KiXLogonIni,'',''),Chr(10))
For Each $Section In $Sections
If $Section
$Discard=Execute('$rc=' + $section + '() ; Exit @ERROR')
EndIf
Next

Including the "; Exit @ERROR" preserves any @ERROR value returned by your function so that it can be tested in your main script.

I've discarded the return value from the Execute(), as I assume you are more interested in the return value of the function.

Top
#76303 - 2003-08-08 09:47 AM Re: Execute() variable functions
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
Could be...

But this did it for me:

code:
$rc=Execute('$rc=' + $section + '()')

with an ini like

code:
[DRIVES]
Personal=P,\\server\personalshare
Group=G,\\server\groupshare
[REGIMPORT]
Yada=\\server\netlogon\reggies\Yada.reg

_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#76304 - 2003-08-08 09:47 AM Re: Execute() variable functions
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I haven't slept in I don't know how long ... I'm still at the office ... but its great to see guys around, little bit of company on a lonely night ...
Top
#76305 - 2003-08-08 09:48 AM Re: Execute() variable functions
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
You got your msn there ?
_________________________



Top
#76306 - 2003-08-08 09:49 AM Re: Execute() variable functions
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Well, yes and no, you know the score with my msm here, its up and down like a toilet seat [Frown]
Top
#76307 - 2003-08-08 09:52 AM Re: Execute() variable functions
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
yeah. remember [Frown]

dang Shawn ! What are you into ? Slavery ?
_________________________



Top
#76308 - 2003-08-08 10:37 AM Re: Execute() variable functions
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
ja, im starting to see double, not kidding, need sleep.
Top
#76309 - 2003-08-13 08:10 AM Re: Execute() variable functions
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Shawn -- You need to copyright the toilet seat thing.. [Wink]

Kent

[ 13. August 2003, 08:11: Message edited by: kdyer ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#76310 - 2003-08-13 02:15 PM Re: Execute() variable functions
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, as all have given their shot...

pat, why not remove the first line of your initial code and add second dollar to $rc:
code:
$Sections=Split(ReadProfileString($KiXLogonIni,'',''),Chr(10))
For Each $Section In $Sections
If $Section
$rc=Execute('$$rc=$section()')
EndIf
Next

basically just the same but better golf-score [Wink]
_________________________
!

download KiXnet

Top
#76311 - 2003-08-13 02:29 PM Re: Execute() variable functions
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
Works (maybe),

but I'd like to avoid the strings in vars thingie...

[ 13. August 2003, 14:31: Message edited by: MightyR1 ]
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

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 640 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.07 seconds in which 0.025 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