Results 1 to 7 of 7

Thread: INI Write Error

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2005
    Location
    Toronto, Canada
    Posts
    357

    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:
    1. WriteToINI "CLICKWHEEL", "Sensitivity", intSensitivity, strINILoc

    VB Code:
    1. 'In a module
    2. Public Sub WriteToINI(strSectionName As String, strKeyName As String, strValue As String, strFileName As String)
    3.  
    4. Dim WriteToIniResult As Long
    5.  
    6. On Error GoTo ErrHandler
    7.  
    8.     WriteToIniResult = WritePrivateProfileString(strSectionName, strKeyName, strValue, strFileName)
    9.     Exit Sub
    10.    
    11. ErrHandler:
    12.     Debug.Print Err.Description
    13.     Err.Clear
    14.     Resume Next
    15.  
    16. 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.

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: INI Write Error

    Post this module also
    VB Code:
    1. WritePrivateProfileString
    Please mark you thread resolved using the Thread Tools as shown

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2005
    Location
    Toronto, Canada
    Posts
    357

    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.

  4. #4
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: INI Write Error

    Try this example
    VB Code:
    1. 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
    2. 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
    3. Private Sub Form_Load()
    4.     Dim Ret As String, NC As Long
    5.     'Write the setting to the file (c:\test.ini) under
    6.     '   Project1 -> Keyname
    7.     WritePrivateProfileString App.Title, "KeyName", "This is the value", "c:\test.ini"
    8.     'Create a buffer
    9.     Ret = String(255, 0)
    10.     'Retrieve the string
    11.     NC = GetPrivateProfileString(App.Title, "KeyName", "Default", Ret, 255, "C:\test.ini")
    12.     'NC is the number of characters copied to the buffer
    13.     If NC <> 0 Then Ret = Left$(Ret, NC)
    14.     'Show our string
    15.     MsgBox Ret
    16.     'Delete the file
    17.    ' Kill "c:\test.ini"
    18. End Sub
    Please mark you thread resolved using the Thread Tools as shown

  5. #5
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: INI Write Error

    put this in your module...

    VB Code:
    1. 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
    2.  
    3. 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
    4.  
    5. Function ReadInI(strSectionHeader As String, strVariableName As String, strFileName As String) As String
    6.     Dim strReturn As String
    7.     '// reads INI file
    8.     strReturn = String(255, Chr(0))
    9.     ReadInI = Left$(strReturn, _
    10.     GetPrivateProfileString(strSectionHeader, ByVal strVariableName, "=", strReturn, Len(strReturn), strFileName))
    11. End Function
    12.  
    13. Function WriteINI(strSectionHeader As String, strVariableName As String, strValue As String, strFileName As String) As String
    14.     '// writes to the INI file
    15.     WriteINI = WritePrivateProfileString(strSectionHeader, strVariableName, strValue, strFileName)
    16. End Function

    To use...

    VB Code:
    1. Private Sub Command1_Click()
    2.     ReadInI "AnyKey", "AnyString", App.Path & "\settings.ini"
    3. End Sub
    4.  
    5. Private Sub Command2_Click()
    6.     WriteINI App.EXEName, "AnyKey", "AnyString", App.Path & "\settings.ini"
    7. End Sub

  6. #6
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: INI Write Error

    Is intSensitivity a number ? If so you'll need to convert it to a string:
    VB Code:
    1. 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.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2005
    Location
    Toronto, Canada
    Posts
    357

    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
  •  



Click Here to Expand Forum to Full Width