Question How to set and get a value from a class property within the main event of a module ?

Michel_P

New member
Joined
Jul 8, 2011
Messages
2
Programming Experience
Beginner
Hi,
I started as a part-timer in my current job(vb.net developer - windows forms) 6 months ago and now I'm stuck with a major problem...
My boss gave me the project he was working on, my problem there is: the project uses a submain as startup object which is located in a module, thy so the application will be started in tray. Within the main() event i need to deserialize a xml file and with it set the properties of a class and then set what the application will do.
The problem is, after I deserialize it and put set the property values I try to get them in the same event(main) but when it gets the value it returns as nothing(if string) or 0(if integer) but in the debugging i saw it setting the values.
Is there a way to do that, within the main() event of a module to set the properties of a class and then get them without being nothing/0 ?

Sorry if there's any grammar error, I'm still improving my English.
 
Last edited:
If you set property values then , when you get those property values, you will get the values you set. That is an absolute. If you are getting Nothing and 0 then I would guess that you are actually getting the property values from a different object to the one you're setting them on. Perhaps you could show us some code and provide an explanation of what you expect to happen and what actually does happen.
 
Those are the code parts you might need to analyse the app
when i call the .carregar it should fill the config class but just after when i call the mconfig.TempoSincronizacao or the mconfig.sync it returns a different value(nothing/0) than the xml file values.
the problem is in the 1st part of the code
on every property of the class config
if i call it on timer.tick it have the right values but on main it seems like they've never been set

VB.NET:
Module xxx Public filePath As String Public mconfig As New configuracao Public appicon As New NotifyIcon() Public menu_context As New ContextMenu() Public WithEvents mostra_configuracao As New MenuItem("Config...") Public WithEvents sai_app As New MenuItem("Exit") Public WithEvents tempo As New Timer Private cEventLog As New cEventLog Private wsHelpDesk As New wsHelpDesk2.wsHelpDeskSoapClient Private WithError As Boolean Private Stabilishment As String Public Sub main() Dim ico As Icon = My.Resources.sp Application.EnableVisualStyles() appicon.Icon = ico menu_contexto.MenuItems.Add(mostra_configuracao) menu_contexto.MenuItems.Add(sai_app) appicon.ContextMenu = menu_context appicon.Text = "Sistema exportador Qbit" appicon.Visible = True With mconfig .carregar() If .TempoSincronizacao <> 0 Then tempo.Interval = .TempoSincronizacao * 60000 Else tempo.Interval = 60000 End If setConfiguracoes(BaseDeDados.FireBird, .server, .archive, .User, .Pass) tempo.Enabled = .Sync End With Application.Run() End Sub-----------------------------------------------------------------------------------------------Public Sub carregar() Dim filePath = Application.StartupPath & "\xxx.config" If File.Exists(filePath) Then Dim fs As New FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.None) Dim xs As New Serialization.XmlSerializer(GetType(configuracao)) mconfig = CType(xs.Deserialize(fs), config) fs.Close() If tempo.Enabled = False And Sincronizar Then tempo.Enabled = True End If Else If Not frmConfiguracao.Visible Then frmConfiguracao.ShowDialog() End If End If End Sub-----------------------------------------------------------------------------------------------------<Serializable()>Public Class config#Region "Propriedades" Private _server As String Public Property server As String Get server = _server End Get Set(ByVal value As String) _server = value End Set End Property Private _User As String Public Property User As String Get User = _User End Get Set(ByVal value As String) _Usuario_Firebird = value End Set End Property Private _Pass As String Public Property Pass As String Get Pass = _Pass End Get Set(ByVal value As String) _Pass = value End Set End Property Private _archive As String Public Property archive As String Get archive = _archive End Get Set(ByVal value As String) _archive = value End Set End Property Private _ativado As Boolean Public Property ativado As Boolean Get ativado = _ativado End Get Set(ByVal value As Boolean) _ativado = value End Set End Property Private _express As Boolean Public Property express As Boolean Get express = _express End Get Set(ByVal value As Boolean) _express = value End Set End Property Private _Sync As Boolean Public Property Sync() As Boolean Get Return _Sync End Get Set(ByVal value As Boolean) _Sync = value End Set End Property Private _TempoSincronizacao As Integer Public Property TempoSincronizacao() As Integer Get Return _TempoSincronizacao End Get Set(ByVal value As Integer) _TempoSincronizacao = value End Set End Property#End Region
 
Back
Top