Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Public vars

Status
Not open for further replies.

spyderco

Programmer
Jan 23, 2005
107
US
Just finished the meta tag generator yesterday and it works great. Now onto a reaction time game that changes the background and sees how fast you react.

The first question is, how do I make public variables? I tried "public _startTime as DateTime" but that didn't work and either did taking the Private subs and making them Public.

It needs to be globally accessible variables so I can track the start and stop button with the time variables being in both.

Code:
    Public Sub StartBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartBtn.Click
        Dim _randomNum As Integer = New System.Random(). _
                 Next("1", "15")

        System.Threading.Thread.Sleep(1000 * _randomNum)
        Dim _startTime As DateTime
        Dim _stopTime As DateTime
        _startTime = Now 'initiate the time NOW

        'MsgBox(getRandomNumber)

        Me.Label1.BackColor = System.Drawing.Color.Blue

    End Sub

    Public Sub StopBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopBtn.Click
        _stopTime = Now ' intiate the endtime NOW
    End Sub

The second question is.. is there a way to kill all processes without killing the program?

For example, the user clicks the Start button.. a random number is chosen and a sleep() executed. If the user presses Stop BEFORE the background changes, a messagebox would complain and then kill the process of the background changing. Simply put, if they do something too soon, I'd like to prompt them and put the program back in it's original state.. OR just stop all current processes without closing the window.

Any ideas?

Thanks!
 
you should make your variabels shared

Code:
public shared _name as string

You shouldn't use sleep, you should use a timer, by preference the threading variety.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Hi.

Code:
public shared _stopTime as string

Doesn't work. It says neither public nor shared are proper local variable declarations.

Any suggestions?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top