Results 1 to 5 of 5

Thread: INI Files.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2003
    Posts
    137

    INI Files.

    Ok i want to make ini files not XML not anything else. Just INI files. I am using VB.Net of course so can someone help me out. I tried searching google and msdn but il i see is vb6 answers nothing for .NET and i really need this. I cant use XML because this program is for my mp3 player im making and its all setup using ini files. now i want to make this like a playlist maker. and i need it in ini files. i already finished my MP3 player all i need is to know how to save and read a ini file
    Live to love, Not to hate

  2. #2
    Addicted Member
    Join Date
    Apr 2002
    Location
    California
    Posts
    160
    There is no true support for INI in VB.NET. However you could use File IO operations to read and right data to INI Files. I am not going to explain everything you need to do (vast amounts of information) but I will point you in the right direction. INI files are just text files, so just use simple IO. Youll need to import system.io

    VB Code:
    1. Private Function WriteINI() As Boolean
    2.         Dim objFile As TextWriter
    3.         Dim objRFile As TextReader
    4.         Dim i As Integer
    5.         Dim strAppName As String
    6.         Dim strFile As String = "c:\MyFile.ini"
    7.         Dim lneInput As String
    8.         Dim arrTemp As String()
    9.  
    10.         objFile = File.AppendText(strFile)
    11.  
    12.         objFile.WriteLine("[KEY1]" & vbCrLf & "AppName=MyApp")
    13.  
    14.         objFile.Close()
    15.  
    16.         objRFile = File.OpenText(strFile)
    17.  
    18.         lneInput = objRFile.ReadLine
    19.  
    20.         Do While Not IsNothing(lneInput)
    21.             If InStr(lneInput, "[KEY1]") Then
    22.                 arrTemp = objRFile.ReadLine().Split("=")
    23.                 strAppName = arrTemp(1)
    24.                 MsgBox(strAppName)
    25.             End If
    26.             lneInput = objRFile.ReadLine
    27.         Loop
    28.         objRFile.Close()
    29.         Return True
    30.  
    31.     End Function
    Jason Moore

    Software Engineer, Database Architect, Web Designer

    (C#,VB/NET,ASP/NET,COLDFUSION,JAVASCRIPT,SQL)

    http://www.gatorstudios.com
    [email protected]

  3. #3
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi AtomSoft.

    You might wanna check out the WriteProfile and GetProfile API's.
    They will work just as well in VB .NET.

    VB Code:
    1. Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Object, ByVal lpString As Object, ByVal lpFileName As String) As Integer
    2.  
    3. Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Object, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer

    I'm not sure the above declarations are 100% accurate, but it's definitly close

    Hope it helps.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  4. #4
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    it's very easy in .net use the 2 mentioned api's ( modified slightly ) along with System.Text.StringBuilder ...
    VB Code:
    1. Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As System.Text.StringBuilder, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
    2.     Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer
    3.  
    4.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    5.         '/// retrieve a value from an ini file , in this case one i have stored under C:\
    6.         Dim strItem As New System.Text.StringBuilder(256)
    7.         GetPrivateProfileString("drivers", "wave", "Default", strItem, strItem.Capacity, "C:\dynamic.ini")
    8.         MessageBox.Show(strItem.ToString)
    9.     End Sub
    10.  
    11.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    12.         '/// add a new item to the ini file ( you can also update the values here )
    13.         Dim strNewItem As String = "another item under the drivers section"
    14.         WritePrivateProfileString("drivers", "newitem", strNewItem, "C:\dynamic.ini")
    15.     End Sub
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  5. #5
    Member
    Join Date
    Nov 2003
    Location
    Amsterdam, The Netherlands
    Posts
    53

    INI class for VB.net

    get it here

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