Results 1 to 6 of 6

Thread: INI PROBLEMS

  1. #1

    Thread Starter
    Hyperactive Member PITBULLCJR's Avatar
    Join Date
    Nov 1999
    Location
    New York
    Posts
    408

    Post

    I am sorry but I don't get that code at all. Could you try and explain it a little better for dumb people. Thanks you

  2. #2

    Thread Starter
    Hyperactive Member PITBULLCJR's Avatar
    Join Date
    Nov 1999
    Location
    New York
    Posts
    408

    Post

    Ok I made a program that has you log in using a username and password. THe username and password are set in stone in the code but what i want is to be able to change your username or password. so i figured I would have the password thing look for the username and password in an ini file and if they want to change it then it would just rewrite the ini information. well I put in the
    [username]
    username=chris
    [pass]
    pass=chris
    in the ini file. I did it by opening the file and just typing it in and it didn't work and then i deleted it and had my code write it in and it still didn't work. What keeps happening is that when it goes to read it it reads it like this chris| || || || || || || || || || || || | os something close to that the bars are very fat and close together. WHy does it put all those bars in? I figured this out by using the debug thing and when that is yellow it says username = chris| || || || || || || || well if you have any ideas please help thanks
    sincerely, CHris

  3. #3
    Lively Member
    Join Date
    Dec 1999
    Location
    Karlsruhe, Germany
    Posts
    122

    Post

    The bars depend on what you initialize your var with. I suppose you use writeprivateprofilestring and getprivateprofilestring. getprivateprofilestring needs a max number of characters to read and gives you the number of read characters as result. Init your var to read in with space(x) first!

    Use
    readvar = space(100)
    readlen = getprivateprofilestring(<section in ini-file in []>, <key, that is key=>, default, readvar, 100, file)
    readvar = left$(readvar, readlen)

    RogerH

  4. #4
    Lively Member
    Join Date
    Dec 1999
    Location
    Karlsruhe, Germany
    Posts
    122

    Post

    OK, I'll try to make it clear:

    Suppose you want to write/read this INI-file

    [username]
    usernamekey=chris
    [pass]
    passkey=chris

    named C:\temp\test.ini

    First you have to declare the API-functions (in a module):

    Code:
    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
    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
    Writing the file:

    Code:
    WritePrivateProfileString "username", "usernamekey", "chris", "c:\temp\test.ini"
    WritePrivateProfileString "pass", "passkey", "chris", "c:\temp\test.ini"
    Reading is not that simple. As you see in the declaration, the get-function want's the parameters
    lpDefault As String => Give this back, if the entry is not found in the INI-file
    lpReturnedString As String => This parameter gives back the result
    nSize => max. number of characters for the result

    GetPrivateProfileString needs reserved variable space to give something back. You create this by adding spaces to the string variable lpReturnedString before calling the function and you have to tell the function in nSize how many space in number of characters is reserved. The function gives you the number of characters used as result and puts the result in lpReturnedString.


    Code:
    DIM readvar as string 
    DIM readlen as string 
    readvar = space(100)  'reserve 100 char 
    readlen = getprivateprofilestring("username", "usernamekey", "defaultuser", readvar, 100, "c:\temp\test.ini")
    readvar = left$(readvar, readlen) 'cut off unused space
    msgbox "Username = " & readvar
    
    readvar = space(100)  'reserve 100 char 
    readlen = getprivateprofilestring("pass", "passkey", "defaultpassword", readvar, 100, "c:\temp\test.ini")
    readvar = left$(readvar, readlen) 'cut off unused space
    msgbox "Password = " & readvar
    Hope this makes it clear

    RogerH


  5. #5

    Thread Starter
    Hyperactive Member PITBULLCJR's Avatar
    Join Date
    Nov 1999
    Location
    New York
    Posts
    408

    Post

    Hey it gives me the correct password now but it says the username is false instead of chris. What went wrong?

    ------------------
    Sincerely,
    Chris
    :-) ;-)
    Email [email protected]

  6. #6

    Thread Starter
    Hyperactive Member PITBULLCJR's Avatar
    Join Date
    Nov 1999
    Location
    New York
    Posts
    408

    Post

    Wopps my mistake i missed a line. All fixed I get the correct username and password now lets see if i can get it to work in my program. Well thanks a ton!!!

    ------------------
    Sincerely,
    Chris
    :-) ;-)
    Email [email protected]

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