|
-
Jan 24th, 2004, 01:45 PM
#1
Thread Starter
Addicted Member
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
-
Jan 24th, 2004, 05:28 PM
#2
Addicted Member
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:
Private Function WriteINI() As Boolean
Dim objFile As TextWriter
Dim objRFile As TextReader
Dim i As Integer
Dim strAppName As String
Dim strFile As String = "c:\MyFile.ini"
Dim lneInput As String
Dim arrTemp As String()
objFile = File.AppendText(strFile)
objFile.WriteLine("[KEY1]" & vbCrLf & "AppName=MyApp")
objFile.Close()
objRFile = File.OpenText(strFile)
lneInput = objRFile.ReadLine
Do While Not IsNothing(lneInput)
If InStr(lneInput, "[KEY1]") Then
arrTemp = objRFile.ReadLine().Split("=")
strAppName = arrTemp(1)
MsgBox(strAppName)
End If
lneInput = objRFile.ReadLine
Loop
objRFile.Close()
Return True
End Function
-
Jan 24th, 2004, 05:44 PM
#3
Hi AtomSoft.
You might wanna check out the WriteProfile and GetProfile API's.
They will work just as well in VB .NET.
VB Code:
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
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...
-
Jan 24th, 2004, 05:54 PM
#4
it's very easy in .net use the 2 mentioned api's ( modified slightly ) along with System.Text.StringBuilder ...
VB Code:
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
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
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'/// retrieve a value from an ini file , in this case one i have stored under C:\
Dim strItem As New System.Text.StringBuilder(256)
GetPrivateProfileString("drivers", "wave", "Default", strItem, strItem.Capacity, "C:\dynamic.ini")
MessageBox.Show(strItem.ToString)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'/// add a new item to the ini file ( you can also update the values here )
Dim strNewItem As String = "another item under the drivers section"
WritePrivateProfileString("drivers", "newitem", strNewItem, "C:\dynamic.ini")
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]
-
Jan 24th, 2004, 09:46 PM
#5
Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|