Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read and Write InI's
#1
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?

Reply
#2
Eh...

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

That's the format...
Reply
#3
Do you want the code? the API call and how to use them?

Other than that its pretty easy
Reply
#4
Actually, putvar and getvar are alot nicer. You can rip those from MS too, they read/write ini files.
Reply
#5
halla that would be awsome

I mean can you like post an exaplme of how they read from the ini?
Reply
#6
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.
Reply
#7
Thanks man realy helped me loads.

If you ever need anything webhosting or PHP wise, ask Big Grin
Reply
#8
Not a problem. And thanks... I know basic PHP but im not expert.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)