help Make settings.in ...

Posts 1–15 of 16 · Page 1 of 2
help Make settings.in ...
Hello MPGH Coder VB 2008 or 2010 or 6.0
lol
okay i want your help To show me how to do settings.ini
for my Program how to add settings and how to write settings
and how to Read settings ...
thank you
settings.ini
*if you don't Understand don't spam ...just see i don't understand /yea
thank you
Make a new module..

Code:
Option Strict On
Module INIAccess

#Region "API Calls"
' standard API declarations for INI access
' changing only "As Long" to "As Int32" (As Integer would work also)
Private Declare Unicode Function WritePrivateProfileString Lib "kernel32" _
Alias "WritePrivateProfileStringW" (ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal lpString As String, _
ByVal lpFileName As String) As Int32

Private Declare Unicode Function GetPrivateProfileString Lib "kernel32" _
Alias "GetPrivateProfileStringW" (ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal lpDefault As String, _
ByVal lpReturnedString As String, ByVal nSize As Int32, _
ByVal lpFileName As String) As Int32
#End Region

Public Overloads Function INIRead(ByVal INIPath As String, _
ByVal SectionName As String, ByVal KeyName As String, _
ByVal DefaultValue As String) As String
' primary version of call gets single value given all parameters
Dim n As Int32
Dim sData As String
sData = space$(1024) ' allocate some room 
n = GetPrivateProfileString(SectionName, KeyName, DefaultValue, _
sData, sData.Length, INIPath)
If n > 0 Then ' return whatever it gave us
INIRead = sdata.Substring(0, n)
Else
iniread = ""
End If
End Function

#Region "INIRead Overloads"
Public Overloads Function INIRead(ByVal INIPath As String, _
ByVal SectionName As String, ByVal KeyName As String) As String
' overload 1 assumes zero-length default
Return INIRead(inipath, sectionname, KeyName, "")
End Function

Public Overloads Function INIRead(ByVal INIPath As String, _
ByVal SectionName As String) As String
' overload 2 returns all keys in a given section of the given file
Return INIRead(inipath, sectionname, Nothing, "")
End Function

Public Overloads Function INIRead(ByVal INIPath As String) As String
' overload 3 returns all section names given just path
Return INIRead(inipath, Nothing, Nothing, "")
End Function
#End Region

Public Sub INIWrite(ByVal INIPath As String, ByVal SectionName As String, _
ByVal KeyName As String, ByVal TheValue As String)
Call WritePrivateProfileString(SectionName, KeyName, TheValue, INIPath)
End Sub

Public Overloads Sub INIDelete(ByVal INIPath As String, ByVal SectionName As String, _
ByVal KeyName As String) ' delete single line from section
Call WritePrivateProfileString(SectionName, KeyName, Nothing, INIPath)
End Sub

Public Overloads Sub INIDelete(ByVal INIPath As String, ByVal SectionName As String)
' delete section from INI file
Call WritePrivateProfileString(SectionName, Nothing, Nothing, INIPath)
End Sub

End Module
Usage:

Code:
Dim sValue As String
Dim sPath As String
sPath = "testing.ini"

INIWrite(sPath, "Section1", "Key1-1", "Value1-1") ' build INI file
INIWrite(sPath, "Section1", "Key1-2", "Value1-2")
INIWrite(sPath, "Section1", "Key1-3", "Value1-3")
INIWrite(sPath, "Section2", "Key2-1", "Value2-1")
INIWrite(sPath, "Section2", "Key2-2", "Value2-2")

sValue = INIRead(sPath, "section2", "key2-1", "Unknown") ' specify all
MessageBox.Show(sValue, "section2/key2-1/unknown", MessageBoxButtons.OK)

sValue = INIRead(sPath, "section2", "XYZ", "Unknown") ' specify all
MessageBox.Show(sValue, "section2/xyz/unknown", MessageBoxButtons.OK)

sValue = INIRead(sPath, "section2", "XYZ") ' use zero-length string as default
MessageBox.Show(sValue, "section2/XYZ", MessageBoxButtons.OK)

sValue = INIRead(sPath, "section1") ' get all keys in section
sValue = sValue.Replace(ControlChars.NullChar, "|"c) ' change embedded NULLs to pipe chars
MessageBox.Show(sValue, "section1 pre delete", MessageBoxButtons.OK)

INIDelete(sPath, "section1", "key1-2") ' delete middle entry in section 1
sValue = INIRead(sPath, "section1") ' get all keys in section again
sValue = sValue.Replace(ControlChars.NullChar, "|"c) ' change embedded NULLs to pipe chars
MessageBox.Show(sValue, "section1 post delete", MessageBoxButtons.OK)

sValue = INIRead(sPath) ' get all section names
sValue = sValue.Replace(ControlChars.NullChar, "|"c) ' change embedded NULLs to pipe chars
MessageBox.Show(sValue, "All sections pre delete", MessageBoxButtons.OK)

INIDelete(sPath, "section1") ' delete section
sValue = INIRead(sPath) ' get all section names
sValue = sValue.Replace(ControlChars.NullChar, "|"c) ' change embedded NULLs to pipe chars
MessageBox.Show(sValue, "All sections post delete", MessageBoxButtons.OK)
Copy & pasted from another site, cbf to search the one I used.
Quote Originally Posted by Blubb1337 View Post
Make a new module..

Code:
Option Strict On
Module INIAccess

#Region "API Calls"
' standard API declarations for INI access
' changing only "As Long" to "As Int32" (As Integer would work also)
Private Declare Unicode Function WritePrivateProfileString Lib "kernel32" _
Alias "WritePrivateProfileStringW" (ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal lpString As String, _
ByVal lpFileName As String) As Int32

Private Declare Unicode Function GetPrivateProfileString Lib "kernel32" _
Alias "GetPrivateProfileStringW" (ByVal lpApplicationName As String, _
ByVal lpKeyName As String, ByVal lpDefault As String, _
ByVal lpReturnedString As String, ByVal nSize As Int32, _
ByVal lpFileName As String) As Int32
#End Region

Public Overloads Function INIRead(ByVal INIPath As String, _
ByVal SectionName As String, ByVal KeyName As String, _
ByVal DefaultValue As String) As String
' primary version of call gets single value given all parameters
Dim n As Int32
Dim sData As String
sData = space$(1024) ' allocate some room 
n = GetPrivateProfileString(SectionName, KeyName, DefaultValue, _
sData, sData.Length, INIPath)
If n > 0 Then ' return whatever it gave us
INIRead = sdata.Substring(0, n)
Else
iniread = ""
End If
End Function

#Region "INIRead Overloads"
Public Overloads Function INIRead(ByVal INIPath As String, _
ByVal SectionName As String, ByVal KeyName As String) As String
' overload 1 assumes zero-length default
Return INIRead(inipath, sectionname, KeyName, "")
End Function

Public Overloads Function INIRead(ByVal INIPath As String, _
ByVal SectionName As String) As String
' overload 2 returns all keys in a given section of the given file
Return INIRead(inipath, sectionname, Nothing, "")
End Function

Public Overloads Function INIRead(ByVal INIPath As String) As String
' overload 3 returns all section names given just path
Return INIRead(inipath, Nothing, Nothing, "")
End Function
#End Region

Public Sub INIWrite(ByVal INIPath As String, ByVal SectionName As String, _
ByVal KeyName As String, ByVal TheValue As String)
Call WritePrivateProfileString(SectionName, KeyName, TheValue, INIPath)
End Sub

Public Overloads Sub INIDelete(ByVal INIPath As String, ByVal SectionName As String, _
ByVal KeyName As String) ' delete single line from section
Call WritePrivateProfileString(SectionName, KeyName, Nothing, INIPath)
End Sub

Public Overloads Sub INIDelete(ByVal INIPath As String, ByVal SectionName As String)
' delete section from INI file
Call WritePrivateProfileString(SectionName, Nothing, Nothing, INIPath)
End Sub

End Module
Usage:

Code:
Dim sValue As String
Dim sPath As String
sPath = "testing.ini"

INIWrite(sPath, "Section1", "Key1-1", "Value1-1") ' build INI file
INIWrite(sPath, "Section1", "Key1-2", "Value1-2")
INIWrite(sPath, "Section1", "Key1-3", "Value1-3")
INIWrite(sPath, "Section2", "Key2-1", "Value2-1")
INIWrite(sPath, "Section2", "Key2-2", "Value2-2")

sValue = INIRead(sPath, "section2", "key2-1", "Unknown") ' specify all
MessageBox.Show(sValue, "section2/key2-1/unknown", MessageBoxButtons.OK)

sValue = INIRead(sPath, "section2", "XYZ", "Unknown") ' specify all
MessageBox.Show(sValue, "section2/xyz/unknown", MessageBoxButtons.OK)

sValue = INIRead(sPath, "section2", "XYZ") ' use zero-length string as default
MessageBox.Show(sValue, "section2/XYZ", MessageBoxButtons.OK)

sValue = INIRead(sPath, "section1") ' get all keys in section
sValue = sValue.Replace(ControlChars.NullChar, "|"c) ' change embedded NULLs to pipe chars
MessageBox.Show(sValue, "section1 pre delete", MessageBoxButtons.OK)

INIDelete(sPath, "section1", "key1-2") ' delete middle entry in section 1
sValue = INIRead(sPath, "section1") ' get all keys in section again
sValue = sValue.Replace(ControlChars.NullChar, "|"c) ' change embedded NULLs to pipe chars
MessageBox.Show(sValue, "section1 post delete", MessageBoxButtons.OK)

sValue = INIRead(sPath) ' get all section names
sValue = sValue.Replace(ControlChars.NullChar, "|"c) ' change embedded NULLs to pipe chars
MessageBox.Show(sValue, "All sections pre delete", MessageBoxButtons.OK)

INIDelete(sPath, "section1") ' delete section
sValue = INIRead(sPath) ' get all section names
sValue = sValue.Replace(ControlChars.NullChar, "|"c) ' change embedded NULLs to pipe chars
MessageBox.Show(sValue, "All sections post delete", MessageBoxButtons.OK)
Copy & pasted from another site, cbf to search the one I used.
this is not For vb 2008 Right //
i want something Easy To understand
step by step
That's way complicated Blubb, there are simpler ways, although that may be more effective.
Quote Originally Posted by Jason View Post
That's way complicated Blubb, there are simpler ways, although that may be more effective.
Do you have any Idea ?>?
Quote Originally Posted by mo3ad001 View Post
Do you have any Idea ?>?
Well I know how to do it, but it's text specific. I think I'm going to try and write a more comprehensive save ini function for myself and others today. gives me something to do.
thank you but _
i don't understand him
him talk about other things

Quote Originally Posted by Jason View Post


Well I know how to do it, but it's text specific. I think I'm going to try and write a more comprehensive save ini function for myself and others today. gives me something to do.
i want simple TUT
like to save Items
[name items]
....
[msg when i press Info]
...
Quote Originally Posted by mo3ad001 View Post
thank you but _
i don't understand him
him talk about other things



i want simple TUT
like to save Items
[name items]
....
[msg when i press Info]
...
Okay here's a very simple tut, it should give you an idea of the basics

http://www.mpgh.net/forum/33-visual-...critiques.html

I wrote that a while ago. Scroll down 'til you get to "ALTERNATE METHOD", that one is much better than the first one I posted.
Quote Originally Posted by Jason View Post


Okay here's a very simple tut, it should give you an idea of the basics

http://www.mpgh.net/forum/33-visual-...critiques.html

I wrote that a while ago. Scroll down 'til you get to "ALTERNATE METHOD", that one is much better than the first one I posted.
thank you but the Read ... just Read First line form the Settings.ini
Okay a VERY basic example of saving an ini

Global variable:

[php]
Dim path As String = Application.StartupPath & "\Settings.ini"
[/php]

Saves the contents of TextBox1.Text to an ini

[php]

Private sub SaveINI()

Using sWrite as New IO,StreamWriter(path)

sWrite.WriteLine(TextBox1.Text)

End Using

End Sub

[/php]

Retrieves the setting:

[php]

Private sub RetrieveINI()

Using sRead As New IO.StreamReader(path)

TextBox1.Text = sRead.ReadLine()

End Using

End Sub

[/php]
Quote Originally Posted by Jason View Post
Okay a VERY basic example of saving an ini

Global variable:

[php]
Dim path As String = Application.StartupPath & "\Settings.ini"
[/php]

Saves the contents of TextBox1.Text to an ini

[php]

Private sub SaveINI()

Using sWrite as New IO,StreamWriter(path)

sWrite.WriteLine(TextBox1.Text)

End Using

End Sub

[/php]

Retrieves the setting:

[php]

Private sub RetrieveINI()

Using sRead As New IO.StreamReader(path)

TextBox1.Text = sRead.ReadLine()

End Using

End Sub

[/php]
i use Listbox [ items]
rotfl... leechers should die... people always want stuff already made and ready to use...

Why the hell you fuck a women? Get a pregnant one too? omfg
Now it is YOUR task to figure out how to do it multilined. NOT hard, but you cannot always copy & paste everything without giving it a try.
So what?

for each item as string in listbox1.items

next
Posts 1–15 of 16 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us