Worksheet.nl  

Ga terug   Worksheet.nl > Excel Overig > Downloads



Status bericht: Opgelost
Reageren
 
Discussietools Weergave
  #1  
Oud 19 July 2010, 22:00
Mr. Magoo's schermafbeelding
Super Moderator
 
Geregistreerd: 17 November 2005
Locatie: Blokker Nederland
Berichten: 4.884
Standaard Ini File demo

Ik heb een voorbeeld gemaakt die demonstreert hoe een Inifile werkt.

Maak hierbij gebruik van een Classe
Heb hier op het forum al eens een simpele inifile Classe geplaatst.
Deze is uitgebreider zowel de Classe als het voorbeeld.

Mochten er vragen zijn hoor ik het wel

Code:
'Classe voorbeeld: IniFile
'Datum: Juli 2010
'Mr. Magoo
'www.worksheet.nl/forumexcel/

Option Explicit

Private Path_Property As String
Private Key_Property As String
Private Section_Property As String
Private Default_Property As String
Private WriteError_Property As Long

'Profile String DLL functie's:
Private Declare Function WritePrivateProfileString Lib "Kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private Declare Function GetPrivateProfileString Lib "Kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As Any, ByVal lpKeyName As Any, ByVal lpDefault As Any, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

'Geef path en de filenaam op van de Inifile
Property Let Path(LetValue As String)
  Path_Property = LetValue
End Property

'Geef path en de filenaam terug van de Inifile waar naar toe wordt geschreven
Property Get Path() As String
  Path = Path_Property
End Property

'Geeft Error foutwaarde als het schrijven naar de Inifile is mislukt
'True -> Fout / False -> Geen fouten
Property Get WriteError() As Boolean
  WriteError = Not (WriteError_Property > 0)
End Property

Property Let Default(LetValue As String)
  Default_Property = LetValue
End Property

Property Get Default() As String
  Default = Default_Property
End Property

'Keywaarde welke geschreven moet worden
Property Let Key(LetValue As String)
  Key_Property = LetValue
End Property

'Lees de laatste gelezen keywaarde / keywaarde welke opgegeven is
Property Get Key() As String
  Key = Key_Property
End Property

'Sectionwaarde welke geschreven moet worden
Property Let Section(LetValue As String)
  Section_Property = LetValue
End Property

'Lees de laatste gelezen sectionwaarde / sectionwaarde welke opgegeven is
Property Get Section() As String
  Section = Section_Property
End Property

'Lees de waarde uit de opgegeven Section en opgegeven Key
Property Get Value() As String
  Dim ReturnValue As String, CountChar As Long

  If Path_Property <> "" Then
    ReturnValue = String(255, Chr(0))
    CountChar = GetPrivateProfileString(Section_Property, Key_Property, Default_Property, ReturnValue, Len(ReturnValue), Path_Property)
  End If
  Value = IIf(CountChar > 0, Left(ReturnValue, CountChar), "")
End Property

'Schrijf de opgegeven waarde in de opgegeven Section en opgegeven Key
Property Let Value(LetValue As String)
  WriteError_Property = WritePrivateProfileString(Section_Property, Key_Property, LetValue, Path_Property)
End Property

'Verwijder de key + keywaarde in een section
Public Sub DeleteKey()
  WriteError_Property = WritePrivateProfileString(Section_Property, Key_Property, 0&, Path_Property)
End Sub

'Verwijder de opgegeven Section + key + keywaarde
Public Sub DeleteSection()
  WriteError_Property = WritePrivateProfileString(Section_Property, 0&, 0&, Path_Property)
End Sub

'Schrijf huidige section naar Inifile
Property Let CurrentSection(LetValue As String)
  WriteError_Property = WritePrivateProfileString(Section_Property, 0&, LetValue, Path_Property)
End Property

'Lees alle sections uit de Inifile en plaats deze in een string.
'Sections worden gescheiden door karakter chr(0)
Property Get AllSections() As String
  Dim Buf As String, Size As String, CountChar As Long

  If Path_Property <> "" Then
    Size = 8192  '8 Kb (1024*8)
    Buf = String(Size, Chr(0))
    CountChar = GetPrivateProfileString(0&, 0&, Default_Property, Buf, Size, Path_Property)
  End If
  AllSections = IIf(CountChar > 0, Left(Buf, CountChar), "")
End Property

'Plaats alle sections in een array
Public Sub EnumerateAllSections(ByRef Section() As String, ByRef Count As Long)
  Dim Sections As String

  Sections = AllSections
  Section() = Split(Sections, Chr(0))
  Count = IIf(Len(Sections) > 0, UBound(Section()), 0)
End Sub

'Lees alle keys van huidige section uit de Inifile en plaats deze in een string.
'Keys worden gescheiden door karakter chr(0)
Property Get CurrentSection() As String
  Dim Buf As String, Size As String, CountChar As Long

  If Path_Property <> "" Then
    Size = 8192  '8 Kb (1024*8)
    Buf = String(Size, Chr(0))
    CountChar = GetPrivateProfileString(Section_Property, 0&, Default_Property, Buf, Size, Path_Property)
  End If
  CurrentSection = IIf(CountChar > 0, Left(Buf, CountChar), "")
End Property

'Plaats alle keys van huidige section in een array
Public Sub EnumerateCurrentSection(ByRef Key() As String, ByRef Count As Long)
  Dim Section As String

  Section = CurrentSection
  Key() = Split(Section, Chr(0))
  Count = IIf(Len(Section) > 0, UBound(Key()), 0)
End Sub
Bijgevoegde bestanden
Bestandstype: xls Ini File Classe voorbeeld.xls‎ (79,5 KB, 76x gelezen)
__________________
Suc6

druk op F1 en lees ! En zie wat de moeder van de meeste oplossingen is.
en Worksheet.nl is de dochter

Moderator www.worksheet.nl / mr.magoo@worksheet.nl

Lees informatieve columns over buitenlandse reizen en wandelingen in Nederland
Verrassende columns over het leven van alledag op een camping.
Optimistische columns over pubers, ouders en ouderen. op www.jolandacatharina.nl
Met citaat reageren
Sponsored Links
Reageren

Labels
classe inifile


Discussietools
Weergave

Regels voor berichten
Je mag geen nieuwe discussies starten
Je mag niet reageren op berichten
Je mag geen bijlagen versturen
Je mag niet je berichten bewerken

BB code is Aan
Smileys zijn Aan
[IMG]-code is Aan
HTML-code is Uit
Trackbacks are Aan
Pingbacks are Aan
Refbacks are Aan



Ga terug   Worksheet.nl > Excel Overig > Downloads



Alle tijden zijn GMT +1. Het is nu 01:51.


Forumsoftware: vBulletin®, versie 3.8.7
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.0