Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8069743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:09:36+00:00 2026-06-05T13:09:36+00:00

Just working on getting more fluent in Visual Basic over the summer so I’m

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:09:39+00:00Added an answer on June 5, 2026 at 1:09 pm

    You are describing Module Level Scope.

    From above link:

    For convenience, the single term module level applies equally to modules, classes, and structures. You can declare elements at this level by placing the declaration statement outside of any procedure or block but within the module, class, or structure.

    When you make a declaration at the module level, the access level you choose determines the scope. The namespace that contains the module, class, or structure also affects the scope.

    Elements for which you declare Private (Visual Basic) access level are available to every procedure in that module, but not to any code in a different module. The Dim statement at module level defaults to Private if you do not use any access level keywords. However, you can make the scope and access level more obvious by using the Private keyword in the Dim statement.

    So in your case I would do something like this

    Public Class Form1  
        
        Dim hourArray(0 To 11) As String   'These variables are private to your Class
        Dim minuteArray(0 To 59) As String 
    
        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 
    
            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 
    
            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 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just getting started on NVelocity (v1.1.1) and it seems to be working just fine.
Just getting started with C++ here. I am working on OSX with Eclipse CDT.
I'm having real problems getting PDO_MYSQL working. I started by just trying to install
I'm just getting started with Dependency Injection (DI) using Ninject and am working through
I just installed Boost on my machine. I'm working with the Visual Studio 2010
I am working on a small toy project who is getting more and more
So I'm just getting started with Python, and currently working my way through http://diveintopython3.ep.io/
I'm currently working on a project that's getting more complex than I thought it
I am just getting started working with Google API and OAuth2. When the client
I've just been given the task of getting a previously working version of an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.