Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2012 Help: How to share a variable between subs?

$
0
0
('inserts long story of how he is a noob')

When i was in school my teacher told me that using global variables was something to avoid at all cost. I'm trying to call the variable from another sub, and when I add the ByRef it throws an error. Probably the worst explanation every so here is the code

Code:

    Public Sub dragonTimer_Tick(sender As Object, e As EventArgs, ByRef dragonTimeLeft As Integer) Handles dragonTimer.Tick

        If dragonTimeLeft >= 0 Then
            dragonTimeLeft -= 1
            dragonTimeLabel.Text = dragonTimeLeft
        Else
            dragonTimer.Stop()
            dragonTimeLabel.Text = "Respawning"
            'Add a sound/voice to tell user time is up
        End If

    End Sub

    Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim dragonTimeLeft As Integer = 360

        dragonTimeLabel.Text = 360
        dragonTimer.Start()

    End Sub

Here is the error I am getting.

Error 1 Method 'Public Sub dragonTimer_Tick(sender As Object, e As System.EventArgs, ByRef dragonTimeLeft As Integer)' cannot handle event 'Public Event Tick(sender As Object, e As System.EventArgs)' because they do not have a compatible signature.

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>