473,612 Members | 2,331 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reference a vb.net windows form control from a module sub

Hi

Relative vb.net newbie here... I have a Windows Form
application with a few subroutines in a separate module.
From one of the subroutines, I want to get the value of a
label or text box on the form. As it is, I get
a "Reference to a non-shared member requires an object
reference." error message. I can't seem to figure out how
to tell the subroutine how to find and use the labels or
text boxes on the form.

I'm sure there's an simple command I need to include,
just can't seem to find it, can someone help?

Mark D
LandAmerica Data Center - Dallas

Nov 20 '05 #1
2 7262
You have to create an instance of the form. In VB6, if you defined a form
in the IDE and called it "frmOne", you could access it from a module using
"frmOne.TextBox 1.Text" etc. In .NET, you should create an instance of the
form - Dim mvForm As New frmOne - then you can use "mvForm.TextBox 1.Text"

Here's a basic outline of a "standard" form and module project - just
remember to set the startup point to Sub Main, and not your form;

Module Blah
Public Sub Main()
Public myForm As New FrmOne
Application.Run (myForm)
End Sub
Public Sub MyCommonModuleS ub()
myForm.Button.T ext = "Code ran"
End Sub
End Module

Class FrmOne
/// Form initialisation, component code, etc ///
Private Sub Button_Click(pS ender As Object, pArgs As EventArgs) Handles
Button.Click()
MyCommonModuleS ub()
' button text on the form will now be changed
End Sub
End Class
_______________ _______________ ______
The Grim Reaper

"Mark D" <an*******@disc ussions.microso ft.com> wrote in message
news:2a******** *************** *****@phx.gbl.. .
Hi

Relative vb.net newbie here... I have a Windows Form
application with a few subroutines in a separate module.
From one of the subroutines, I want to get the value of a
label or text box on the form. As it is, I get
a "Reference to a non-shared member requires an object
reference." error message. I can't seem to figure out how
to tell the subroutine how to find and use the labels or
text boxes on the form.

I'm sure there's an simple command I need to include,
just can't seem to find it, can someone help?

Mark D
LandAmerica Data Center - Dallas

Nov 20 '05 #2
Do you know how to make a form variable visible to a module or class other
than the form?

If not this article should help:

http://msdn.microsoft.com/library/de...texmltopic.asp

--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com

"Mark D" <an*******@disc ussions.microso ft.com> wrote in message
news:2a******** *************** *****@phx.gbl.. .
Hi

Relative vb.net newbie here... I have a Windows Form
application with a few subroutines in a separate module.
From one of the subroutines, I want to get the value of a
label or text box on the form. As it is, I get
a "Reference to a non-shared member requires an object
reference." error message. I can't seem to figure out how
to tell the subroutine how to find and use the labels or
text boxes on the form.

I'm sure there's an simple command I need to include,
just can't seem to find it, can someone help?

Mark D
LandAmerica Data Center - Dallas

Nov 20 '05 #3

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

Similar topics

1
288
by: JenHu | last post by:
Hi all, I have a checkbox cboxProcessRet in my VB.NET windows application's main.vb as following, so how can I use reference this checkbox in moduleA.vb? I want to use it in a function in the module, it said cboxProcessRet is not declared (If cboxProcessRet.Checked = True ) ------------------------------------------------------------------------
2
2578
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a good while and I'm getting really frustrated now! My problem is this - my custom controls periodically disappear from my
16
2301
by: Paul S. Natanson | last post by:
What is a Null Reference error and how do I fix it? My newly installed VB.Net2003 gives me a "Microsoft Development Environment" error message box EVERY time I try to run/start ANY project - even very simple ones. The error says: "An unhandled exception of type 'System.NullReferenceException' occurred in
23
1276
by: Carlos | last post by:
Before in VB 6 I used to reference for examplea progressbar1 doin the following Form1.ProgressBar1.val =1 Now how do I refrence a control for a module if the control is in a different form Thanks
2
2205
by: Jeff | last post by:
I'm getting an Object Reference error before I even run my app, and I'm not sure where to look to find the cause. I'd appreciate your help. When I open my Windows Application project, the following Microsoft Development Environment error message displays: "Object reference not set to an instance of an object." Then when I access the design view of one of my forms, the controls on
2
10700
by: JenHu | last post by:
Hi all, I have a checkbox cboxProcessRet in my VB.NET windows application's main.vb as following, so how can I use reference this checkbox in moduleA.vb? I want to use it in a function in the module, it said cboxProcessRet is not declared (If cboxProcessRet.Checked = True ) ------------------------------------------------------------------------
1
8357
by: Don | last post by:
I'm getting the following exception displayed in the task list at design time for my project: "Code generation for property 'Controls' failed. Error was: 'Object reference not set to an instance of an object.'" I've traced the problem to a custom control I created that inherits from Inherits System.Windows.Forms.TextBox. In this custom control, I have two constructors. I'm not sure why I created the second constructor -- it was so...
3
5327
by: Sarang | last post by:
Hi, I have this code that makes the form as an MDIChild: chartWindowController.GetForm().MdiParent = _expertTradeMainFrm; chartWindowController.GetForm().WindowState =FormWindowState.Normal; chartWindowController.GetForm().Show();
4
1269
by: zswanson | last post by:
Hi all, I have a sub-form that has 196 controls on it. The name for each control is a nubmer from 1 to 196. I'd like to generate a loop that assigns a value to each control. Is there a way to reference a control through a variable? This is what I have now, without trying to attempt to reference through string: (arrLayoutArray is a 28 row by 7 columns array that was generated in a seperate module)
0
8173
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
8617
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
8568
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
8254
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
8422
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
7044
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...
1
6082
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
4047
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...
1
2555
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.