Results 1 to 7 of 7
  1. #1
    That0n3Guy's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Posts
    1,137
    Reputation
    13
    Thanks
    271
    My Mood
    Sleepy

    [Tutorial/Snippet][VB6] Reading and writing INI Files

    Purpose: Saving settings, etc.

    Setting it up

    • Create a new module
    • Name it something along the lines of "SaveSets"
    • Add the following code to your module:


    Code:
    Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName As Any, ByVal lsString As Any, ByVal lplFilename As String) As Long
    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 Check As String
    
    Public Function Load(Section As String, Key As String) As String 
    Dim lngResult As Long 
    Dim strFileName 
    Dim strResult As String * 300
    strFileName = App.Path & "\settings.ini" 
    lngResult = GetPrivateProfileString(Section, Key, strFileName, strResult, Len(strResult), strFileName) 
    Check = App.Path & "\sets.ini" 
    Load = Trim(strResult) 
    End Function
    
    Public Function Save(Section As String, Key As String, Content As String)
    Dim lngResult As Long
    Dim strFileName
    strFileName = App.Path & "\settings.ini"
    lngResult = WritePrivateProfileString(Section, Key, Content, strFileName)
    End Function
    • Now, change where it says "settings.ini" to file name of which you want to read and write.
    • All of the rest of the code will stay the same, you shouldn't have much of a reason to chance it.


    Using it

    Saving

    To save something, write the following under the code for your button or whatever it is your saving from.

    Code:
    Call Save("Section", "Label", "Value")
    Now start to fill this out. Right now that would output the following:

    Code:
    [Section]
    Label = Value
    Knowing that, replace section, label, and value with whatever you want to save.

    Loading

    To load something, put the following code for when you want to load:

    Code:
    Call Load("Section", "Label")
    or, to assign the value it loaded to a variable,

    Code:
    MyVariable = Load("Section", "Label")
    This works the same way as above and needs to have the same values for section and label or else it will NOT work.

    If you need anymore help, just post saying so and I'll do my best to help.
    Quotes Hall of Fame

    Quote Originally Posted by martijno0o0 View Post
    ok, i got visual basic 2008 and i got some expirients but i need c++ to make hacks rigth?
    so i need c++ and my question is!?¿? where i dontload it? and is c++ a own program or a update for vb08?
    [IMG]https://i660.photobucke*****m/albums/uu327/EddieTheWin/duff.png[/IMG]

  2. The Following User Says Thank You to That0n3Guy For This Useful Post:

    FatCat00 (10-23-2009)

  3. #2
    FatCat00's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Posts
    78
    Reputation
    10
    Thanks
    10
    My Mood
    Bitchy
    just what i need for my app. thanx a bunch
    Edit: Some Problems in the code? @_@'
    Last edited by FatCat00; 10-23-2009 at 10:34 PM.
    Quote Originally Posted by Benzoboy View Post
    can anyone help me find a download for perX? What is PerX.

    Help Quick.

    Thanks very much!! :]
    Quote Originally Posted by Casavir View Post
    I keep answering the same shit every day
    don't u choobs know the usage of the button called 'Search' ?I suppose not
    when something is approved,it's not a virus
    Got it retard?
    Quote Originally Posted by juan1212 View Post
    where is the search button?

    OWNED

  4. #3
    Zoom's Avatar
    Join Date
    May 2009
    Gender
    male
    Location
    Your going on my 24/7 DDoS hit list.
    Posts
    8,552
    Reputation
    127
    Thanks
    5,970
    My Mood
    Happy
    Thanks for this usefull tut..
    -Rest in peace leechers-

    Your PM box is 100% full.

  5. #4
    That0n3Guy's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Posts
    1,137
    Reputation
    13
    Thanks
    271
    My Mood
    Sleepy
    Quote Originally Posted by FatCat00 View Post
    just what i need for my app. thanx a bunch
    Edit: Some Problems in the code? @_@'
    Where do you see any problems in the code?
    Quotes Hall of Fame

    Quote Originally Posted by martijno0o0 View Post
    ok, i got visual basic 2008 and i got some expirients but i need c++ to make hacks rigth?
    so i need c++ and my question is!?¿? where i dontload it? and is c++ a own program or a update for vb08?
    [IMG]https://i660.photobucke*****m/albums/uu327/EddieTheWin/duff.png[/IMG]

  6. #5
    FatCat00's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Posts
    78
    Reputation
    10
    Thanks
    10
    My Mood
    Bitchy
    The words in red are the error i get i try to fix them but i think i made it worse?
    Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName As Any, ByVal lsString As Any, ByVal lplFilename As String) As Long
    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 Check As String

    Public Function Load(Section As String, Key As String) As String
    Dim lngResult As Long
    Dim strFileName
    Dim strResult As String * 300
    strFileName = App.Path & "\settings.ini"
    lngResult = GetPrivateProfileString(Section, Key, strFileName, strResult, Len(strResult), strFileName)
    Check = App.Path & "\sets.ini"
    Load = Trim(strResult)
    End Function

    Public Function Save(Section As String, Key As String, Content As String)
    Dim lngResult As Long
    Dim strFileName
    strFileName = App.Path & "\settings.ini"
    lngResult = WritePrivateProfileString(Section, Key, Content, strFileName)
    End Function
    Quote Originally Posted by Benzoboy View Post
    can anyone help me find a download for perX? What is PerX.

    Help Quick.

    Thanks very much!! :]
    Quote Originally Posted by Casavir View Post
    I keep answering the same shit every day
    don't u choobs know the usage of the button called 'Search' ?I suppose not
    when something is approved,it's not a virus
    Got it retard?
    Quote Originally Posted by juan1212 View Post
    where is the search button?

    OWNED

  7. #6
    That0n3Guy's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Posts
    1,137
    Reputation
    13
    Thanks
    271
    My Mood
    Sleepy
    Quote Originally Posted by FatCat00 View Post
    The words in red are the error i get i try to fix them but i think i made it worse?
    What are you coding in? This was made strictly for VB6, I don't do any of the other VBs.
    Quotes Hall of Fame

    Quote Originally Posted by martijno0o0 View Post
    ok, i got visual basic 2008 and i got some expirients but i need c++ to make hacks rigth?
    so i need c++ and my question is!?¿? where i dontload it? and is c++ a own program or a update for vb08?
    [IMG]https://i660.photobucke*****m/albums/uu327/EddieTheWin/duff.png[/IMG]

  8. #7
    wtfiwantthatname's Avatar
    Join Date
    Oct 2008
    Gender
    male
    Posts
    260
    Reputation
    10
    Thanks
    39
    My Mood
    Bored
    Quote Originally Posted by FatCat00 View Post
    The words in red are the error i get i try to fix them but i think i made it worse?

    Those errors are from vb.net in .net you cant do string * 300 to create a strign with 300 characters. try using strResult = space(300)


    For app.path use Application.ExecutablePath.

    For the length of strResult you can use len() or strResult.length.


    P.S ; I Forgot to mention that long in VB is equal to an integer in vb.net. Also for you API declarations you need to marshal the variables that are declared as any.

Similar Threads

  1. [Help] Reading and Writing Float
    By hack_tr in forum Visual Basic Programming
    Replies: 2
    Last Post: 08-11-2011, 04:01 AM
  2. need help!? read and write (txt)
    By GER-Domi. in forum Visual Basic Programming
    Replies: 5
    Last Post: 09-10-2010, 08:11 PM
  3. [TUT]How to read and write to a text file
    By XORxHACK in forum Java
    Replies: 18
    Last Post: 02-26-2010, 04:41 PM
  4. [Help]Reading and Writing to .txt files on the internet
    By treeham in forum Visual Basic Programming
    Replies: 6
    Last Post: 01-30-2010, 01:07 AM
  5. Reading from an INI file
    By Credzis in forum C++/C Programming
    Replies: 0
    Last Post: 11-28-2007, 02:18 PM

Tags for this Thread