473,395 Members | 1,412 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,395 software developers and data experts.

How to use data from one form to others

I'm trying to use this variable called Group that's created in my Login form to use in other form:
Expand|Select|Wrap|Line Numbers
  1. Public Class Login
  2.  
  3. Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
  4.         Dim conn As New SqlClient.SqlConnection
  5.         Dim command As New SqlClient.SqlCommand
  6.         Dim adaptor As New SqlClient.SqlDataAdapter
  7.         Dim dataset As New DataSet
  8.         Dim Group As String
  9.         Dim count As Integer
  10.         Dim frm As SwitchBoard
  11.  
  12. If count > 0 Then
  13.             Me.Hide()
  14.  
  15.             Group = dataset.Tables(0).Rows(0).Item("Usergroup")
  16.             frm = New SwitchBoard(Group)
  17.             frm.Show()
  18.         Else
  19.             MsgBox("Wrong username or password")
  20.         End If
  21.  
I managed to pass it to my switchboard form:
Expand|Select|Wrap|Line Numbers
  1. Public Class SwitchBoard
  2.  
  3.     Public Group As String
  4.  
  5.     Public Sub New(ByVal theGroup As String)
  6.         InitializeComponent()
  7.  
  8.         Group = theGroup
  9.     End Sub
  10.  
  11.     Private Sub btnCust_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCust.Click
  12.         'Dim frm As CustomerForm = New CustomerForm()
  13.  
  14.         'frm.Show()
  15.         CustomerForm.Show()
  16.     End Sub
to use as this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub SwitchBoard_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.         StatusStrip1.Items.Add("Logged in as: " + Group)
  3.  
  4.         If Group = "user" Then
  5.             btnCreate.Enabled = False
  6.         End If
  7.     End Sub
and I tried typing the same thing in another form called CustomerForm:
Expand|Select|Wrap|Line Numbers
  1. Public Class CustomerForm
  2.     Private theBinding As BindingSource
  3.     Private objCustomer As CustomerTier
  4.  
  5.     Public Group As String
  6.  
  7.     Public Sub New(ByVal theGroup As String)
  8.         InitializeComponent()
  9.  
  10.         Group = theGroup
  11.     End Sub

and I get an error in my switchboard form where it says "CustomerForm.Show()" saying "reference to a non-shared member requires an object reference:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnCust_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCust.Click
  2.         'Dim frm As CustomerForm = New CustomerForm()
  3.  
  4.         'frm.Show()
  5.         CustomerForm.Show()
  6.     End Sub
Dec 2 '10 #1
1 1014
Within a class a public object (variable, function sub whatever) needs to be instantiated (in VB this means created with NEW.

It looks like you tried this but forgot that you overrode the NEW sub to have a parameter (Group)

Instantiate the class

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnCust_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCust.Click
  2.     ''Dim frm As CustomerForm = New CustomerForm() 
  3.  
  4.     ''frm.Show() 
  5.     'CustomerForm.Show()
  6.  
  7.     Dim frm As New CustomerForm(Group)
  8.     frm.show()
  9.  
  10. End Sub
  11.  
OR
Expand|Select|Wrap|Line Numbers
  1. Private Sub btCust_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btCust.Click
  2.         Dim frm As CustomerForm = New CustomerForm(Group)
  3.  
  4.         frm.Show()
  5.  
  6.     End Sub 
  7.  
Dec 4 '10 #2

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

Similar topics

0
by: James | last post by:
Hello, I have about 15 master catalogs, or master tables, of information that my application uses. The data form wizard is fine because most of them have between 20 and 200 items in them. ...
3
by: David C. Allen | last post by:
I am following thru the examples in the book I am studying for my MCSD. This is the web applications book. One example is to use the data form wizard to create a simple data form on the...
1
by: Zal | last post by:
hi, i would like someone to confirm something for me, i have the trail edition of vs.net2003 which i will upgrade to the standard edition,once i get it through the post. ive been looking at a...
1
by: AndrwChau | last post by:
I just want to know how many user are use the Data Form wizard to generate the input form. Is most of programmer use the wizard to generate the input form or they are create one by themself. Is...
6
by: Bob | last post by:
I've located instruction as to how to add the Data Form Wizard into a VB.NET 2005 project at this location. ...
1
by: Avi G | last post by:
Hi, i use VS2005 Pro and i can't find the "Data form Wizard" when i try to include it to my form, where can i find it , or maybe there is something else that do the same thing? i need to bind a...
6
by: shivavrata | last post by:
Hi All, I want to transfer the data form webpage to any other own application which is running in backend.How i develop this web page. which technology is good for this or any particular protocol...
3
by: nkoriginal | last post by:
Hello: I tried an script for keep my data form after reload page, but I've some errors. In this momento I runnung my own browser because we've an intranet. And for security reason, our page...
1
by: Wan | last post by:
According to MSN instruction found here http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsin... on how to add a Data Form Wizard in .Net 2005. However, after several tries I...
3
by: Saucer Man | last post by:
....in Visual Basic.net 2008 Express? -- Thanks!
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.