Page 1 of 1 1
Topic Options
#198988 - 2010-07-12 06:20 PM Reading a variable from .ini file
anaftel Offline
Just in Town

Registered: 2010-07-06
Posts: 4
Loc: Guernsey, UK
I am reading a .ini which contains a variable to the home drive however when read into the array the variable is not resolved meaning I map to \home$\$Specuser which fails instead of \home$\%username%

 Code:
Function GroupMap($inFile, $inSec)
	Dim $tmpDrv
	$Sec = ReadProfileString($inFile, $inSec, "") 
	$aMaps = Split($Sec, Chr(10), -1)
	For Each $a in $aMaps
		$tmpDrv = ReadProfileString($inFile, $inSec, $a)
		$aParms = Split($tmpDrv, ",")                     
		$act = UBound($aParms)
		If $act > 0
			MapDrv($aParms[0], $aParms[1], $aParms[2])
		EndIf
	Next
	$GroupMap = 1
EndFunction ; Reads groups for drive mapping


 Code:
[Authenticated Users]
MapDrive1=H,xxxxx,home$$\$$Specuser
MapDrive2=I,xxxxx,SolarisOutput

Top
#198990 - 2010-07-12 10:00 PM Re: Reading a variable from .ini file [Re: anaftel]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Don't double the $ in the ini data.. also, do you expect $Specuser to be evaluated by $aParms[2]? That's not going to work without an Execute command. Try this simple example:
 Code:
$ = SetOption('NoVarsInStrings', 'On')
$SpecUser = "some data"
$aParms = '$Specuser'
$aParms ?
$ = Execute($aParms) ?
See what happens with the Execute?

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

Top
#199014 - 2010-07-15 06:19 PM Re: Reading a variable from .ini file [Re: Glenn Barnas]
anaftel Offline
Just in Town

Registered: 2010-07-06
Posts: 4
Loc: Guernsey, UK
Thanks for the reply, I can see what happens when I run your code however I am failing to apply this is in the context of my code ...

Any more help appreciated?!

Top
#199019 - 2010-07-15 10:29 PM Re: Reading a variable from .ini file [Re: anaftel]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Try this on for starters:
 Code:
Break On
$_ = SetOption('NoVarsInStrings', 'On')

; This is the defined user info - more likely @USERID or %USERNAME%
; It represents a variable name defined in an external INI file that
; should be substituted with actual data
$SpecUser = @USERID

; This is part of the data read from the INI file - I'm too lazy to 
; deal with this extra code - yours is working fine..
$IniData = 'home$\$$SpecUser\subfolder'		; example with embedded Variable
;$IniData = 'home$\$$SpecUser'			; example with trailing Variable
;$IniData = 'home$\fixedpath'			; example with no Variable


; THIS IS PSEUDO-CODE - no error checking or optimization has been done!!!


'IniData contains: ' $IniData ?			; just for development / debugging


; Check to see if the INI data requires a variable lookup / replacement
If InStr($IniData, '$$')			; have replacement varname!
  ; define part 1 of the path
  $Part1 = Left($IniData, InStr($IniData, '$$') - 1)
  'Part1 contains: ' $Part1 ?			; just for development / debugging

  ; define a working var containing the rest of the data
  $Work = SubStr($IniData, InStr($IniData, '$$') + 2)
  'Work contains: ' $Work ?			; just for development / debugging

  ; WORK contains the variable name and any extra data.. 
  ; determine the variable name part

  ; This string contains all of the characters that define the end of a variable name
  ; THIS list is not complete
  $VarTerms = Chr(9) + Chr(36) + " .,$<>():;'\|/+=" ; list of most variable termination chars

  ; Loop until all characters have been evaluated
  While Len($Work) > 0
    $C = Left($Work, 1)				; take the first/next character
    If Not InStr($VarTerms, $C)			; don't have a var termination char, so
      $VarName = $VarName + $C			; add the char to the varname variable
      $Work = SubStr($Work, 2)			; trim the work string
    Else
      $Part2 = $Work $Work = ''			; we've terminated, so assign the rest to Part2
    EndIf					; and clear WORK to end the loop
  Loop
  'Varname contains: ' $VarName ?		; just for development / debugging

  $VarName = Chr(36) + $VarName			; add the "$"

  'Varname contains: ' $VarName ?		; just for development / debugging
  'Part2 contains: ' $Part2 ?			; just for development / debugging

  $So = SetOption('NoVarsInStrings', 'Off')
  $ = Execute('$Value = $VarName')		; push the extracted variable data into $Value
  $ = SetOption('NoVarsInStrings', $So)

  $Path = $Part1 + $Value + $Part2		; build the complete path

Else

  $Path = $IniData				; don't make any changes if no $$ was found
  
EndIf

'Path=' $Path ?
Glenn
_________________________
Actually I am a Rocket Scientist! \:D

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
1 registered (Allen) and 977 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.055 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

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