Not a Member Yet,
Click here to Register

ID: 340
Viewed: 3500
Added: Aug 19, 2002
Version:
Snippet uploaded by: snippet
Written By: Unknown
Demo: Sorry, no demo



User Rated at: 0 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

here is how you can store and retrieve info (in this case scores) from an ini file. Just create a new standard code module and put this code into it:

Now in your sub main or form load call ReadScores and in your form unload call SaveScores. The resulting ini file will look like:

[HighScore]
Score.0=150
Score.1=149
Score.2=148
Score.3=147
Score.4=146
Score.5=145
Score.6=144
Score.7=143
Score.8=142
Score.9=141


Have fun

Highlight all by clicking in box
<!---Declaration--->
Option Explicit 
'
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As Any, ByVal lpFileName As String) As Long
'
' <<< Public Declarations >>>
'
Public g_tbl_Scores() As String
'table to hold scores
'
' <<< Local Constants >>>
'
Const m_int_SCORES As Integer = 9
'number of scores to track
'
'
' <<< Public Functions >>>
'
Public Function ReadINI(Section, KeyName, FileName As String) As String
Dim sRet As String
sRet = String(255, Chr(0))
ReadINI = Left(sRet, GetPrivateProfileString(Section, ByVal KeyName, "", sRet, Len(sRet), FileName))
End Function
'
Public Function writeini(sSection As String, sKeyName As String, sNewString As String, sFileName) As Integer
Dim variable 'doesn't seem to matter
variable = WritePrivateProfileString(sSection, sKeyName, sNewString, sFileName)
End Function
'
Public Function NormPath(sPath As String, Optional sSeperator As String = "") As String
If Right(sPath, Len(sSeperator)) = sSeperator Then
NormPath = sPath
Else
NormPath = sPath & sSeperator
End If
End Function

Highlight All
<!---Code--->
Public Sub ReadScores() 
'this sub will load the scores from an ini file into 'an array
Dim sFile As String
Dim iControl As Integer
sFile = NormPath(App.Path) & "HighScores.ini"
'
ReDim g_tbl_Scores(m_int_SCORES) 'resize array
'
For iControl = 0 To m_int_SCORES g_tbl_Scores(iControl) = ReadINI("HighScore", _ "Score." & iControl, sFile)
Next iControl
End Sub
'
Public Sub SaveScores()
'this sub will save scores from an array
Dim sFile As String
Dim iControl As Integer
sFile = NormPath(App.Path) & "HighScores.ini"
'
For iControl = 0 To m_int_SCORES
writeini "HighScore", "Score." & iControl, _ g_tbl_Scores(iControl), sFile
Next iControl
End Sub
;


No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Replying to a Comment...


Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2024 snippetlibrary.com All Rights Reserved. Conditions
Do NOT follow this link or you will be banned from the site!