Results 1 to 11 of 11

Thread: problems with ini files that never existed before?!

  1. #1
    Guest
    I always used the Get & WritePrivateProfileString to write and read ini files, but today when i wrote a new line of code using the same old line i always used i got a weird error massage:
    compile error: type-decleration character does not match declared data type.
    what is the problem?

    this is the line its the same as i always used:

    inipath$ = App.Path & "\file.ini"
    If Dir(inipath$, vbNormal) = "" Then
    rc% = WritePrivateProfileString("Database", "Path", "", inipath$)
    'read
    lngResult = GetPrivateProfileString("Database", "Path", inipath$, strResult, Len(strResult), inipath$)
    DBPath = Trim(strResult)

    this got something to do with the $ sign but now it seems that the entire program cant deal with this sign, and it worked before, and its working in another program i wrote...
    when taking off the $ the program works but you cant read the ini file just writing it..

    ..thanks..

  2. #2
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    This error means that you declared a variable as one dattype, and used a type declaration character of another datatype.
    So check the declaration of the variable. It will be easier if you use Option Explicit; that way you are forced to declare the variables, so you are forced to think about the datatypes.
    The following examples will go wrong:

    Dim x
    x$ = "Hello World"

    x is declared as variant (because the default is used), but the $ sign is used for string variables.

    Dim y As Integer
    y& = 120

    y is declared as integer, but the ampersand is used for longs.

  3. #3
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    I just noticed that you use an integer (rc%, % is the sign for integer) to store the returnvalue of WritePrivateProfileString. This should be a long(&) in 32 bits api calls.

  4. #4
    Guest

    still not helping..

    I still don't know how to solve this.. the weird part is that this code used to work, it works in another program i made, and it worked in the current program im writing. what i cant figure out is why now i cant use this code and the old parts of the program that used to work arent working too. i tried removing the $ sign but then the program just wrote ini file but it didnt read them.
    any help will be good..

    thanks..

  5. #5
    Guest

    still need info

    i still need help please anyone that have an idea??

  6. #6
    Hyperactive Member JazzBass's Avatar
    Join Date
    Jun 1999
    Posts
    393

    I have a thought

    bzemer,
    You said that it wrote out the ini file, but could not read it. I noticed in your code to write out the file, you are sending an empty string to your 'Path' key.

    Here is your code:
    Code:
    inipath$ = App.Path & "\file.ini" 
    If Dir(inipath$, vbNormal) = "" Then 
    rc% = WritePrivateProfileString("Database", "Path", "", inipath$) 
    
    'read 
    lngResult = GetPrivateProfileString("Database", "Path", inipath$, strResult, Len(strResult), inipath$)DBPath = Trim(strResult)
    Try this:
    Code:
    inipath$ = App.Path & "\file.ini" 
    If Dir(inipath$, vbNormal) = "" Then 
    rc% = WritePrivateProfileString("Database", "Path", "C:\database", inipath$) 
    
    'read 
    lngResult = GetPrivateProfileString("Database", "Path", inipath$, strResult, Len(strResult), inipath$)DBPath = Trim(strResult)

    If you can't read the file, it may be because there is no value to read from.

    This is the routine I use to read and write ini files
    (Courtesy of Aaron Young)


    Code:
    'Read ini file
    Dim sBuff As String * 255  
    n% = GetPrivateProfileString("Settings", "ProgramPath", "DefaultPath", sBuff, Len(sBuff), sInifile)
    
    'Write ini file
    n% = WritePrivateProfileString("ProjectCodes", "Code", "Deleted", sIniFile)
    Try it out.
    Let us know if that helps
    JazzBass
    JazzBass
    In the .NET era
    Trying to remember VB6
    Progress:
    XP Professional @ Home
    and @ the Office

  7. #7
    Guest

    problem not solved but sure helped

    hey,
    my problem was that somehow the program wouldnt allow me to use the $ sign. still so.. but now that i have the new code you gave me, i dont have to deal with the problem any more. but i need to figure something.. what does the 'defaultpath' stand for..?

    anyway i know i left the path blank, it was supposesd to be so, but thanks for your help. everything works fine now..

  8. #8
    Hyperactive Member JazzBass's Avatar
    Join Date
    Jun 1999
    Posts
    393

    Cool

    bzemer,
    Glad to be of help. The 'Defaultpath' in the routine is the value that would be returned if the routine could not read from the ini file. You could make it anything you want, ie "C:\database", "C:\mydb\database".

    In your code, you had the ini file path returning as the default value. I don't know if that also contributed to your problem after you deleted the $. I setup the default value and I use for testing sometimes. If the value that returns is what I set up as default, then I know I have a problem somewhere in my code or my ini file.

    Hope that helps.

    JazzBass

  9. #9
    Guest

    another problem

    thanks..but now i have another problem..
    i tryed to make my program locate the database name for data1 from an ini file. i made the ini file tell where the data.mdb file is and yet i get an error massage. this is the massage: "object variable or with block variable not set". do you know why i get the error or what it means? .. thanks..

    someone told me i need to declare a variable im using.. but i didnt thats not enough information for me..

    thanks again..

  10. #10
    New Member
    Join Date
    Mar 2000
    Posts
    1
    We need more information rather the exact code segment you used to "make my program locate the database name for data1 from an ini file." to answer this question

  11. #11
    Guest

    more info

    this code reads databse faster

    SIniFile = App.Path & "\CharGen.ini"
    Dim sBuff As String * 255
    n% = GetPrivateProfileString("Database", "Path", "DefaultPath", sBuff, Len(sBuff), SIniFile)
    Data1.DatabaseName = sBuff
    Data1.Recordset.MoveLast
    intRecCount = Data1.Recordset.RecordCount
    Data1.Recordset.MoveFirst

    For intCounter = 1 To intRecCount
    List2.AddItem Data1.Recordset!Description
    Data1.Recordset.MoveNext
    Next intCounter

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