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 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
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
"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
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
> ~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=] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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
|
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";
|
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
|
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...
| |
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;
}
|
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...
|
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);
|
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...
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |