Mirage Engine
Read and Write InI's - Printable Version

+- Mirage Engine (https://mirage-engine.uk/forums)
+-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61)
+--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18)
+---- Forum: Resources (https://mirage-engine.uk/forums/forumdisplay.php?fid=49)
+---- Thread: Read and Write InI's (/showthread.php?tid=300)



Read and Write InI's - Reece - 11-09-2006

Hey, i have to make a database at school and ini's seemed simple to make. i have 3 months untill i have to start, so could somone post with a detailed expantation of how they work please?




- pingu - 12-09-2006

Eh...

Quote:[HEADER1]
Value1=3
Value2=6
Value3=Pie
[HEADER2]
Value1=9
Value2=Huge
Value3=1

That's the format...


- halla - 12-09-2006

Do you want the code? the API call and how to use them?

Other than that its pretty easy


- Matt - 12-09-2006

Actually, putvar and getvar are alot nicer. You can rip those from MS too, they read/write ini files.


- Reece - 12-09-2006

halla that would be awsome

I mean can you like post an exaplme of how they read from the ini?


- halla - 12-09-2006

Sure. This is taken from my Snake game.

I made a mod and named it modINI. This just sets read and write ini.

Code:
Option Explicit
Public Declare Function WritePrivateProfileString& Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal AppName$, ByVal KeyName$, ByVal keydefault$, ByVal FileName$)
Public Declare Function GetPrivateProfileString& Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal AppName$, ByVal KeyName$, ByVal keydefault$, ByVal ReturnedString$, ByVal RSSize&, ByVal FileName$)

Public Sub WriteINI(INISection As String, INIKey As String, INIValue As String, INIFile As String)
    Call WritePrivateProfileString(INISection, INIKey, INIValue, INIFile)
End Sub

Public Function ReadINI(INISection As String, INIKey As String, INIFile As String) As String
    Dim StringBuffer As String
    Dim StringBufferSize As Long
    
    StringBuffer = Space$(255)
    StringBufferSize = Len(StringBuffer)
    
    StringBufferSize = GetPrivateProfileString(INISection, INIKey, "", StringBuffer, StringBufferSize, INIFile)
    
    If StringBufferSize > 0 Then
        ReadINI = Left$(StringBuffer, StringBufferSize)
    Else
        ReadINI = ""
    End If
End Function

Writing to the INI file.
Code:
Call WriteINI("HIGH SCORES", "1.", lblFinalScore.Caption, (App.Path & "\highscores.ini"))

First part calls it. HIGH SCORES is like the category its labeled under. Then 1. is a sub category... it then writesFinalScore's Caption to that category. Then the last part places it in highscores.ini .

Read INI


Code:
HighScore = Trim(ReadINI("HIGH SCORES", "1.", App.Path & "\highscores.ini"))

HighScore = just sets that value to the following. Then it searches under the Category HIGH SCORES. Then it finds the sub category 1. It takes the value from there and thats the value of HighScore. Then of course the last part is the file it takes the info from.

Anyways pretty simple. You should be able to do whatever you need with this. If you need any more help let me know.


- Reece - 12-09-2006

Thanks man realy helped me loads.

If you ever need anything webhosting or PHP wise, ask Big Grin


- halla - 12-09-2006

Not a problem. And thanks... I know basic PHP but im not expert.