Michael,

 

As an added bonus I’ve also showed how to write a string to an ini file.

 

Regards

 

Bo Thomsen

GeoConsult I/S

Denmark

 

+++++++++++++++++++++++++++++++++++++++++++++++++++++

Declare sub WritePrivateProfileString32

  Lib "KERNEL32" Alias "WritePrivateProfileStringA"

   (ByVal lpszSection As String,

    ByVal lpszEntry As String, 

    ByVal lpszString As String,

    ByVal lplFileName As String)

 

Declare Function GetPrivateProfileString32

  Lib "kernel32" alias "GetPrivateProfileStringA"

   (ByVal lpApplicationName As String,

    ByVal lpKeyName As String,

    ByVal lpDefault As String,

          lpReturnedString As String,

    ByVal nSize As Integer,

    ByVal lpFileName As String)

  As Integer

 

Declare Function GetIni

   (ByVal IniFile as string,

    ByVal Section As String,

    ByVal key As String,

    ByVal default As String)

  As String

 

Function GetIni

   (ByVal IniFile as string,

    ByVal Section As String,

    ByVal key As String,

    ByVal default As String)

  As String

                                                                                                                        

  Dim sRetVal, sTmp As String                                                                                           

  Dim nWorked As Integer                                                                                                

                                                                                                                         

  sRetVal = string$(1000," ")                                                                                           

  nWorked = GetPrivateProfileString32(

    Section, Key, default, sRetVal, Len(sRetVal), IniFile)                            

  sRetVal = rtrim$(ltrim$(left$(sRetVal, nWorked)))                                                                     

                                                                                                                         

  GetIni = sRetval                                                                                                      

                                                                                                                         

End Function                                                                                                            

 

Declare Sub Main

 

Sub Main

 

  Dim sW, sX, sY , sF as string

 

' I assume, that the ini files resides in the

' same directory as the mbx.

 

  sF = applicationdirectory$()+"myapp.ini"

 

  sW = GetIni(sF,"GENERAL","Workfolder","")

  sX = GetIni(sF,"GENERAL","X","")

  sY = GetIni(sF,"GENERAL","Y","")

 

  Note sW + " " + sX + " " + sY

 

' How to write data to an ini file.

 

  Call WritePrivateProfileString32

    ("GENERAL","NewValue","HURRAY", sF)

 

  Note GetIni(sF,"GENERAL","NewValue","")

 

End Sub     

+++++++++++++++++++++++++++++++++++++++++++++++++++++


Fra: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] På vegne af [EMAIL PROTECTED]
Sendt: 31. maj 2006 07:14
Til: [email protected]
Emne: [MI-L] Reading an INI file

 

Hi,

 

Does anyone have a nice clear example of how to read a key from an INI file?

 

I have an application e.g. “d:\apps\myapp.mb” for which I have created “d:\apps\myapp.ini” which looks like this:

 

[GENERAL]

Workfolder=c:\temp

X=longitude

Y=latitude

 

How would I read the value of each of the keys into separate string variables in myapp.mb?

 

Regards

Michael.

 

Michael Zatorsky
GIS Specialist

Interfaces, Integration & Info Analysis Team

QPRIME Project, Operational Policing Program

Queensland Police Service

e. [EMAIL PROTECTED]

p. +61 7 3015 5566
f. +61 7 3015 5599



**********************************************************************
CONFIDENTIALITY: The information contained in this
electronic mail message and any electronic files attached
to it may be confidential information, and may also be the
subject of legal professional privilege and/or public interest
immunity. If you are not the intended recipient you are
required to delete it. Any use, disclosure or copying of
this message and any attachments is unauthorised. If you
have received this electronic message in error, please
inform the sender or contact [EMAIL PROTECTED]

This footnote also confirms that this email message has
been checked for the presence of computer viruses.
**********************************************************************

_______________________________________________
MapInfo-L mailing list
[email protected]
http://www.directionsmag.com/mailman/listinfo/mapinfo-l

Reply via email to