vb.net 2010 default value for shared variable
-
In a VB.net 2010 desktop application, reports obtain their values to execute by users selecting values from the various vb.net controls. In 2 columns where there are date pickers, the default value of the date pickers is to use today's date. The application passes values from the controls using the following code:
Private Sub dtEnddate_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtEnddate.ValueChanged
Variables.g_strEndDate = dtEnddate.Text
End Sub
Private Sub dtEnddate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtEnddate.Click
Variables.g_strEndDate = dtEnddate.Text
End Sub
The problem is if the user keeps todays date, and does not change the date, the variables.g_strEndDate never gets a value. These variables I am referring to are in a Public Class Variables and the variable is define as Public Shared g_strEndDate As String. Thus can you tell me the best way to give this column default values of today's date? What code would you use and where would you place the code?
-
In a VB.net 2010 desktop application, reports obtain their values to execute by users selecting values from the various vb.net controls. In 2 columns where there are date pickers, the default value of the date pickers is to use today's date. The application passes values from the controls using the following code:
Private Sub dtEnddate_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtEnddate.ValueChanged
Variables.g_strEndDate = dtEnddate.Text
End Sub
Private Sub dtEnddate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtEnddate.Click
Variables.g_strEndDate = dtEnddate.Text
End Sub
The problem is if the user keeps todays date, and does not change the date, the variables.g_strEndDate never gets a value. These variables I am referring to are in a Public Class Variables and the variable is define as Public Shared g_strEndDate As String. Thus can you tell me the best way to give this column default values of today's date? What code would you use and where would you place the code?
classy_dog wrote:
Thus can you tell me the best way to give this column default values of today's date?
You could initialize it with a value when the application starts.
classy_dog wrote:
What code would you use
I would recommend removing the global variable altogether. If it is a dialog, then the values should be returned upon closing the dialog and passed to the method that needs them.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)
-
In a VB.net 2010 desktop application, reports obtain their values to execute by users selecting values from the various vb.net controls. In 2 columns where there are date pickers, the default value of the date pickers is to use today's date. The application passes values from the controls using the following code:
Private Sub dtEnddate_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtEnddate.ValueChanged
Variables.g_strEndDate = dtEnddate.Text
End Sub
Private Sub dtEnddate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtEnddate.Click
Variables.g_strEndDate = dtEnddate.Text
End Sub
The problem is if the user keeps todays date, and does not change the date, the variables.g_strEndDate never gets a value. These variables I am referring to are in a Public Class Variables and the variable is define as Public Shared g_strEndDate As String. Thus can you tell me the best way to give this column default values of today's date? What code would you use and where would you place the code?
Is there some reason that you cannot simply give the variables default values when you declare them?
You can lead a developer to CodeProject, but you can't make them think. The Theory of Gravity was invented for the sole purpose of distracting you from investigating the scientific fact that the Earth sucks.
-
In a VB.net 2010 desktop application, reports obtain their values to execute by users selecting values from the various vb.net controls. In 2 columns where there are date pickers, the default value of the date pickers is to use today's date. The application passes values from the controls using the following code:
Private Sub dtEnddate_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtEnddate.ValueChanged
Variables.g_strEndDate = dtEnddate.Text
End Sub
Private Sub dtEnddate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtEnddate.Click
Variables.g_strEndDate = dtEnddate.Text
End Sub
The problem is if the user keeps todays date, and does not change the date, the variables.g_strEndDate never gets a value. These variables I am referring to are in a Public Class Variables and the variable is define as Public Shared g_strEndDate As String. Thus can you tell me the best way to give this column default values of today's date? What code would you use and where would you place the code?
Wrong approach! Store dates as dates, not string! String represenation may differ in different localization/culture. Always initialize variables! It can save you from stress ;)