473,799 Members | 2,907 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing Procedure on another form

Hi,
I am having trouble with a form that I have loaded trying to access a
procedure on the main form.

The trouble seems to be that a Global Array that is declare in a Module is
producing a Nullreference error when I try to call the procedure on the main
form.

ie.
Module 1 contains
Public TXBuff(100) As Byte

Public mainform As Form1

The second form contains code

TXBuff(0) = 2

TXBuff(1) = 13

TXBuff(2) = 6

mainform.Send(3 )

And the main form contains code

Public Sub Send(ByVal nbytes As Integer)

RXBytes = 0

DisplayTXBytes( nbytes)

SerialConnectio n.Write(TXBuff, 0, nbytes)

ReplyTimer.Enab led = True

End Sub

The exact error is ...

An unhandled exception of type 'System.NullRef erenceException ' occurred in
Config Utility Source.exe

Additional information: Object reference not set to an instance of an
object.

Thanks in advance for any help
Nov 21 '05 #1
7 2011

David wrote:
Hi,
I am having trouble with a form that I have loaded trying to access a
procedure on the main form.

The trouble seems to be that a Global Array that is declare in a Module is producing a Nullreference error when I try to call the procedure on the main form.

ie.
Module 1 contains
Public TXBuff(100) As Byte


This *declares* TXBuff to be a variable of type 'array of 100 Byte',
but doesn't actually *define* such an array. Remember, in VB.NET Arrays
are now reference types, not value types (ie they act more like Objects
than, say, Integers). Therefore you must actually create an array of
100 Byte for this variable to reference, otherwise when you refer to
TXBuff(0) you are using a null reference.

The simple fix is to change

Public TXBuff(100) As Byte

to

Public TXBuff(100) As Byte = New Byte(100) {}

This will mean that at initialisation time, a new array of 100 Bytes
will be created, and TXBuff set to point to it.

The changes to arrays are one of the key language change areas
referenced in the MSDN/VStudio help, I think.

--
Larry Lard
Replies to group please

Nov 21 '05 #2
Larry,

Thanks for the response.

When I place this in the Module, the following error occurs.

"Explicit Initialization is not permitted for arrays declared with explicit
bounds"
"Larry Lard" <la*******@hotm ail.com> wrote in message
news:11******** **************@ l41g2000cwc.goo glegroups.com.. .

David wrote:
Hi,
I am having trouble with a form that I have loaded trying to access a
procedure on the main form.

The trouble seems to be that a Global Array that is declare in a

Module is
producing a Nullreference error when I try to call the procedure on

the main
form.

ie.
Module 1 contains
Public TXBuff(100) As Byte


This *declares* TXBuff to be a variable of type 'array of 100 Byte',
but doesn't actually *define* such an array. Remember, in VB.NET Arrays
are now reference types, not value types (ie they act more like Objects
than, say, Integers). Therefore you must actually create an array of
100 Byte for this variable to reference, otherwise when you refer to
TXBuff(0) you are using a null reference.

The simple fix is to change

Public TXBuff(100) As Byte

to

Public TXBuff(100) As Byte = New Byte(100) {}

This will mean that at initialisation time, a new array of 100 Bytes
will be created, and TXBuff set to point to it.

The changes to arrays are one of the key language change areas
referenced in the MSDN/VStudio help, I think.

--
Larry Lard
Replies to group please

Nov 21 '05 #3

David wrote:
Larry,

Thanks for the response.

When I place this in the Module, the following error occurs.

"Explicit Initialization is not permitted for arrays declared with explicit bounds"
Sorry my mistake, you want

Public TXBuff() As Byte = New Byte(100) {}


"Larry Lard" <la*******@hotm ail.com> wrote in message
news:11******** **************@ l41g2000cwc.goo glegroups.com.. .

David wrote:
Hi,
I am having trouble with a form that I have loaded trying to access a procedure on the main form.

The trouble seems to be that a Global Array that is declare in a

Module is
producing a Nullreference error when I try to call the procedure
on the main
form.

ie.
Module 1 contains
Public TXBuff(100) As Byte


This *declares* TXBuff to be a variable of type 'array of 100 Byte', but doesn't actually *define* such an array. Remember, in VB.NET Arrays are now reference types, not value types (ie they act more like Objects than, say, Integers). Therefore you must actually create an array of 100 Byte for this variable to reference, otherwise when you refer to TXBuff(0) you are using a null reference.

The simple fix is to change

Public TXBuff(100) As Byte

to

Public TXBuff(100) As Byte = New Byte(100) {}

This will mean that at initialisation time, a new array of 100 Bytes will be created, and TXBuff set to point to it.

The changes to arrays are one of the key language change areas
referenced in the MSDN/VStudio help, I think.

--
Larry Lard
Replies to group please


Nov 21 '05 #4
Larry,

I made the changes and now do not get the explicit initialization error but
still get the null reference error.

If I call the Send routine from the main form instaed of from the second
form, it works fine. The nullreference error only occurs when I try to call
the send routine from another form that I have opened.
"Larry Lard" <la*******@hotm ail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .

David wrote:
Larry,

Thanks for the response.

When I place this in the Module, the following error occurs.

"Explicit Initialization is not permitted for arrays declared with

explicit
bounds"


Sorry my mistake, you want

Public TXBuff() As Byte = New Byte(100) {}


"Larry Lard" <la*******@hotm ail.com> wrote in message
news:11******** **************@ l41g2000cwc.goo glegroups.com.. .

David wrote:
> Hi,
> I am having trouble with a form that I have loaded trying to access a > procedure on the main form.
>
> The trouble seems to be that a Global Array that is declare in a
Module is
> producing a Nullreference error when I try to call the procedure on the main
> form.
>
> ie.
> Module 1 contains
> Public TXBuff(100) As Byte

This *declares* TXBuff to be a variable of type 'array of 100 Byte', but doesn't actually *define* such an array. Remember, in VB.NET Arrays are now reference types, not value types (ie they act more like Objects than, say, Integers). Therefore you must actually create an array of 100 Byte for this variable to reference, otherwise when you refer to TXBuff(0) you are using a null reference.

The simple fix is to change

Public TXBuff(100) As Byte

to

Public TXBuff(100) As Byte = New Byte(100) {}

This will mean that at initialisation time, a new array of 100 Bytes will be created, and TXBuff set to point to it.

The changes to arrays are one of the key language change areas
referenced in the MSDN/VStudio help, I think.

--
Larry Lard
Replies to group please

Nov 21 '05 #5
Larry,

I think the error may actually be in the way I am trying to call the main
form.
If I stop in debug mode and cursor over the call, the dialog shows "mainform
= nothing"

"Larry Lard" <la*******@hotm ail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .

David wrote:
Larry,

Thanks for the response.

When I place this in the Module, the following error occurs.

"Explicit Initialization is not permitted for arrays declared with

explicit
bounds"


Sorry my mistake, you want

Public TXBuff() As Byte = New Byte(100) {}


"Larry Lard" <la*******@hotm ail.com> wrote in message
news:11******** **************@ l41g2000cwc.goo glegroups.com.. .

David wrote:
> Hi,
> I am having trouble with a form that I have loaded trying to access a > procedure on the main form.
>
> The trouble seems to be that a Global Array that is declare in a
Module is
> producing a Nullreference error when I try to call the procedure on the main
> form.
>
> ie.
> Module 1 contains
> Public TXBuff(100) As Byte

This *declares* TXBuff to be a variable of type 'array of 100 Byte', but doesn't actually *define* such an array. Remember, in VB.NET Arrays are now reference types, not value types (ie they act more like Objects than, say, Integers). Therefore you must actually create an array of 100 Byte for this variable to reference, otherwise when you refer to TXBuff(0) you are using a null reference.

The simple fix is to change

Public TXBuff(100) As Byte

to

Public TXBuff(100) As Byte = New Byte(100) {}

This will mean that at initialisation time, a new array of 100 Bytes will be created, and TXBuff set to point to it.

The changes to arrays are one of the key language change areas
referenced in the MSDN/VStudio help, I think.

--
Larry Lard
Replies to group please

Nov 21 '05 #6
You have declared

Public mainform As Form1

but remembering that Forms are *objects*, it sounds like you haven't
explicitly set mainform to the instance of your Form1. If there is only
one Form1 in your app, you can get away with just putting

mainform = Me

in the Form_Load of Form1. Then when other parts of the code use the
mainform variable it will refer to the Form1 that is loaded.

Nov 21 '05 #7
Larry,

Thanks for the help with what must be very fundamental issues for you.

setting mainform = me has fixed the problem.


"Larry Lard" <la*******@hotm ail.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
You have declared

Public mainform As Form1

but remembering that Forms are *objects*, it sounds like you haven't
explicitly set mainform to the instance of your Form1. If there is only
one Form1 in your app, you can get away with just putting

mainform = Me

in the Form_Load of Form1. Then when other parts of the code use the
mainform variable it will refer to the Form1 that is loaded.

Nov 21 '05 #8

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

Similar topics

4
1786
by: stjulian | last post by:
I have a stored procedure that is supposed to 1. Increment a counter in Table A via a transaction 2. Use this value as the primary key to add in an address to customers Table B (Referenced as a "DECLARE @CustomerID INT" just after the AS clause) 3. Return the primary key. This works perfectly when being called from Query Analyzer supplying values in an EXEC line, however, accessing it from .ASP (IIS 5.0 on Win2K), the
1
1490
by: - | last post by:
this is one way of creating a stored procedure in mysql: CREATE PROCEDURE some_procedure (IN value1, OUT value2) BEGIN SELECT ... INTO value2 FROM .... END// and if called from another procedure, i can access the variable this way:
6
2747
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is called "form1", and I have selects called "PORTA", "PORTB" ... etc...
8
4457
by: Christopher Weaver | last post by:
I'm having trouble accessing the value of an output parameter of a stored procedure. The SP looks like this: SET TERM ^ ; CREATE PROCEDURE SP_NEW_TASK RETURNS ( "uidTask" INTEGER) AS begin
8
3561
by: Mike Caputo | last post by:
In VB.NET, need to be able to access certain properties on my main form from other forms. These are properties that may be changed by the user, so I have to be able to get to them throughout the application. How can I access the current instance of a specific Form object? For example: Class frmOne ....... Public Readonly Property XYZ() as String Get
5
1947
by: RSH | last post by:
I havent been able to set a property from another class with out getting some sort of error. Can someone please tell me what I'm doing wrong here? Public Class Form1
6
3683
by: Bob Alston | last post by:
I am looking for Access reporting add-in that would be easy to use by end users. My key focus is on selection criteria. I am very happy with the Access report writer capabilities. As far as development of reports, it is certainly fine in my book. But for end-users, with little experience or training, it would be nice to have an easy way to handle various selection criteria, perhaps with relatively stock reports. I see easy to use by...
3
2026
by: Kurtulus | last post by:
Hi; I have problem for very long time. I have one mdiparent form and several mdichild form. I have tried to change one control on the mdi parent form form anther one. However I have encountered an error which is "An unhandled exception of type 'System.NullReferenceException' occurred in .....exe Additional information: Object reference not set to an instance of an object." Can you tell me what the solution and problem is? Thank you for...
7
9717
by: Siv | last post by:
Hi, I have a stored procedure that I want to execute and then wait in a loop showing a timer whilst it completes and then carry on once I get notification that it has completed. The main reason for this being to stop the user thinking the application has frozen when in fact it is just waiting for a long SP to complete. Another reason for doing it like this is that I also have had a problem in the past where the SP takes longer than the...
0
9685
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
9538
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,...
0
10473
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
10249
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...
0
9068
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
6804
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
5461
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...
0
5584
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4138
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.