473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Easy question: How to access control on a form ?

Eh
I have a project containing a WindowsForm and a module and
need to set the text property on a label control on the
form from the module.

here's the code (from MS Framework .Net Doc):
Dim test as Form2 = Form2.ActiveForm
Dim i As Integer
For i = 0 To test.Controls.Count - 1
MsgBox(test.Controls(i).Name)
Next
When I run this I get a System.NullReferenceException:
Object reference not set to an instance of an object

Any ideas anyone ?
Nov 20 '05 #1
3 1476
Cor
Hi,
I don't know what you are doing,
But I asume that the error will not show when you change
Dim test as Form2 = Form2.ActiveForm in

Dim test as New Form2
If the result is what you want, that I cannot see with so few code.

I hope this helps a little bit.
Cor
Nov 20 '05 #2
eh
The New statement creates a new instance of the form which
I do not want to do. The form is loaded before the call
to function in the module so I need to be able to set the
test object reference to an instance by getting the form
handle which the .ActiveForm property should be doing but
for some reason it isn't.
-----Original Message-----
Hi,
I don't know what you are doing,
But I asume that the error will not show when you change
Dim test as Form2 = Form2.ActiveForm inDim test as New Form2
If the result is what you want, that I cannot see with so

few code.
I hope this helps a little bit.
Cor
.

Nov 20 '05 #3
"Eh" <eh@he.eh> schrieb
I have a project containing a WindowsForm and a module and
need to set the text property on a label control on the
form from the module.
Why do you need the module?
here's the code (from MS Framework .Net Doc):
Dim test as Form2 = Form2.ActiveForm
Dim i As Integer
For i = 0 To test.Controls.Count - 1
MsgBox(test.Controls(i).Name)
Next
When I run this I get a System.NullReferenceException:
Object reference not set to an instance of an object

Any ideas anyone ?


test is Nothing. If you want to access an object you need a reference. If
you don't have one you have to pass it, e.g. as an argument of the
procedure.
--
Armin

Nov 20 '05 #4

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

Similar topics

7
by: vindaloo1 | last post by:
I'm using Access 2000 and I have a main form and a subform. When a control on the subform is updated I am trying to update a control on the mainform. But instead of updating the control on the...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
7
by: Trev | last post by:
Hey, I just want to know (i know i should know this) how can i show up another form? I have 2 forms and the first one has a button on it that when i click the button i want the second form to...
10
by: patang | last post by:
Question 1 I have two forms, let say Form1 and Form2. There is datetimepicker control on Form2. In the Load Event of Form2 I have set the default value of datetimepicker control to NOW. So as...
2
by: kaosyeti | last post by:
it may be because i'm having a BAD day but i can't come up with an easy way to do this... i want to have a form for recording one department's yearly forecasted data. what i have is a column of...
7
by: jimi_xyz | last post by:
I am kind of new to C sharp; I have a quick question I have multiple text boxes 12 of them to be exact. What I want to do is fill them with values that are in a array of integers. The way I am...
0
by: Brian Cesafsky | last post by:
I am using framework 1.1 I have a user control and a web page. I want to set up properties on the user control, so I can access the text boxes on the user control when I am in the code behind...
34
by: Mathieu Trentesaux | last post by:
Hello I downloaded Office 2007 for this reason : It seems, once again, that it is impossible to save any modification done in a VBA library, from the main project in Access. The save button...
2
by: Crimson* | last post by:
I've got a table with an entry type as "OLE Object" in Access 2003. In the form that the table is linked to I want to insert an image (BMP) for each record. However, when I attempt to do so the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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...
0
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,...

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.