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 633583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:12:09+00:00 2026-05-13T20:12:09+00:00

I’m looking at controlling properties of an array of buttons in VB 2008 (express).

  • 0

I’m looking at controlling properties of an array of buttons in VB 2008 (express). I have been looking at the sample code from a whitepaper at MS, and it kind of makes my head spin compared to what was done in VB6! (and yes I’m an amateur, so please forgive the poor coding and what is probably a simple question for the experienced here…)

If I’m reading it correctly, the correct way to do it now is to create a separate class, create constructors, etc. for that class, then instantiate it in the project?

I’m trying to use a relatively simple array like this:

    'Create buttons
    'Dim btn(30) As Button
    'For i As Integer = 0 To 29
    '    btn(i) = New Button()
    '    btn(i).Width = 100
    '    btn(i).Height = 30
    '    btn(i).Text = i + 1

    '    btn(0).Left = 120
    '    btn(0).Top = 100

    '    If i >= 1 And i <= 14 Then
    '        btn(i).Left = 120
    '        btn(i).Top = btn(0).Top + (i * 30)
    '    End If

    '    If i = 15 Then
    '        btn(15).Left = 235
    '        btn(15).Top = 100
    '    End If

    '    If i >= 16 And i <= 29 Then
    '        btn(i).Left = 235
    '        btn(i).Top = btn(0).Top + ((i Mod 15) * 30)
    '    End If
    '    Me.Controls.Add(btn(i))

    'Next

If I put it into the load method, then I can’t access it from another button, because I think it’s in a private subroutine when this snippet is in the load subroutine? Is there a simple way to just have this code so that the btn(i) array is accessible from other functions in the form?

  • 1 1 Answer
  • 1 View
  • 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-05-13T20:12:09+00:00Added an answer on May 13, 2026 at 8:12 pm

    You need to make the button array a field or a property in the class rather than in the load method.

    Easiest way is to just move the Dim btn(30) As Button declaration out of the load method into the class (stick it on the line above the load method) and you’re done.

    One might argue about coding standards and stuff – but I think that’ll get you working (-:

    Ok, further to the above and your comment, just enough code to illustrate what I was trying to explain. This code will compile and run – button array accessible from two methods within the form class:

    Public Class Form1
    
        Dim btn(30) As Button
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            For i As Integer = 0 To 29
                btn(i) = New Button
            Next
        End Sub
    
        Private Sub DoSomethingElse()
            For i As Integer = 0 To 29
                btn(i).Text = String.Format("{0}", i + 1)
            Next
        End Sub
    
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I have been unable to fix a problem with Java Unicode and encoding. The
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.