Public Class clsSettings
'http://www.tek-tips.com/faqs.cfm?fid=6320
'ejemplo uso:
'clsSettings.clsSetSetting("MyValue", "1234567890")
'msgbox(clsSettings.GetSetting("MyValue"))
'NOTA: Si queremos guardar un archivo de configuración diferente para cada usuario,
'solo tenemos que cambiar Application.StartupPath por Application.LocalUserAppDataPath
Public Shared Function GetSetting(ByVal Key As String) As String
Dim sReturn As String = String.Empty
Dim dsSettings As New DataSet
If System.IO.File.Exists(Application.StartupPath & "\Settings.xml") Then
dsSettings.ReadXml(Application.StartupPath & "\Settings.xml")
Else
dsSettings.Tables.Add("Settings")
dsSettings.Tables(0).Columns.Add("Key", GetType(String))
dsSettings.Tables(0).Columns.Add("Value", GetType(String))
End If
Dim dr() As DataRow = dsSettings.Tables("Settings").Select("Key = '" & Key & "'")
If dr.Length = 1 Then sReturn = dr(0)("Value").ToString
Return sReturn
End Function
Public Shared Sub SetSetting(ByVal Key As String, ByVal Value As String)
Dim dsSettings As New DataSet
If System.IO.File.Exists(Application.StartupPath & "\Settings.xml") Then
dsSettings.ReadXml(Application.StartupPath & "\Settings.xml")
Else
dsSettings.Tables.Add("Settings")
dsSettings.Tables(0).Columns.Add("Key", GetType(String))
dsSettings.Tables(0).Columns.Add("Value", GetType(String))
End If
Dim dr() As DataRow = dsSettings.Tables(0).Select("Key = '" & Key & "'")
If dr.Length = 1 Then
dr(0)("Value") = Value
Else
Dim drSetting As DataRow = dsSettings.Tables("Settings").NewRow
drSetting("Key") = Key
drSetting("Value") = Value
dsSettings.Tables("Settings").Rows.Add(drSetting)
End If
dsSettings.WriteXml(Application.StartupPath & "\Settings.xml")
End Sub
End Class
Suscribirse a:
Enviar comentarios (Atom)
VBA Access. Redondeo de números decimales con el método medio redondeo. Alternativa a la función Round (bankers round)
Private Function Redondeo(ByVal Numero As Variant, ByVal Decimales As Integer) As Double 'Aplica método medio redondeo (half round ...
-
Option Compare Database Option Explicit '***************************** ' 'Ejemplo de uso ' 'selecciona 1 ficher...
-
Option Compare Database Option Explicit 'Zip / UnZip file or folder 'http://www.codekabinett.com/rdumps.php?Lang=2&targetDoc...
No hay comentarios:
Publicar un comentario