|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|||
|
static variables in vb.net
Try below code:
Shared start_time As DateTime Shared stop_time As DateTime Private Sub cmdNewRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNewRecord.Click Dim elapsed_time As TimeSpan If Me.cmdNewRecord.Text = "New Record" Then Me.txtComments.Text = "" start_time = Now Me.cmdNewRecord.Text = "Save" Else stop_time = Now elapsed_time = stop_time.Subtract(start_time) Me.txtComments.Text = _ elapsed_time.TotalSeconds.ToString("0.000000") Me.cmdNewRecord.Text = "New Record" End If End Sub |
|
||||
|
Static <> Shared in VB.Net.
Shared is more analogous to C#/C++ static. Static in VB.Net is a little... special. Static members in a function are scoped to the function, in that they are not accessible outside the function. Therefore you debugger shouldn't be able to see them. They should be available (with their previous values) on the next function call, however. You could of course also declare them outside the function (scoped to the class) as vgangal suggests. However, if you do that they shouldn't be declared as Shared anymore. Just make them private. The advantage to keeping them in the function is that then they are guaranteed to be threadsafe. You might also want to consider using System.Diagnostics.StopWatch rather than DateTime.Now for this. |
|
|||
|
I have never read about vb.net that's why i had entered for gain any type of information from there so i think these posts useful for me but this is not enough for me so i am waiting for the other posts..
|
![]() |
| Viewing: Dev Hardware Forums > SOFTWARE > Programming > VB.NET + Static Variables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|