Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] - [Matrix1]Reading INI files

Author
Message
Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 6th Jun 2012 15:20 Edited at: 9th Jun 2012 23:04
This is a simple example of how to lookup information in an INI file using Matrix1 Utilities



These are extra functions that you may find useful when reading information that requires constraints

Lookup#( iLookupId, sKey$, fDefault#, fMin#, fMax# )
Get a number from a lookup table and clamp it in range.
For example: If you need a number between 0 and 10
and the lookup (or INI) field specifies 1000.
the function will return 10. If -2 was received, it will
return 0. If the field does not exist it will return the
default parameter value

Lookup( iLookupId, sKey$, iDefault, iMin, iMax )
This is an integer version of the Lookup# function

LookupBool( iLookupId, sKey$ )
DBPRO will not clamp boolean values between 0 and 1. This
lookup function can only return 0 or 1. If any lookup value
is below zero, then zero is returned. If any value is higher
than zero, then you will get back a value of 1.

LookupColour( iIni, sColourKey$, iDefault )
This function will return a colour value from a comma seperated
RGB or ARGB field. For example, a string with "255,255,255" will
cause the function to return an integer value representing white.
A value of "128,255,0,0" will return an integer value representing
a semi-transparent red. If you use only two numbers, such as "128,255"
then the function will use the first to represent the alpha
transparency, and the latter will represent a grade of grey.

CurrentLookupByte( iLookupId )
CurrentLookupBool( iLookupId )
CurrentLookupValue( iLookupId )
These three functions return numeric values from the current lookup string. The current lookup is set using First Lookup, Next Lookup and other similar functions outlined in the Matrix1 utility 31 documentation.

LookupP( iLookup, sKey$,fDefX#,fDefY#,fDefZ#,fMin#, fMax# )
This function requires the use of the attached UDT called
PosType. It will store the position specified in a comma
seperated string, such as '0,10,20', and store it in the
X#, Y# & Z# fields of the NewPos UDT variable, which you
must initiate before using this function.
The function will also limit the position to a bounding
area so that your positions do not go off course. There
is also a default position if the location was not specified

Note that if only 1 or 2 numbers are specified, only x or x & y
values are obtained respectively. The missing information is
defaulted to your default specification.

LookupPos( iLookup, sKey$,fDefX#,fDefY#,fDefZ#, arrayPtr, index )
Similar to LookupP, this time the function stores the position in a UDT array of the PosType class, which you need to pass a pointer for, using the Get ArrayPtr function. Note that if only 1 or 2 numbers are specified, only x or x & y values are obtained respectively. The missing information is defaulted to your default specification.

The functions:


PosType UDT:


Le Verdier
12
Years of Service
User Offline
Joined: 10th Jan 2012
Location: In the mosh-pit
Posted: 9th Jun 2012 18:36
Useful functions
LookUps are useful...
But consider using IntVal() when reading ints
Val() may be inaccurate for large numbers
IntVal() is included in Matrix1 DLL's too


Chris Tate
DBPro Master
15
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 9th Jun 2012 23:03
Thanks for that Le Verdier. I will do.

Login to post a reply

Server time is: 2024-04-19 21:16:49
Your offset time is: 2024-04-19 21:16:49