473,320 Members | 2,110 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,320 software developers and data experts.

Error: Reference to a non-shared member | Constructor; Pass Variable

Hello,

I've been trying implement Constructor method in passing variable between two forms.

Just a rough user interface guide - issue Invoice. User would type in all the Customer Name, Document Number. Once he reached Item Details, a Child Form would pop-up for the User to select/search the Invoice's Item; Once selected, the selected item would showed in the primary Form.

What I had tried is, the Constructor method worked perfectly when it is self-contain in a new project, yet to be implement in my application.

But when I implemented, there is an error:
Reference to a non-shared member requires an object reference.
The error highlighted at my main (menu) form - where one of the menu selection referred to the Invoice Form.

Constructor Code at the Invoice Form
Expand|Select|Wrap|Line Numbers
  1.     Public Sub New(ByVal strTextBox As String)
  2.  
  3.         InitializeComponent()
  4.  
  5.         txtPartNumber.Text = strTextBox
  6.  
  7.     End Sub
Part of the Constructor Code at the Child Form:
Expand|Select|Wrap|Line Numbers
  1.     Private Sub passVariableNextForm()
  2.  
  3.         Dim frm As NewStockTransaction = New NewStockTransaction(selectedBox.Text)
  4.  
  5.         frm.Show()
  6.  
  7.         Me.Dispose()
  8.  
  9.     End Sub
  10.  
  11.     Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
  12.  
  13.         passVariableNextForm()
  14.  
  15.     End Sub
Both Form have Import References:
Imports System.Data
Imports System.Data.SqlClient
Mar 13 '10 #1
6 2459
tlhintoq
3,525 Expert 2GB
I have xxx, then do yyy then zzz happens. Here's my code ...
Ok. You know what you have.
What you don't have is a question. Nobody here knows why you posted this since you haven't asked anything. What is it you are looking for?
I recommend you read the FAQ about How to ask a good question so the volunteers will be able to help you.
Mar 13 '10 #2
Sorry, I did not make myself clear.

The question is simply, how to fix the error.
Reference to a non-shared member requires an object reference.
The error highlighted at my main (menu) form - where one of the menu selection referred to the Invoice Form.

Other question are:
i) Would it be logical/appropriate/effective/efficient to use this method to pass variable? If not, please suggest.

Note: I'm a starter in the programming world especially vb.net. If did offence anyone, I mean no harm and sorry about that.
Mar 13 '10 #3
tlhintoq
3,525 Expert 2GB
The child form really doesn't need to know anything from the parent, does it?
Shouldn't it just collect all the information *it*is responsible for then pass it back up to whomever called it?

Little black boxes of code that know nothing outside themselves. That's how it tends to work best.

Have your child (ItemDetails) form open... collect all of its data... then raise an event when it is done. The arguments of that event can be a class you create with all the details. An ItemDetailsArgs class if you like.

This keeps your child (details) form a bit more generic. It can be used to gather information... display information... update then resend information...

If you make a List<t> of ItemDetails then you can associate 50 items to one person...

We love re-usability and not restricting a chunk of code to only one purpose if you don't have to.
Mar 13 '10 #4
Hi tlhintoq,

Thanks for the advise.

I tried your advise - not really sure whether my solution is what you suggested.

Here what I understand,
You had suggested that I create an Class (named SelectItemDetails) to hold get the selected data from Child and update the data of the Primary Form.

Below are my codes:

Part of Child Form
Expand|Select|Wrap|Line Numbers
  1.     Private Sub passVariableNextForm()
  2.  
  3.         Dim SelectedItemDetails As New SelectedItemDetails
  4.  
  5.         NewStockTransaction.Enabled = True
  6.  
  7.         SelectedItemDetails.GetSelectedID(selectedBox.Text)
  8.  
  9.         Me.Dispose()
  10.  
  11.     End Sub
  12.  
  13.     Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
  14.  
  15.         passVariableNextForm()
  16.  
  17.     End Sub

New Class
Expand|Select|Wrap|Line Numbers
  1. Public Class SelectedItemDetails
  2.  
  3.     Public Sub GetSelectedID(ByVal SelectedItemID As String)
  4.  
  5.         NewStockTransaction.txtPartNumber.Text = SelectedItemID
  6.  
  7.     End Sub
  8.  
  9. End Class

Result:
It works!

Any comment?
Mar 13 '10 #5
tlhintoq
3,525 Expert 2GB
Result:
It works!
It works! Congratulations!
Mar 13 '10 #6
Thanks a lot for your help.
Mar 13 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Matthew Del Buono | last post by:
Don't try to solve the problem. I've found a way -- around or fixing it. I'm just curious as to whether this is Microsoft's problem in their compiler or if there's a standard saying this is to be...
5
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
7
by: Sean | last post by:
Can someone help me see why the following "operator=" overloading doesn't work under g++? and the error message is copied here. I see no reason the compiler complain this. Thanks, $ g++...
16
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 -...
9
by: CQ | last post by:
Hi everyone, I get the following error when compiling my code: error: invalid initialization of non-const reference of type 'Vertex&' from a temporary of type 'int' The implementation of...
4
by: dancer | last post by:
I get this error if an item in a radiobutton list is not chosen when filling in a form.. I added a RequiredFieldValidator, but I still get the message. Object reference not set to an instance of...
1
by: Alexander Higgins | last post by:
>>Thanks for the response.... Point Taken but this is not the case. Thus, if a person writes a text file on her or his computer and does not use UNICODE to save it, the current code page is...
5
by: George2 | last post by:
Hello everyone, This is my understanding of non-const reference, const reference and their relationships with lvalue/rvalue. Please help to review whether it is correct and feel free to...
5
by: Daniel Oberhoff | last post by:
Hi, Can someone more proficient in the details of the c++ type system please tell me how I can instantiate the for constesses of references that I think should be possible: 1. non-constant...
3
by: Lance Wynn | last post by:
Hello, I am receiving this error when trying to instantiate a webservice component. I have 2 development machines, both are XP sp2 with VS 2008 installed. On one machine, the code works fine. On...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.