ASP MagicINI Object  

The MagicINI object allows you to manipulate INI files from an Active Server Page. You can create INI entrees, read them, change and delete values and sections.

 
 

Methods

  WriteString Method
ReadString Method
DeleteSection Method
DeleteString Method
CheckKey Method
GetLastErrorNbr Method
GetLastErrorDscr Method

 

Working with MagicINI

To call the MagicINI Object from an Active Server Page, you will need to create the object using the following code:

<%MyObj = Server.CreateObject("MagicBundle.MagicINI")%>

Remember to enclose the code within <% %> brackets.
 
WriteString Method
Copies a string into the specified section of the specified initialization file.
Return Value: Nonzero if successful; otherwise 0.
Syntax: object.WriteString(strApp, strKey, strVal, strFile)

Example: The following example creates new entree "LastName" in the file "d:\temp\userinf.ini" under Section "UserInformation" equals to "Ivanov":

<%
Set MyObj=Server.CreateObject("MagicBundle.MagicINI")
lpappname = "UserInformation"
lpkeyname = "LastName"
lpfilename = "d:\temp\userinf.ini"
if myobj.WriteString(lpappname, lpkeyname, "Ivanov", lpfilename) then
     response.write "Value is written successfully"
else
    response.write("Error #" & MyObj.GetLastErrorNbr & " occurred:")
    response.write(MyObj.GetLastErrorDscr)
end if
%>
Note: If file or section name does not exist function WriteString will create for you automatically.
ReadString Method
Retrieves a string from the specified section in an initialization file.
Return Value: key value if successful; otherwise empty string.
Syntax: object.ReadString(strApp, strKey, strFile)

Example: This example returns value of the "LastName" key under "UserInformation" section.

<%
Set MyObj=Server.CreateObject("MagicBundle.MagicINI")
lpappname = "UserInformation"
lpkeyname = "LastName"
lpfilename = "d:\temp\userinf.ini"
mystr = myobj.ReadString(lpappname, lpkeyname, lpfilename)
if mystr<>"" then
  response.write "Last Name is " & mystr
else
  response.write("Error #" & MyObj.GetLastErrorNbr & " occurred:")
  response.write(MyObj.GetLastErrorDscr)
end if
%>
DeleteSection Method
Deletes all contexts of the section.
Return Value: Nonzero if successful; otherwise 0.
Syntax: object.DeleteSection(strApp, strFile)

Example: This example deletes "UserInformation" section from file "d:\temp\userinf.ini"

<%
Set MyObj=Server.CreateObject("MagicBundle.MagicINI")
lpappname = "UserInformation"
lpfilename = "d:\temp\userinf.ini"
if myobj.DeleteSection(lpappname, lpfilename) then
     response.write "Deleted successfully"
else
    response.write("Error #" & MyObj.GetLastErrorNbr & " occurred:")
    response.write(MyObj.GetLastErrorDscr)
end if
%>
DeleteString Method
Deletes string contexts of the section.
Return Value: Nonzero if successful; otherwise 0.
Syntax: object.DeleteString(strApp, strKey, strFile)

Example: This example deletes key and associated value in "LastName".

<%
Set MyObj=Server.CreateObject("MagicBundle.MagicINI")
lpappname = "UserInformation"
lpkeyname = "LastName"
lpfilename = "d:\temp\userinf.ini"
if myobj.DeleteString(lpappname, lpkeyname, lpfilename) then
     response.write "Value is deleted successfully."
else
    response.write("Error #" & MyObj.GetLastErrorNbr & " occurred:")
    response.write(MyObj.GetLastErrorDscr)
end if
%>
CheckKey Method
Search a key in the specified section in an initialization file.
Return Value: Nonzero if successful; otherwise 0.
Syntax: object.CheckKey(strApp, strKey, strFile)

Example: This example searches the key "LastName" in the "UserInformation" section in the file "d:\temp\userinf.ini"

<%
Set MyObj=Server.CreateObject("MagicBundle.MagicINI")
lpappname = "UserInformation"
lpkeyname = "LastName"
lpfilename = "d:\temp\userinf.ini"
if myobj.CheckKey(lpappname, lpkeyname, lpfilename) then
     response.write "Key exists."
else
    response.write(MyObj.GetLastErrorDscr)
end if
%>
GetLastErrorNbr Method
Syntax: object.GetLastErrorNbr
Returns number of the last error.
GetLastErrorDscr Method
Syntax: object.GetLastErrorDscr
Returns description of the last error.
top


Home | FAQ | News | How to buy | Contacts | ASP MagicPerf Component | ASP MagicShell Component | Website Monitoring Blog
Our friends: FatCow Web Hosting