Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. vb.net 2010 default value for shared variable

vb.net 2010 default value for shared variable

Scheduled Pinned Locked Moved Visual Basic
csharphelpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    classy_dog
    wrote on last edited by
    #1

    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?

    L M 3 Replies Last reply
    0
    • C classy_dog

      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?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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)

      1 Reply Last reply
      0
      • C classy_dog

        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?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • C classy_dog

          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?

          M Offline
          M Offline
          Maciej Los
          wrote on last edited by
          #4

          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 ;)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups