Page 1 of 2 12>
Topic Options
#75987 - 2003-07-18 07:25 PM ENUMINI() - Trying to create a new UDF
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Trying to get this to work.. Any comments, ideas, etc. are welcome. [Smile]

It works, but does not "return" anything in it's current state:
code:
CLS
BREAK ON
;ENUMINI
$fl=@scriptdir+'\test.ini'
$rc=ENUMINI($fl)
$rc
sleep 2
FUNCTION ENUMINI($fl)
DIM $fl,$line,$section,$key,$r
IF EXIST($fl)
$rc=Open(1,$fl)
$line=ReadLine(1)
WHILE @error=0
IF LEFT($line,1)=';' ;IGNORE COMMENTS
ENDIF
IF LEFT($line,1)='['
$section=substr($line,2,len($line)-2)
ENDIF
IF NOT INSTR($line,'[')
$key=SPLIT($line,'=')[0]
ENDIF
IF $section<>'' AND $key<>'' ;Be sure both of these are populated
;sections and keys are done, let's do the READPROFILESTRING
$r=READPROFILESTRING($fl,$section,$key)
ENDIF
$line=ReadLine(1)
LOOP
close(1)
ENDIF
ENDFUNCTION

TEST.INI is -
code:
[DOMAIN1\PDX]
;H='\\SERVER7\'+@userid+'$$'
R=\\SERVER5\APPS
S=\\SERVER6\SHARED

[DOMAIN2\PDX]
H='\\SERVER7\'+@userid+'$$'
R=\\SERVER5\APPS
S=\\SERVER6\SHARED

[DOMAIN1\Info_Technology]
G=\\SERVER7\IS

Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#75988 - 2003-07-18 07:35 PM Re: ENUMINI() - Trying to create a new UDF
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
What is the purpose of this?

Is READPROFILESTRING/WRITEPROFILESTRING not sufficient?

What is it supposed to return?

Why do you never assign a return value?
_________________________
There are two types of vessels, submarines and targets.

Top
#75989 - 2003-07-18 07:40 PM Re: ENUMINI() - Trying to create a new UDF
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
The purpose being is to generate the $section and $key by reading through the INI file without knowing these values. In other words, "automating" this process.

So...

What the intent was to -
  • Read the lines..
  • Determine if it is commented, header, key, etc.
  • Once all parameters are found for READPROFILESTRING, it would do just that.
If there is a better way to do this, I am open to suggestions.
Thanks,
Kent

[ 18. July 2003, 19:41: Message edited by: kdyer ]
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#75990 - 2003-07-18 07:50 PM Re: ENUMINI() - Trying to create a new UDF
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
You can enum sections and keys with READPROFILESTRING().
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#75991 - 2003-07-18 07:51 PM Re: ENUMINI() - Trying to create a new UDF
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You mean this:
code:
$sections=split(readprofilestring($fl,'',''),chr(10)
for each $sectionentry in $sections
? 'Section = '+$sectionentry
$keys=split(readprofilestring($fl,$sectionentry,''),chr(10)
for each $sectionkey in $keys
? 'Key "'+$sectionkey+'" = "'+readprofilestring($fl,$sectionentry,$sectionkey)+'"'
next
next

See the KiXtart Manual, too.

And throw in an EXECUTE statement to convert the macros.

[ 18. July 2003, 19:55: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#75992 - 2003-07-18 07:56 PM Re: ENUMINI() - Trying to create a new UDF
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
enuming with readprofilestring is just a looot slower.
you will loose many milliseconds with that method on little larger files [Big Grin]
_________________________
!

download KiXnet

Top
#75993 - 2003-07-18 08:26 PM Re: ENUMINI() - Trying to create a new UDF
Kdyer Offline
KiX Supporter
*****

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

Works great with a couple of mods. [Wink]

code:
 $sections=split(readprofilestring($fl,'',''),chr(10))
FOR EACH $sectionentry IN $sections
IF $sectionentry <>''
?'Section '+$sectionentry
$keys=split(readprofilestring($fl,$sectionentry,''),chr(10))
FOR EACH $sectionkey IN $keys
IF $sectionkey <>''
? 'Key "'+$sectionkey+'" = "'+readprofilestring($fl,$sectionentry,$sectionkey)+'"'
ENDIF
NEXT
ENDIF
NEXT

Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#75994 - 2003-07-18 08:57 PM Re: ENUMINI() - Trying to create a new UDF
Kdyer Offline
KiX Supporter
*****

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

Seems to work ok, but...

Here is the changed code -
code:
 CLS
BREAK ON
;ENUMINI
$fl=@scriptdir+'\test.ini'
ENUMINI($fl)
FUNCTION ENUMINI($fl)
$sections=split(readprofilestring($fl,'',''),chr(10))
FOR EACH $sectionentry IN $sections
IF $sectionentry <>''
?'Section '+$sectionentry
$keys=split(readprofilestring($fl,$sectionentry,''),chr(10))
FOR EACH $sectionkey IN $keys
IF $sectionkey <>''
? 'Key "'+$sectionkey+'" = "'+readprofilestring($fl,$sectionentry,$sectionkey)+'"'
$resource=readprofilestring($fl,$sectionentry,$sectionkey)
IF INGROUP($sectionentry)
USE $sectionkey+':' $resource
ENDIF
ENDIF
NEXT
ENDIF
NEXT
ENDFUNCTION

The problem is that if I want to map the drive using a $ share (personal drive), it is not picked up. I have used single $, double $$, and chr(36) and these do not work..

Here is the modified INI file -
code:
[DOMAIN1\PDX]
H=\\SERVER7\@userid+'$$'
R=\\SERVER5\APPS
S=\\SERVER6\SHARED
[DOMAIN2\PDX]
H=\\SERVER7\@userid+'$$'
R=\\SERVER5\APPS
S=\\SERVER6\SHARED
[DOMAIN1\Info_Technology]
G=\\SERVER7\IS

Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#75995 - 2003-07-18 08:59 PM Re: ENUMINI() - Trying to create a new UDF
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
As I already mentioned, you will need to throw in an EXECUTE in order to translate the @USERID.
_________________________
There are two types of vessels, submarines and targets.

Top
#75996 - 2003-07-18 09:00 PM Re: ENUMINI() - Trying to create a new UDF
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
You need to "execute" the string to get the "$" appended.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#75997 - 2003-07-18 10:02 PM Re: ENUMINI() - Trying to create a new UDF
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
OK.. I am feeling a little slow as I have not used the EXECUTE() before. [Frown]

Here is the code at this point -
code:
 CLS
BREAK ON
$fl=@scriptdir+'\test.ini'
ENUMINI($fl)
FUNCTION ENUMINI($fl)
$sections=split(readprofilestring($fl,'',''),chr(10))
FOR EACH $sectionentry IN $sections
IF $sectionentry <>''
?'Section '+$sectionentry
$keys=split(readprofilestring($fl,$sectionentry,''),chr(10))
FOR EACH $sectionkey IN $keys
IF $sectionkey <>''
? 'Key "'+$sectionkey+'" = "'+readprofilestring($fl,$sectionentry,$sectionkey)+'"'
$resource=readprofilestring($fl,$sectionentry,$sectionkey)
IF INSTR($resource,'$')
$server=SPLIT($resource,'\')[2]
$nul=Execute('$$resource = '+@userid+'$$')
;$nul=Execute('$$resource = '+@USERID+'$$')
;?$$resource
IF INGROUP($sectionentry)
;USE $sectionkey+':' '\\'+$server+'\'+$$resource+'$$'
USE $sectionkey+':' '\\'+$server+'\'+@userid+'$$'
ENDIF
ELSE
IF INGROUP($sectionentry)
USE $sectionkey+':' $resource
ENDIF
ENDIF
ENDIF
NEXT
ENDIF
NEXT
ENDFUNCTION

I am sure that this can be improved upon.

Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#75998 - 2003-07-18 10:12 PM Re: ENUMINI() - Trying to create a new UDF
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
code:
; assuming NoVarsInStrings=ON
; otherwise double up all $
$value="'\\SERVER7\'+@userid+'$'"
$iRC=execute("$value="+$value)

_________________________
There are two types of vessels, submarines and targets.

Top
#75999 - 2003-07-18 10:12 PM Re: ENUMINI() - Trying to create a new UDF
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
What does this give you:

code:
CLS
BREAK ON
$fl=@scriptdir+'\test.ini'
ENUMINI($fl)
FUNCTION ENUMINI($fl)
$sections=split(readprofilestring($fl,'',''),chr(10))
FOR EACH $sectionentry IN $sections
IF $sectionentry <>''
?'Section '+$sectionentry
$keys=split(readprofilestring($fl,$sectionentry,''),chr(10))
FOR EACH $sectionkey IN $keys
IF $sectionkey <>''
? 'Key "'+$sectionkey+'" = "'+readprofilestring($fl,$sectionentry,$sectionkey)+'"'
$resource=readprofilestring($fl,$sectionentry,$sectionkey)
$rc=execute("$$resource="+$resource)
IF INGROUP($sectionentry)
USE $sectionkey+':' $resource
ENDIF
ELSE
IF INGROUP($sectionentry)
USE $sectionkey+':' $resource
ENDIF
ENDIF
ENDIF
NEXT
ENDIF
NEXT
ENDFUNCTION


_________________________
Home page: http://www.kixhelp.com/hb/

Top
#76000 - 2003-07-18 11:02 PM Re: ENUMINI() - Trying to create a new UDF
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
wasn't the topic enumini UDF and not USE command?
this is not even close to the original topic anymore...
_________________________
!

download KiXnet

Top
#76001 - 2003-07-18 11:04 PM Re: ENUMINI() - Trying to create a new UDF
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Jooel: Take a look at the sample .INI file.
_________________________
There are two types of vessels, submarines and targets.

Top
#76002 - 2003-07-18 11:12 PM Re: ENUMINI() - Trying to create a new UDF
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yes?
it does not matter what the ini looks like.
enum function should not start to convert the stuff the ini has.
it should enum it.
_________________________
!

download KiXnet

Top
#76003 - 2003-07-18 11:15 PM Re: ENUMINI() - Trying to create a new UDF
Kdyer Offline
KiX Supporter
*****

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

Here are the results -
quote:

Key "H" = "\\SERVER7\@userid+'$$'"KDyer$

Jens -
code:
H="'\\SERVER7\'+@userid+'$'"

Works fine with NoVarsInStrings.

Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#76004 - 2003-07-18 11:28 PM Re: ENUMINI() - Trying to create a new UDF
Kdyer Offline
KiX Supporter
*****

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

This appears to work too -

With NoVarsInStrings:
code:
H=\\SERVER7\+@userid+'$'

Without NoVarsInStrings:
code:
H=\\SERVER7\+@userid+'$$'

Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#76005 - 2003-07-19 08:46 AM Re: ENUMINI() - Trying to create a new UDF
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Two other variations - DELPROFILESTRING.. I think there is a version of this using WRITEPROFILESTRING in PostPrep.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#76006 - 2003-07-19 02:49 PM Re: ENUMINI() - Trying to create a new UDF
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
DELPROFILESTRING? [Confused]

WRITEPEROFILESTRING with empty value/key/section will delete the appropriate value/key/section.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 2 12>


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

Who's Online
0 registered and 778 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.112 seconds in which 0.077 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