Page 1 of 1 1
Topic Options
#12093 - 2001-09-04 06:34 PM Reading Config File?
Anonymous
Unregistered


I am getting the default gateway for the pc logging in and would like to set and pass parameters from a file based on the gateway

Preferred File Format:

gateway1|homesrv|datasrv|alias
gateway2|homesrv|datasrv|alias

Top
#12094 - 2001-09-04 06:46 PM Re: Reading Config File?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
ReadProfileString() comes to mind. Basically you can setup a file with the GW address as headers (section). Then under each section, set keys for homeserv, datasrv, etc.
quote:

ReadProfileString()



Action: Retrieves a string from an initialization file.
Syntax: READPROFILESTRING ("file name", "section", "key")
Parameters: File name
- A string that names the initialization file. If this parameter does not include a full path, Windows searches for the file in the Windows directory.
Section
- A string that specifies the section containing the key name. If this parameter is empty, READPROFILESTRING returns all section names in the file.

Key
- A string containing the key name whose associated string is to be retrieved. If this parameter is empty, all key names in the section specified by section are returned.

Remarks: This function is provided for compatibility with 16-bit Windows – based applications. Win32 – based applications store initialization information in the registry.
Returns: 0 Function returns a string representing the value of the specified key
Error code Function failed

Example: $dev = ReadProfileString(“win.ini”, "Windows", "Device")
If @ERROR = 0
? "Windows device = " + $dev
Endif


[ 04 September 2001: Message edited by: LLigetfa ]

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#12095 - 2001-09-04 06:53 PM Re: Reading Config File?
Anonymous
Unregistered


Thanks,
I am currently using readprofile but the file has the potential for getting a bit confusing with all the sections. It is do-able, but I thougt maybe a file much like a host file would be easier to maintain and faster to read? Thoughts?

Top
#12096 - 2001-09-04 06:59 PM Re: Reading Config File?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well... You could pare down the .ini file to just have one section and use the GW as the key instead. Then, concantenate the values with a delimiter.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#12097 - 2001-09-04 07:14 PM Re: Reading Config File?
Anonymous
Unregistered


Thanks,
You hit on the gist of my question.
This is what I am struggling with. How do I concantenate the values with a delimiter.
I'm not comfortable or understanding of the syntax

Top
#12098 - 2001-09-04 07:46 PM Re: Reading Config File?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well... Looks like we're back at square one. So, you setup a file, say call it GW.INI as follows:
code:

[Gateway]
10.198.1.1=homesrv1|datasrv1|alias1
10.198.1.2=homesrv2|datasrv2|alias2

Then with some code, read out the desired line:

code:

break on
$key = "10.198.1.1"
$dev = ReadProfileString("C:\KIX\GW.ini", "Gateway", "$Key")
? $dev
get $

I used your example ( | ) for a delimiter. Just so long as it doesn't naturally occur in the data. Then with string manipulation, split out the values.
See Bryce's examples in http://kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=2&t=002142 on using SPLIT or SUBSTR.

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#12099 - 2001-09-04 08:24 PM Re: Reading Config File?
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
using kix4.0

code:


;using Les's example to read in the data.
break on
$key = "10.198.1.1"
$dev = ReadProfileString("C:\KIX\GW.ini", "Gateway", "$Key")

;$dev now is equal to "homesrv1|datasrv1|alias1"
;split the data in $dev into its separate parts,
;using "|" as a separator

$dev = split($dev,"|")

;check to make sure that the split command was ok,
;and the correct number of parts are there
if UBOUND($dev) = 2
$homesrv = $dev[0]
$datasrv = $dev[1]
$Alias = $dev[2]
endif



Top
#12100 - 2001-09-04 09:25 PM Re: Reading Config File?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Bryce,
Thanks for finishing the job.
SDH,
Not sure about your network setup, but a heads up none the less. On my network, when I dial in, I get a DHCP assigned IP and subsequent matching GW. See http://kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=1&t=003038 for some of my examples.
If the same holds true for you, then I'm afraid, it's back to the drawing board...
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

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
1 registered (Allen) and 581 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.055 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