N
NachoShaw
Guest
Hey
Could someone help me set this so it works please? I have the right idea but its not working properly. What i am trying to do is read a bunch of Registry Values as my form opens and populate some properties. Then if some of these values change, the property is updated and then the registry to match the properties. The property values update some setting fields on my form.
This is what i have, i dont think its right..
My GetSet to / from Registry
Imports Microsoft.Win32
Public Class GetSetRegistry
Public ReadOnly Property HKeyLocalMachine() As RegistryKey
Get
Return Registry.LocalMachine
End Get
End Property
Public Function WriteValue(ByVal ParentKey As RegistryKey, ByVal SubKey As String,
ByVal ValueName As String, ByVal Value As Object) As Boolean
Dim Key As RegistryKey
Try
'Open the given subkey
Key = ParentKey.OpenSubKey(SubKey, True)
If Key Is Nothing Then 'when subkey doesn't exist create it
Key = ParentKey.CreateSubKey(SubKey)
End If
'Once we have a handle to the key, set the value(the data)
Key.SetValue(ValueName, Value)
Return True
Catch e As Exception
Return False
End Try
Key.Close()
End Function
Public Function ReadValue(ByVal ParentKey As RegistryKey, ByVal SubKey As String,
ByVal ValueName As String, ByRef Value As Object) As Boolean
Dim Key As RegistryKey
Try
'open the given subkey
Key = ParentKey.OpenSubKey(SubKey, True)
If Key Is Nothing Then 'when the key doesn't exist throw an
'exception
Throw New Exception("the subkey doens't exist")
End If
'Get the value
Value = Key.GetValue(ValueName)
Return True
Catch e As Exception
Return False
End Try
Key.Close()
End Function
End Class
My Property Class
Public Class MySettings
Private ReadOnly objReg As New GetSetRegistry
Private ReadOnly RegPath As String = "Software\MyApp"
Friend Property ApplyMaterial As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "ApplyMaterial", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "ApplyMaterial", "")
End Get
End Property
Friend Property AssemblyMaterialText As String
Set(ByVal value As string)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "AssemblyMaterialText", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "AssemblyMaterialText", "")
End Get
End Property
Friend Property AssyRootSave As String
Set(ByVal value As String)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "AssyRootSave", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "AssyRootSave", "")
End Get
End Property
Friend Property ConnDatasource As String
Set(ByVal value As String)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "ConnDatasource", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "ConnDatasource", "")
End Get
End Property
Friend Property ConnInitialCatalog As String
Set(ByVal value As String)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "ConnInitialCatalog", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "ConnInitialCatalog", "")
End Get
End Property
Friend Property ConnPassword As String
Set(ByVal value As String)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "ConnPassword", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "ConnPassword", "")
End Get
End Property
Friend Property ConnPort As String
Set(ByVal value As String)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "ConnPort", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "ConnPort", "")
End Get
End Property
Friend Property ConnUserID As String
Set(ByVal value As String)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "ConnUserID", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "ConnUserID", "")
End Get
End Property
Friend Property CreateDrawing As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "CreateDrawing", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "CreateDrawing", "")
End Get
End Property
Friend Property FlattenAssy As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "FlattenAssy", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "FlattenAssy", "")
End Get
End Property
Friend Property LengthUnit As String
Set(ByVal value As String)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "LengthUnit", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "LengthUnit", "")
End Get
End Property
Friend Property LookFeel As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "Look&Feel", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "Look&Feel", "")
End Get
End Property
Friend Property Organise As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "Organise", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "Organise", "")
End Get
End Property
Friend Property ProjectPath As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "ProjectPath", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "ProjectPath", "")
End Get
End Property
Friend Property ReplaceCode As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "ReplaceCode", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "ReplaceCode", "")
End Get
End Property
Friend Property SupressASME As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "SupressASME", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "SupressASME", "")
End Get
End Property
Friend Property SupressSMLS As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "SupressSMLS", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "SupressSMLS", "")
End Get
End Property
Friend Property TemplatePath As String
Set(ByVal value As String)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "TemplatePath", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "TemplatePath", "")
End Get
End Property
Friend Property UseDarkTheme As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "UseDarkTheme", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "UseDarkTheme", "")
End Get
End Property
Friend Property UseFaceInitials As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "UseFaceInitials", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "UseFaceInitials", "")
End Get
End Property
Friend Property UsePrefix As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "UsePrefix", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "UsePrefix", "")
End Get
End Property
Friend Property UseTypeInitials As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "UseTypeInitials", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "UseTypeInitials", "")
End Get
End Property
Friend Property ZeroValueReplacement As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "ZeroValueReplacement", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "ZeroValueReplacement", "")
End Get
End Property
Friend Property Separator As String
Set(ByVal value As String)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "Separator", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "Separator", "")
End Get
End Property
End Class
And how i am trying to call it
'Declared in my Form
Public GetSettings As MySettings = New MySettings()
Then as a property value is required, i am trying to get it from GetSettings
Dim GetCurrentCode As String = GetSettings.ReplaceCode
And how i am trying to set the value
GetSettings.ReplaceCode = "some current code"
What would be the right way to approach this? I thought that as an alternative, i could list out a set of public properties to store the Regvalues and get them set them on the fly with a get / set function but id like to know that i am doing it the best & most efficient way-
Any advice greatly received
Thanks
Im a self taught VB.Net guy who writes code for Autodesk Inventor. I may not know the terminology but i try so please be patient. Im not a kid so please dont treat me like one
Continue reading...
Could someone help me set this so it works please? I have the right idea but its not working properly. What i am trying to do is read a bunch of Registry Values as my form opens and populate some properties. Then if some of these values change, the property is updated and then the registry to match the properties. The property values update some setting fields on my form.
This is what i have, i dont think its right..
My GetSet to / from Registry
Imports Microsoft.Win32
Public Class GetSetRegistry
Public ReadOnly Property HKeyLocalMachine() As RegistryKey
Get
Return Registry.LocalMachine
End Get
End Property
Public Function WriteValue(ByVal ParentKey As RegistryKey, ByVal SubKey As String,
ByVal ValueName As String, ByVal Value As Object) As Boolean
Dim Key As RegistryKey
Try
'Open the given subkey
Key = ParentKey.OpenSubKey(SubKey, True)
If Key Is Nothing Then 'when subkey doesn't exist create it
Key = ParentKey.CreateSubKey(SubKey)
End If
'Once we have a handle to the key, set the value(the data)
Key.SetValue(ValueName, Value)
Return True
Catch e As Exception
Return False
End Try
Key.Close()
End Function
Public Function ReadValue(ByVal ParentKey As RegistryKey, ByVal SubKey As String,
ByVal ValueName As String, ByRef Value As Object) As Boolean
Dim Key As RegistryKey
Try
'open the given subkey
Key = ParentKey.OpenSubKey(SubKey, True)
If Key Is Nothing Then 'when the key doesn't exist throw an
'exception
Throw New Exception("the subkey doens't exist")
End If
'Get the value
Value = Key.GetValue(ValueName)
Return True
Catch e As Exception
Return False
End Try
Key.Close()
End Function
End Class
My Property Class
Public Class MySettings
Private ReadOnly objReg As New GetSetRegistry
Private ReadOnly RegPath As String = "Software\MyApp"
Friend Property ApplyMaterial As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "ApplyMaterial", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "ApplyMaterial", "")
End Get
End Property
Friend Property AssemblyMaterialText As String
Set(ByVal value As string)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "AssemblyMaterialText", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "AssemblyMaterialText", "")
End Get
End Property
Friend Property AssyRootSave As String
Set(ByVal value As String)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "AssyRootSave", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "AssyRootSave", "")
End Get
End Property
Friend Property ConnDatasource As String
Set(ByVal value As String)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "ConnDatasource", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "ConnDatasource", "")
End Get
End Property
Friend Property ConnInitialCatalog As String
Set(ByVal value As String)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "ConnInitialCatalog", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "ConnInitialCatalog", "")
End Get
End Property
Friend Property ConnPassword As String
Set(ByVal value As String)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "ConnPassword", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "ConnPassword", "")
End Get
End Property
Friend Property ConnPort As String
Set(ByVal value As String)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "ConnPort", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "ConnPort", "")
End Get
End Property
Friend Property ConnUserID As String
Set(ByVal value As String)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "ConnUserID", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "ConnUserID", "")
End Get
End Property
Friend Property CreateDrawing As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "CreateDrawing", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "CreateDrawing", "")
End Get
End Property
Friend Property FlattenAssy As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "FlattenAssy", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "FlattenAssy", "")
End Get
End Property
Friend Property LengthUnit As String
Set(ByVal value As String)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "LengthUnit", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "LengthUnit", "")
End Get
End Property
Friend Property LookFeel As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "Look&Feel", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "Look&Feel", "")
End Get
End Property
Friend Property Organise As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "Organise", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "Organise", "")
End Get
End Property
Friend Property ProjectPath As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "ProjectPath", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "ProjectPath", "")
End Get
End Property
Friend Property ReplaceCode As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "ReplaceCode", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "ReplaceCode", "")
End Get
End Property
Friend Property SupressASME As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "SupressASME", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "SupressASME", "")
End Get
End Property
Friend Property SupressSMLS As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "SupressSMLS", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "SupressSMLS", "")
End Get
End Property
Friend Property TemplatePath As String
Set(ByVal value As String)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "TemplatePath", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "TemplatePath", "")
End Get
End Property
Friend Property UseDarkTheme As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "UseDarkTheme", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "UseDarkTheme", "")
End Get
End Property
Friend Property UseFaceInitials As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "UseFaceInitials", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "UseFaceInitials", "")
End Get
End Property
Friend Property UsePrefix As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "UsePrefix", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "UsePrefix", "")
End Get
End Property
Friend Property UseTypeInitials As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "UseTypeInitials", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "UseTypeInitials", "")
End Get
End Property
Friend Property ZeroValueReplacement As Boolean
Set(ByVal value As Boolean)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "ZeroValueReplacement", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "ZeroValueReplacement", "")
End Get
End Property
Friend Property Separator As String
Set(ByVal value As String)
objReg.WriteValue(objReg.HKeyLocalMachine, RegPath, "Separator", value)
End Set
Get
Return objReg.ReadValue(objReg.HKeyLocalMachine, RegPath, "Separator", "")
End Get
End Property
End Class
And how i am trying to call it
'Declared in my Form
Public GetSettings As MySettings = New MySettings()
Then as a property value is required, i am trying to get it from GetSettings
Dim GetCurrentCode As String = GetSettings.ReplaceCode
And how i am trying to set the value
GetSettings.ReplaceCode = "some current code"
What would be the right way to approach this? I thought that as an alternative, i could list out a set of public properties to store the Regvalues and get them set them on the fly with a get / set function but id like to know that i am doing it the best & most efficient way-
Any advice greatly received
Thanks
Im a self taught VB.Net guy who writes code for Autodesk Inventor. I may not know the terminology but i try so please be patient. Im not a kid so please dont treat me like one
Continue reading...