|
-
Dec 28th, 2006, 11:40 PM
#1
Thread Starter
Hyperactive Member
INI Write Error
I am using a INI file to save the configs of my software. I am getting this weird error when I am saving (writing) the configurations to the INI file.
I get the following error message:
Compile Error: ByRef argument type mismatch
Vb says that the error is with the following line:
VB Code:
WriteToINI "CLICKWHEEL", "Sensitivity", intSensitivity, strINILoc
VB Code:
'In a module
Public Sub WriteToINI(strSectionName As String, strKeyName As String, strValue As String, strFileName As String)
Dim WriteToIniResult As Long
On Error GoTo ErrHandler
WriteToIniResult = WritePrivateProfileString(strSectionName, strKeyName, strValue, strFileName)
Exit Sub
ErrHandler:
Debug.Print Err.Description
Err.Clear
Resume Next
End Sub
with the intSensitivity part.
The variable is declared as public and contains either a 1 or 0.
I have a line before this one that writes a string to the INI file and it works fine, but I get an error with this line.
I am new to INI files... so any clue??
I already made a thread of this... but I accidently marked it resolved so I had to make a new thread... I don't know how to remove the resolved...
I shall reply tomorrow morning because I have to go to sleep now...
Hey... If you found this post helpful please rate it.

-
Dec 28th, 2006, 11:41 PM
#2
Re: INI Write Error
Post this module also
VB Code:
WritePrivateProfileString
Please mark you thread resolved using the Thread Tools as shown
-
Dec 28th, 2006, 11:42 PM
#3
Thread Starter
Hyperactive Member
Re: INI Write Error
Umm... WritePrivateProfileString is an API
Yes... and I am unfortunately going to sleep (finally) so I will reply tomorrow...
Hey... If you found this post helpful please rate it.

-
Dec 28th, 2006, 11:44 PM
#4
Re: INI Write Error
Try this example
VB Code:
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private Sub Form_Load()
Dim Ret As String, NC As Long
'Write the setting to the file (c:\test.ini) under
' Project1 -> Keyname
WritePrivateProfileString App.Title, "KeyName", "This is the value", "c:\test.ini"
'Create a buffer
Ret = String(255, 0)
'Retrieve the string
NC = GetPrivateProfileString(App.Title, "KeyName", "Default", Ret, 255, "C:\test.ini")
'NC is the number of characters copied to the buffer
If NC <> 0 Then Ret = Left$(Ret, NC)
'Show our string
MsgBox Ret
'Delete the file
' Kill "c:\test.ini"
End Sub
Please mark you thread resolved using the Thread Tools as shown
-
Dec 29th, 2006, 12:08 AM
#5
Re: INI Write Error
put this in your module...
VB Code:
Public 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
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Function ReadInI(strSectionHeader As String, strVariableName As String, strFileName As String) As String
Dim strReturn As String
'// reads INI file
strReturn = String(255, Chr(0))
ReadInI = Left$(strReturn, _
GetPrivateProfileString(strSectionHeader, ByVal strVariableName, "=", strReturn, Len(strReturn), strFileName))
End Function
Function WriteINI(strSectionHeader As String, strVariableName As String, strValue As String, strFileName As String) As String
'// writes to the INI file
WriteINI = WritePrivateProfileString(strSectionHeader, strVariableName, strValue, strFileName)
End Function
To use...
VB Code:
Private Sub Command1_Click()
ReadInI "AnyKey", "AnyString", App.Path & "\settings.ini"
End Sub
Private Sub Command2_Click()
WriteINI App.EXEName, "AnyKey", "AnyString", App.Path & "\settings.ini"
End Sub
-
Dec 29th, 2006, 05:09 AM
#6
Re: INI Write Error
Is intSensitivity a number ? If so you'll need to convert it to a string:
VB Code:
Public Sub WriteToINI(strSectionName As String, strKeyName As String, [COLOR=Red]strValue As String[/COLOR], strFileName As String)
Alternatively, You could use the Write/GetPrivateProfileStruct APIs to store a mixture of data types. I've posted a couple of examples here and there if interested.
Last edited by schoolbusdriver; Dec 29th, 2006 at 05:29 AM.
-
Dec 29th, 2006, 12:04 PM
#7
Thread Starter
Hyperactive Member
Re: INI Write Error
Thanx a lot schoolbus... So silly of me...
Hey... If you found this post helpful please rate it.

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|