473,795 Members | 3,215 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem initializing global label array outside of procedure

The following code snipet won't run if I initialize my global label array
outside of a procedure - say Form_Load. If I initialize the array inside
Form_Load then it works. Is there a way to initialize the label array
outside of a procedure as I am doing? Or... (see below this snipet)
---------------------------------------------------------------------------------
Public Class Form1
Inherits System.Windows. Forms.Form

" Windows Form Designer generated code "

Dim arrlbl As Label() = {lbl0, lbl1, lbl2, lbl3}

Private Sub Form1_Load(...)
Dim i As Integer
For i = 0 To arrlbl.Length - 1 : arrlbl(i).Text = "test" : Next
....
---this not working
----------------------------------------------------------------

Or...

Dim arrlbl(3) As Label

Private Sub Form1_Load(...)
Dim i As Integer
arrlbl(0) = lbl0
arrlbl(1) = lbl1
arrlbl(2) = lbl2
arrlbl(3) = lbl3
For i = 0 To arrlbl.Length - 1 : arrlbl(i).Text = "test" : Next
-------------------------------------------------------------------------

this works but adds an additional 4 rows of code to my project. Is this the
only way to initialize my global array?

Thanks,
Rich
Nov 21 '05 #1
5 2334
Hello Rich,

In your first example you initialize arrlbl at class level. Actually it
happens during the MyBase.New() statement.
lbl* variables are initialized in InitializeCompo nent() method which
executes later.

Thus, at the time ~arrlbl As Label() = {lbl0, lbl1, lbl2, lbl3}~ executes,
lbl's are still uninitialized, so you get an array full of Nothing's.
this works but adds an additional 4 rows of code to my project. Is this the only way to initialize my global array?


No! You can shorten arrlbl(*) = lbl* statements by ~arrlbl = New Label()
{lbl0, lbl1, lbl2, lbl3}~; this way, you don't need to specify bounds in Dim
statement.
You also might want to put this in New() after InitializeCompo nent() to
simulate initialization at class level.

HTH

Roman
Nov 21 '05 #2
Thanks very much for your reply - question:
You can shorten arrlbl(*) = lbl* statements by ~arrlbl = New Label()
{lbl0, lbl1, lbl2, lbl3}~; this way, you don't need to specify bounds in Dim
statement.
You also might want to put this in New() after InitializeCompo nent() to
simulate initialization at class level.
<<

-----------------------------------------------------------------------
Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

~arrlbl = New Label(){lbl0, lbl1, lbl2, lbl3}~

End Sub
-------------------------------------------------------------------

Do I Dim arrlbl? Dim inside of New( )? Appologize for my lack of brain
cells on this. May I request if you could show me a snippet of code what you
are suggesting on how to declare and initialize my global label array?

I'm not clear on your suggestion here.

Thanks,
Rich

"Dragon" wrote:
Hello Rich,

In your first example you initialize arrlbl at class level. Actually it
happens during the MyBase.New() statement.
lbl* variables are initialized in InitializeCompo nent() method which
executes later.

Thus, at the time ~arrlbl As Label() = {lbl0, lbl1, lbl2, lbl3}~ executes,
lbl's are still uninitialized, so you get an array full of Nothing's.
this works but adds an additional 4 rows of code to my project. Is this

the
only way to initialize my global array?


No! You can shorten arrlbl(*) = lbl* statements by ~arrlbl = New Label()
{lbl0, lbl1, lbl2, lbl3}~; this way, you don't need to specify bounds in Dim
statement.
You also might want to put this in New() after InitializeCompo nent() to
simulate initialization at class level.

HTH

Roman

Nov 21 '05 #3
"Rich" <Ri**@discussio ns.microsoft.co m> schrieb
The following code snipet won't run if I initialize my global label
array outside of a procedure - say Form_Load. If I initialize the
array inside Form_Load then it works. Is there a way to initialize
the label array outside of a procedure as I am doing? Or... (see
below this snipet)
---------------------------------------------------------------------------------
Public Class Form1
Inherits System.Windows. Forms.Form

" Windows Form Designer generated code "

Dim arrlbl As Label() = {lbl0, lbl1, lbl2, lbl3}

Private Sub Form1_Load(...)
Dim i As Integer
For i = 0 To arrlbl.Length - 1 : arrlbl(i).Text = "test" : Next
...
---this not working
----------------------------------------------------------------

Dim arrlbl As Label()

Private Sub Form1_Load(...)
arrlbl = new label() {lbl0, lbl1, lbl2, lbl3}
'...
Armin

Nov 21 '05 #4
OK. Thanks very much. Now I get it. I know I have done this before. I
just couldn't find my old code.

Thanks again,
Rich

"Armin Zingler" wrote:
"Rich" <Ri**@discussio ns.microsoft.co m> schrieb
The following code snipet won't run if I initialize my global label
array outside of a procedure - say Form_Load. If I initialize the
array inside Form_Load then it works. Is there a way to initialize
the label array outside of a procedure as I am doing? Or... (see
below this snipet)
---------------------------------------------------------------------------------
Public Class Form1
Inherits System.Windows. Forms.Form

" Windows Form Designer generated code "

Dim arrlbl As Label() = {lbl0, lbl1, lbl2, lbl3}

Private Sub Form1_Load(...)
Dim i As Integer
For i = 0 To arrlbl.Length - 1 : arrlbl(i).Text = "test" : Next
...
---this not working
----------------------------------------------------------------

Dim arrlbl As Label()

Private Sub Form1_Load(...)
arrlbl = new label() {lbl0, lbl1, lbl2, lbl3}
'...
Armin

Nov 21 '05 #5
> ~arrlbl = New Label(){lbl0, lbl1, lbl2, lbl3}~

Eek! "~" was kinda quotation mark. You hadn't to type them.
Do I Dim arrlbl? Dim inside of New( )? Appologize for my lack of brain
cells on this. May I request if you could show me a snippet of code what you are suggesting on how to declare and initialize my global label array?
No, I meant you should declare arrlbl at class level:

~
Private arrlbl() As Label
~

but initialize in New():

~
arrlbl = New Label() {lbl0, lbl1, lbl2, lbl3}
~
I'm not clear on your suggestion here.


I hope it's clear now. 8=]
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1399
by: Gurpreet Sachdeva | last post by:
I have two classes; a.py --> #!/usr/bin/python global test test ='' class a(b): def __init__(self,test): print test
4
3276
by: James E Koehler | last post by:
I can't get the WHILE statement to work in MySQL. The version of MySQL that I am using is: Ver 12.16 Distrib 4.0.6-gamma, for Win95/Win98 (i32) running on Windows MX. Here is the relevant section from the manual: 20.1.9.7 WHILE Statement
10
9095
by: dof | last post by:
I'm trying the following and having problems. I get errors on the array declaration lines. Something about an array must have at least one element. Thanks in advance. D #include stuff .... const enum ENUM_LIST {A = 0, B, C, D, E, ENUM_LIST_MAX}; RWCString MESSAGES; <--------------------- MESSAGES = "MESSAGE_A";
3
539
by: Suhail Salman | last post by:
Dear All, i got the following error message in an applications that opens 13 threads and all of them calling a stored procedure which retreieves data from SQLServer and fills them to a table the error appears at the following statment sqlda.Fill(dtMessages); During an infinit loopp
4
2093
by: Bass Pro | last post by:
Hi, I am creating textbox, radiobuttonlist and checkboxlist dynamically depending on data from a table. It is a questionnaire. I add the control on a Panel control during the 1st load_page event. Each question is displayed and answered, then result written to a SQL table. Then the next question is read from a table and displayed using the load_page event again. The questions display and function perfectly. The user anwers the question...
8
7521
by: SM | last post by:
I've always wonder if there is diference when declaring and initializing a varible inside/outside a loop. What's a better practice? Declaring and initializing variables inside a loop routine, like this: for(var i=0; i<list; i++) { var name = list; }
2
3158
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button then the calender gone actually i want if i click outside off the calender then it should me removed ..How kan i do this ... Pls inform me as early as possible .. I am waiting for ur quick replay ...Here i attached the source code .... <!DOCTYPE...
6
4379
by: Jai Prabhu | last post by:
Hi All, Consider the following piece of code: void func (void) { static unsigned char arr = "\x00\xAA\xBB"; fprintf (stderr, "0x%x\n", arr); fprintf (stderr, "0x%x\n", arr);
2
2640
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to update the information which is stored in a SQL database. In testing we noticed that the form was updating correctly but the update mechanism was also updating the first record of the table in the sql database every time. No error messages are on...
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10439
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7541
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.