Just working on getting more fluent in Visual Basic over the summer so I’m still sharp for my next visual basic class. My teacher went over variables, but only in local scope.
I have looked everywhere, but I can’t find exactly what I need. I’m making an alarm clock of sorts, and I have this code to populate the minute array and the hour array.
Public Class Form1
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.clockTimer.Interval = 1 * 1000
Me.clockTimer.Enabled = True
Dim hourArray(0 To 11) As String
For i As Integer = 1 To 12
If i.ToString.Length < 2 Then
hourArray(i - 1) = "0" & i
Else
hourArray(i - 1) = i
End If
Next
Dim minuteArray(0 To 59) As String
For i As Integer = 0 To 59
If i.ToString.Length < 2 Then
minuteArray(i) = "0" & i
Else
minuteArray(i) = i
End If
Next
hourLabel.Text = hourArray(0)
minuteLabel.Text = minuteArray(0)
End Sub
(Note: The adding of the “0” is just so the clock display will have a “01” instead of a “1”.)
Right now I have this going happening on the forms load (only one form in this project), but it doesn’t have global or public scope. I want to be able to access the hourArray and minuteArray later in the program, but still have this happen on the forms load. How would I do this? Also, what variable scope am I describing? (ie scope for the entire form).
Thanks.
You are describing Module Level Scope.
From above link:
So in your case I would do something like this