473,804 Members | 3,271 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Object references in different form classes

Dan
I'm trying to write a Windows application that obtains
information from a web service. I can access the web
service successfully, but I can't access the object
returned by the web service in different forms.

My application is something like this:

MainForm.vb:

Public Class MainForm
Inherits System.Windows. Forms.Form
#Region " Windows Form Designer generated code "

Public Sub GetResultCollec tion( ...
Dim WebService As New ThisWebService
Dim WebServiceResul t As New ThisWebResult
Dim WebServiceEleme nt As New ThisResultEleme nt
WebServiceResul t = WebService.getR esult("paramete r")
Dim ResultForm As New myResultForm
ResultForm.Show ()
End Sub
End Class

myResultForm.vb :

Public Class myResultForm
Inherits System.Windows. Forms.Form
#Region " Windows Form Designer generated code "

Public Sub ShowResults( ...
For Each WebServiceEleme nt In
WebServiceResul t.resultElement s
myResultForm.Te xtBox.Text =
WebServiceEleme nt.textfield
End Sub
End Class

Note that objects declared in MainForm are accessed in
myResultForm. And that is the problem I'm having.

I can't figure out how to make VB .NET recognize the
objects in myResultForm.

Note ... this is a "scope of variables" problem. The web
service calls all work and if I keep everything in one
form, everything works great. But I just can't get the
objects in the first form to be "seen" in the second one.
Jul 21 '05 #1
4 2070
a
1. Give Form2 a public property (myForm1) of type Form1

Dim frm as Form1
Public Property myForm1 as Form1
..
..
..
End Property
2. Set the myForm1 property of Form2 before calling Show

Dim f as new Form2
f.myForm1 = me
f.show
3. Make sure the variables you are trying to hit on Form1 are Public

( Public WebService As New ThisWebService , not Dim [which defaults to
Private] )
4. Access them on Form2 by calling

myForm1.Variabl eName.
There are a few other ways to do this, but this one will work.

hth
Kevin


"Dan" <se*******@msn. com> wrote in message
news:01******** *************** *****@phx.gbl.. .
I'm trying to write a Windows application that obtains
information from a web service. I can access the web
service successfully, but I can't access the object
returned by the web service in different forms.

My application is something like this:

MainForm.vb:

Public Class MainForm
Inherits System.Windows. Forms.Form
#Region " Windows Form Designer generated code "

Public Sub GetResultCollec tion( ...
Dim WebService As New ThisWebService
Dim WebServiceResul t As New ThisWebResult
Dim WebServiceEleme nt As New ThisResultEleme nt
WebServiceResul t = WebService.getR esult("paramete r")
Dim ResultForm As New myResultForm
ResultForm.Show ()
End Sub
End Class

myResultForm.vb :

Public Class myResultForm
Inherits System.Windows. Forms.Form
#Region " Windows Form Designer generated code "

Public Sub ShowResults( ...
For Each WebServiceEleme nt In
WebServiceResul t.resultElement s
myResultForm.Te xtBox.Text =
WebServiceEleme nt.textfield
End Sub
End Class

Note that objects declared in MainForm are accessed in
myResultForm. And that is the problem I'm having.

I can't figure out how to make VB .NET recognize the
objects in myResultForm.

Note ... this is a "scope of variables" problem. The web
service calls all work and if I keep everything in one
form, everything works great. But I just can't get the
objects in the first form to be "seen" in the second one.

Jul 21 '05 #2
>-----Original Message-----
1. Give Form2 a public property
Snip<<


Very Good! This gave me the clue I needed to move
forward. But I believe there are a few bugs in your code
that need to be corrected, so I'm posting the work I did
for the benefit of any future programmers who might be
this answer.

I reworked the example to make it more simple. Since web
services had nothing to do with it, the example below are
simple standard Windows forms.

Here's what worked for me. Please let me know if this can
be improved.

Form1.vb:

Public Class Form1
Inherits System.Windows. Forms.Form
#Region " Windows Form Designer generated code "
Public o As Object
Public newform As New Form2
Private Sub Form1_Load(ByVa l sender As System.Object,
ByVal e As System.EventArg s) Handles MyBase.Load
o = 12345
MsgBox("Form1: " & o)
newform.myForm1 = Me
newform.Show()
End Sub
End Class

Form2.vb:

Public Class Form2
Inherits System.Windows. Forms.Form
'Bug 1 - the object is passed as a property, so it must
be declared in this form
Private MainForm As Form1
#Region " Windows Form Designer generated code "
Property myForm1() As Form1
'Bug 2 Properties must have Get and Set procedures
Get
End Get
Set(ByVal Value As Form1)
MainForm = Value
End Set
End Property
Private Sub Form2_Load(ByVa l sender As System.Object,
ByVal e As System.EventArg s) Handles MyBase.Load
'Bug 3 MainForm is the object that is set by the property
MsgBox("Form2: " & MainForm.o)
End Sub
End Class

Jul 21 '05 #3
I would also like to know what some of those "other
methods" are if you could post them.
Jul 21 '05 #4
Dan
By the way, I posted the "anonymous" messages above.

I consider this problem to be solved at this time.

(Although I would still appreciate seeing alternative
ideas if anyone has them.)

Dan
-----Original Message-----
I'm trying to write a Windows application that obtains
snip<<

Jul 21 '05 #5

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

Similar topics

12
1663
by: A-PK | last post by:
Anyone know how to breakdown every modules into different assemblies and refernces. Hence, to repair problematic module, only that particular module needed to be recompiled. or any place can get more information about assemblies & references
1
3978
by: Bo Xu | last post by:
Object of Combination By Bo Xu Introduction A combination of n things, taken s at a time, often referred as an s-combination out of n, is a way to select a subset of size s from a given set of size n. There are n!/(s!(n-s)!) ways to do this. Donald E. Knuth gives several methods (algorithms) to generate all the s-combinations in . In such procedure-oriented way, each s-combination is processed while it's being generated. In some
2
8893
by: films | last post by:
I understand the concept. Serialization of a class will add all the sub-objects of the class to the stream if there are also serializible. So say I have: class Author {
3
4237
by: Adam | last post by:
We have a web site that uses .vb for the web pages and .cs for a class module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does work with .NET 1.1. When trying to access a page that needs the class module I get an error on web site: Object reference not set to an instance of an object Here is where the error is:
5
2023
by: wpmccormick | last post by:
What is the cleanest way to gain access to object methods and properties across classes and files in the same namespace? Example: A form object frmForm in file frmForm.cs creates obj1 defined in file obj1.cs, which in turn creates obj2 and obj3 defined in obj2.cs and obj3.cs, respectively. What is the canonical way for frmForm to access obj2 and obj3? For obj3 to access frmForm?
14
2589
by: Jeroen | last post by:
Hi all, I've got a question about writing a library. Let me characterize that library by the following: * there is a class A which is available to the user * there is a class B that is used in severel 'underwater operations' * there is a list which stores objects of class B There are several issues I'm not sure about:
28
2190
by: Stef Mientki | last post by:
hello, I'm trying to build a simple functional simulator for JAL (a Pascal-like language for PICs). My first action is to translate the JAL code into Python code. The reason for this approach is that it simplifies the simulator very much. In this translation I want to keep the JAL-syntax as much as possible intact, so anyone who can read JAL, can also understand the Python syntax. One of the problems is the alias statement, assigning a...
32
2571
by: Joe | last post by:
I am just starting to use Object Oriented PHP coding, and I am seeing quite often the following (this example taken from a wiki): $wakka =& new Wakka($wakkaConfig); What exactly is the =&, and why is it different from = ?
275
12429
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
9705
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
10568
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
10323
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
10311
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
10074
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
9138
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
5516
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
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.