Admin@mbox3.magellan-net.de
alina@yourmx.de
bm@schweinischer-bote.de
boris@cosmeta.de
boss@dan2n.de
btiggemann@mbox3.magellan-net.de
catcher009@blacknbeauty.de
Christopher_Zantopp@web.de
dok123@discardmail.com
dominik.keilbach@rocketmail.com
dominik2712@web.de
einkauf@dan2n.de
elke@kunesch.eu
erik_burgbacher_bi17l4lo@send.electronicmailfor.me.uk
feedme@die-bauer.de
feedme@dog-net.org
feedme@drakensang.de-web.cc
feedme@kraffner.de
feedme@schlaegel.it
feedme@sql-kunesch.de
feedme@wipeout6.de
fetcher@open-host.de
frank@spiracyworld.co.uk
getspam@schlaegel-online.de
harun-ali@web.de
iCollectGarbage@gmx.de
ifyoudone@r0ckt.de
ifyyou@r0ckt.de
info@die-bauer.de
info@mbox3.magellan-net.de
info@r0ckt.de
info@rbcms.de
john.deer@spamreducer.eu
john@cannedmeat.elementfx.com
k.tramm@xspin.de
Karl-Heinz.Becher@gmx.de
Kevin.Becaud@bio-muesli.info
kickers88@live.de
knuddels119k@yahoo.de
loremiosumsitdoloramet@yahoo.de
loremiosumsitdoloramet@yahoo.de
lotharwalter@ymail.com
luna@r0ckt.de
matz0302oyqp@domut.de
mgoessel@gmx.net
michael.k@drakensang.de-web.cc
michael.k@drakensang.de-web.cc
michael.k@sql-kunesch.de
michaknopf@googlemail.com
mk@r0ckt.de
msneijder@mbox3.magellan-net.de
nasti_mkorsa@sql-kunesch.de
newcyborg@gmx.net
schlucks@gmx.net
schwarz@die-bauer.de
service@mbox3.magellan-net.de
sp4mf4ng@j-schmitz.net
spam@teh1.de
spamcatcher@spamtrap.dtdns.net
spamela@spamschlucker.org
spamhog.ihatespam@gmail.com
spamlearn@schlarb-it.de
spamlearn@schlarb-it.de
spamtarget@junge-piraten.de
spamtrap@r0ckt.de
spamtrap@sprachdidaktik.org
spoof@dog-net.org
stephan@spamschlucker.org
support@mbox3.magellan-net.de
thanks@marvin-webservice.net
trap.mitschutz@sprachdidaktik.org
trap@sprachdidakt.de
trap@sprachdidaktik.org
trep@marvin-webservice.net
unwanted@shadowpage.de
vertrieb@dan2n.de
wb@munzinger.de
willmehr@drakensang.de-web.cc
willmehr@drakensang.de-web.cc
willmehr@wipeout6.de
wir@dragoncrew.de
xkbzy@grossermist.de
a Image

Ini files are old. But sometimes you want to store one upto five values, without creating a ৺database connection. Then, ini-files are good enough.

Heres the code (i always put it into a new module called ini)

  1.  
  2. Module ini
  3.     Private Declare Ansi Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" ( _
  4.         ByVal lpApplicationName As String, _
  5.         ByVal lpKeyName As String, _
  6.         ByVal lpString As String, _
  7.         ByVal lpFileName As String) _
  8.     As Integer
  9.  
  10.     Private Declare Ansi Function WritePrivateProfileStringI Lib "kernel32" Alias "WritePrivateProfileStringA" ( _
  11.         ByVal lpApplicationName As String, _
  12.         ByVal lpKeyName As String, _
  13.         ByVal lpString As Integer, _
  14.         ByVal lpFileName As String) _
  15.     As Integer
  16.  
  17.     Private Declare Ansi Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" ( _
  18.     ByVal lpApplicationName As String, _
  19.     ByVal lpKeyName As String, _
  20.     ByVal lpDefault As String, _
  21.     ByVal lpReturnedString As String, _
  22.     ByVal nSize As Integer, _
  23.     ByVal lpFileName As String) _
  24.     As Integer
  25.  
  26.     Private Declare Ansi Function GetPrivateProfileStringI Lib "kernel32" Alias "GetPrivateProfileStringA" ( _
  27.     ByVal lpApplicationName As String, _
  28.     ByVal lpKeyName As String, _
  29.     ByVal lpDefault As String, _
  30.     ByVal lpReturnedString As Integer, _
  31.     ByVal nSize As Integer, _
  32.     ByVal lpFileName As String) _
  33.     As Integer
  34.  
  35.     ''' <summary>
  36.    ''' Gets an integer Value from a specified Ini-File
  37.    ''' </summary>
  38.    ''' <param name="INIFile">The File to read from. Full path</param>
  39.    ''' <param name="Section">The Section name</param>
  40.    ''' <param name="Key">Name of the Key to read</param>
  41.    ''' <param name="DefaultValue">This value is returned, if Section or Key is not found</param>
  42.    ''' <param name="BufferSize">Size of the Buffer, 1024 by default</param>
  43.    ''' <returns>The integer Value stored in the ini file, or the default value</returns>
  44.    ''' <remarks></remarks>
  45.    Public Function GetINIInt(ByVal INIFile As String, ByVal Section As String, ByVal Key As String, Optional ByVal DefaultValue As Integer = 0, Optional ByVal BufferSize As Integer = 1024) As String
  46.         Dim sTemp As String = Space(BufferSize)
  47.         Dim Length As Integer = GetPrivateProfileString(Section, Key, DefaultValue, sTemp, BufferSize, INIFile)
  48.         Return Left(sTemp, Length)
  49.     End Function
  50.  
  51.     ''' <summary>
  52.    ''' Gets a String Value from a specified Ini-File
  53.    ''' </summary>
  54.    ''' <param name="INIFile">The File to read from. Full path</param>
  55.    ''' <param name="Section">The Section name</param>
  56.    ''' <param name="Key">Name of the Key to read</param>
  57.    ''' <param name="DefaultValue">This value is returned, if Section or Key is not found</param>
  58.    ''' <param name="BufferSize">Size of the Buffer, 1024 by default</param>
  59.    ''' <returns>The String Value stored in the ini file, or the default value</returns>
  60.    ''' <remarks></remarks>
  61.    Public Function GetINIString(ByVal INIFile As String, ByVal Section As String, ByVal Key As String, Optional ByVal DefaultValue As String = "", Optional ByVal BufferSize As Integer = 1024) As String
  62.         Dim sTemp As String = Space(BufferSize)
  63.         Dim Length As Integer = GetPrivateProfileString(Section, Key, DefaultValue, sTemp, BufferSize, INIFile)
  64.         Return Left(sTemp, Length)
  65.     End Function
  66.  
  67.     ''' <summary>
  68.    ''' Sets an ini Key to specified value
  69.    ''' </summary>
  70.    ''' <param name="INIFile">The File to write to. Full path</param>
  71.    ''' <param name="Section">The Section name</param>
  72.    ''' <param name="Key">Name of the Key to update</param>
  73.    ''' <param name="Value">The Value to set</param>
  74.    ''' <remarks></remarks>
  75.    Public Sub SetINIString(ByVal INIFile As String, ByVal Section As String, ByVal Key As String, ByVal Value As String)
  76.         WritePrivateProfileString(Section, Key, Value, INIFile)
  77.     End Sub
  78.  
  79.     ''' <summary>
  80.    ''' Sets an ini Key to specified value
  81.    ''' </summary>
  82.    ''' <param name="INIFile">The File to write to. Full path</param>
  83.    ''' <param name="Section">The Section name</param>
  84.    ''' <param name="Key">Name of the Key to update</param>
  85.    ''' <param name="Value">The Value to set</param>
  86.    ''' <remarks></remarks>
  87.    Public Sub SetINIInt(ByVal INIFile As String, ByVal Section As String, ByVal Key As String, ByVal Value As Integer)
  88.         WritePrivateProfileStringI(Section, Key, Value, INIFile)
  89.     End Sub
  90. End Module
  91.  


The Usage is Very simple:

  1.  
  2. ini.SetINIString("test.ini", "config", "FirstKey", "aValue")
  3. ini.SetINIString("test.ini", "config", "Key2", "test")
  4. ini.SetINIInt("test.ini", "config", "Key3", 5)
  5. ini.SetINIString("test.ini", "AnotherConfig", "SomeKey", "SomeValue")
  6.  


will result in a ini file , that looks like that:

----
[config]
FirstKey=aValue
Key2=test
Key3=5

[AnotherConfig]
SomeKey=SomeValue
----

To read values, simple use the Get-Functions:

  1.  
  2. Dim myString as String = ini.GetINIString("test.ini","Config","FirstKey","not found")
  3. ' myString is now "aValue"
  4. Dim myString2 as string = ini.GetINIString("test.ini","Config","AKeyThatIsntValid","not found")
  5. ' myString2 is now "not found"
  6.  


Update 2009-12-27
You can ৺download the ini.vb file here:

Another Pic
Download ini.vb

Related Tags:

Stay tuned:

r a t y y

Top 25 Tag-Cloud (last 14 days):

Trackbacks on this post:

Comments on this post:

Not yet a comment...

Leave a Comment:

Captcha-Code:        reload
Name:
Captcha:
Comment:

Donate!

Like my stuff? Feel free to donate!
 
Modellbau Forum pspad Browser-Statistiken WhatPulse logo dog-net.org Valid XHTML 1.0 Transitional CSS ist valide!

Developmentvb.NET | 2010-01-01 16:41:25

LeadImage

Listview onSelectedIndexChanged Event

The ৺.net ListView offers a ৺onSelectedIndexChanged-Event. But if you are selecting another value, the event is fired twice.

read more...

Developmentvb.NET | 2009-07-09 03:26:30

LeadImage

MakeNiceSize() - Rekursive

This is a little vb.net ৺snippet, to create a nice file size

read more...

Developmentvb.NET | 2009-07-09 03:26:21

LeadImage

MakeNiceSize() - Loop

This is a little vb.net ৺snippet, to create a nice file size

read more...

Developmentvb.NET | 2009-07-09 03:26:12

LeadImage

MakeNiceSize() - Custom Size

This is a little vb.net ৺snippet, to create a nice file size

read more...
Copyright © 2008 - 2010 | by dog.net Development | Imprint | Load in 1.851616