Results 1 to 5 of 5

Thread: INI Manipulation - Problems

  1. #1

    Thread Starter
    Addicted Member Max_aka_NOBODY's Avatar
    Join Date
    Jul 2004
    Location
    Amman, Jordan
    Posts
    179

    INI Manipulation - Problems

    I've been having problem produces a "memory xxxxxxx cannot be read" error. All the functions and variables are declared, the file and the controls exist... If it might be of any significance, this is followed by an "End" command, but it doesn't have any problems on its own. Anyway, here's the code:

    VB Code:
    1. If optAlbum1.Value = True Then
    2.         Call WritePrivateProfileString("MW Photographer", "Album1Index", GetPrivateProfileInt("General", "Screen Shot Index", "0", CurDir() & "\Morrowind.ini"), CurDir() & "\Morrowind.ini")
    3.     ElseIf optAlbum2.Value = True Then
    4.         Call WritePrivateProfileString("MW Photographer", "Album2Index", (GetPrivateProfileInt("General", "Screen Shot Index", "0", CurDir() & "\Morrowind.ini") - 25), CurDir() & "\Morrowind.ini")
    5.     ElseIf optAlbum3.Value = True Then
    6.         Call WritePrivateProfileString("MW Photographer", "Album3Index", (GetPrivateProfileInt("General", "Screen Shot Index", "0", CurDir() & "\Morrowind.ini") - 50), CurDir() & "\Morrowind.ini")
    7.     ElseIf optAlbum4.Value = True Then
    8.         Call WritePrivateProfileString("MW Photographer", "Album4Index", (GetPrivateProfileInt("General", "Screen Shot Index", "0", CurDir() & "\Morrowind.ini") - 75), CurDir() & "\Morrowind.ini")
    9.     End If

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: INI Manipulation - Problems

    Here is your problem:
    The GetPrivateProfileInt function retrieves an integer associated with a key in the specified section of an initialization file. Note This function is provided only for compatibility with 16-bit Windows-based applications. Win32-based applications should store initialization information in the registry.

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: INI Manipulation - Problems

    Two options

    Convert the GetPrivateProfileInt return value with CStr.

    Code:
    Call WritePrivateProfileString("MW Photographer", "Album1Index",  
          CStr(GetPrivateProfileInt("General", "Screen Shot Index", "0", CurDir() & "\Morrowind.ini")) , 
          CurDir() & "\Morrowind.ini")
    Or change the declaration of the WritePrivateProfileString, specifically

    Byval lpString As Any to
    Byval lpString as String

  4. #4

    Thread Starter
    Addicted Member Max_aka_NOBODY's Avatar
    Join Date
    Jul 2004
    Location
    Amman, Jordan
    Posts
    179

    Re: INI Manipulation - Problems

    Thanx a lot! Just what I was looking for!

  5. #5

    Thread Starter
    Addicted Member Max_aka_NOBODY's Avatar
    Join Date
    Jul 2004
    Location
    Amman, Jordan
    Posts
    179

    Re: INI Manipulation - Problems

    Still on topic, I have another question. This is another section of the INI file that I'm trying to manipulate(note that the values and the number of entries will be different for every user):

    Code:
    [Game Files]
    GameFile0=Morrowind.esm
    GameFile1=Tribunal.esm
    GameFile2=Death 2.2.esp
    GameFile3=Land GFX.esp
    GameFile4=lgnpc_Ald'ruhn.esp
    GameFile5=MW Photographer_Album4.esp
    GameFile6=palace test.esp
    GameFile7=Real Misc Items GFX.esp
    GameFile8=Roads to Heaven.esp
    GameFile9=Scum.esp
    GameFile10=Seamless_BB_Asian_Race.esp
    GameFile11=Snow Cottage.esp
    GameFile12=Windows Glow.esp
    And this is the function I wrote for this:

    VB Code:
    1. Private Sub CheckIt()
    2.  
    3. Dim X As Long, i As Long, iLenBuf As Integer, sRetBuf As String, sValue As String
    4.  
    5. sRetBuf$ = String$(256, 0)
    6. iLenBuf% = Len(sRetBuf$)
    7.  
    8. For i = 0 To 256 ' The number of entries is actually a byte value, but it won't hurt.
    9.     X = GetPrivateProfileString("Game Files", "GameFile" & i, "", sRetBuf$, iLenBuf%, CurDir() & "\Morrowind.ini")
    10.     If Left$(sRetBuf$, X) = "MW Photographer_Album1.esp" And optAlbum1.Value = True Then
    11.         Exit For
    12.     ElseIf Left$(sRetBuf$, X) = "MW Photographer_Album2.esp" And optAlbum2.Value = True Then
    13.         Exit For
    14.     ElseIf Left$(sRetBuf$, X) = "MW Photographer_Album3.esp" And optAlbum3.Value = True Then
    15.         Exit For
    16.     ElseIf Left$(sRetBuf$, X) = "MW Photographer_Album4.esp" And optAlbum4.Value = True Then
    17.         Exit For
    18.     ElseIf optAlbum1.Value = True And (Left$(sRetBuf$, X) = "MW Photographer_Album2.esp" Or Left$(sRetBuf$, X) = "MW Photographer_Album3.esp" Or Left$(sRetBuf$, X) = "MW Photographer_Album4.esp") Then
    19.         Call WritePrivateProfileString("Game Files", "GameFile" & CStr(i), "MW Photographer_Album1.esp", CurDir() & "\Morrowind.ini")
    20.     ElseIf optAlbum2.Value = True And (Left$(sRetBuf$, X) = "MW Photographer_Album1.esp" Or Left$(sRetBuf$, X) = "MW Photographer_Album3.esp" Or Left$(sRetBuf$, X) = "MW Photographer_Album4.esp") Then
    21.         Call WritePrivateProfileString("Game Files", "GameFile" & CStr(i), "MW Photographer_Album2.esp", CurDir() & "\Morrowind.ini")
    22.     ElseIf optAlbum3.Value = True And (Left$(sRetBuf$, X) = "MW Photographer_Album2.esp" Or Left$(sRetBuf$, X) = "MW Photographer_Album1.esp" Or Left$(sRetBuf$, X) = "MW Photographer_Album4.esp") Then
    23.         Call WritePrivateProfileString("Game Files", "GameFile" & CStr(i), "MW Photographer_Album3.esp", CurDir() & "\Morrowind.ini")
    24.     ElseIf optAlbum4.Value = True And (Left$(sRetBuf$, X) = "MW Photographer_Album2.esp" Or Left$(sRetBuf$, X) = "MW Photographer_Album3.esp" Or Left$(sRetBuf$, X) = "MW Photographer_Album1.esp") Then
    25.         Call WritePrivateProfileString("Game Files", "GameFile" & CStr(i), "MW Photographer_Album4.esp", CurDir() & "\Morrowind.ini")
    26.     ElseIf Left$(sRetBuf$, X) = "" Then
    27.         If optAlbum1.Value = True Then
    28.             Call WritePrivateProfileString("Game Files", "GameFile" & CStr(i), "MW Photographer_Album1.esp", CurDir() & "\Morrowind.ini")
    29.         ElseIf optAlbum1.Value = True Then
    30.             Call WritePrivateProfileString("Game Files", "GameFile" & CStr(i), "MW Photographer_Album2.esp", CurDir() & "\Morrowind.ini")
    31.         ElseIf optAlbum2.Value = True Then
    32.             Call WritePrivateProfileString("Game Files", "GameFile" & CStr(i), "MW Photographer_Album3.esp", CurDir() & "\Morrowind.ini")
    33.         ElseIf optAlbum3.Value = True Then
    34.             Call WritePrivateProfileString("Game Files", "GameFile" & CStr(i), "MW Photographer_Album4.esp", CurDir() & "\Morrowind.ini")
    35.         End If
    36.         Exit For
    37.     Else
    38.         Call MsgBox("There was a problem detecting your Morrowind installation. Please Reinstall.", vbOKOnly, "Error")
    39.         Unload frmMain
    40.         End
    41.     End If
    42. Next
    43.  
    44. End Sub

    I want it to replace the Album file entry("MW Photographer_Album4.esp" in the above INI snippet) with the one selected by the optAlbum#, and if no album is selected, make a new entry. The problem is that it always writes it in GameFile0 entry with no regards to its contents.

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