473,746 Members | 2,661 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 2332
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
1396
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
3274
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
9091
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
7519
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
3156
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
4375
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
2636
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
8974
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
8800
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9285
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
9218
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...
0
8229
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6060
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
4586
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2199
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.