i have 3 forms
Public Class Form1
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim frm As New Form2
frm.Show(Me)
End Sub
Private _test As String
Friend Property test() As String
Get
Return _test
End Get
Set(ByVal value As String)
_test = value
End Set
End Property
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
_test = "hallo"
End Sub
End Class
Public Class Form2
Private _test As String
Friend Property test() As String
Get
Return _test
End Get
Set(ByVal value As String)
_test = value
End Set
End Property
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim frm As New Form3
frm.Show(Me)
End Sub
Private Sub Form2_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
_test = "hallo"
End Sub
End Class
Public Class Form3
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
MsgBox(Form1.te st)
MsgBox(Form2.te st)
End Sub
End Class
why gives pressing the button in form3 the value of form1 but not of form2
??
i wonder what i am missing
regards
Michel 9 1165
M. Posseth wrote: i have 3 forms
Public Class Form1 Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventAr gs) Handles Button1.Click Dim frm As New Form2 frm.Show(Me) End Sub Private _test As String Friend Property test() As String Get Return _test End Get Set(ByVal value As String) _test = value End Set End Property Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventAr gs) Handles MyBase.Load _test = "hallo" End Sub End Class
Public Class Form2 Private _test As String Friend Property test() As String Get Return _test End Get Set(ByVal value As String) _test = value End Set End Property Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventAr gs) Handles Button1.Click Dim frm As New Form3 frm.Show(Me) End Sub Private Sub Form2_Load(ByVa l sender As System.Object, ByVal e As System.EventAr gs) Handles MyBase.Load _test = "hallo" End Sub End Class
Public Class Form3
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventAr gs) Handles Button1.Click MsgBox(Form1.te st)
MsgBox(Form2.te st)
End Sub End Class
why gives pressing the button in form3 the value of form1 but not of form2 ??
i wonder what i am missing
regards
Michel
Maybe because you are loading Form1 as Form1, but you are instantiating
a new Form2 as frm as a private variable in Form1.
T
Nope....
just tried it this way , and it behaves exactly the same ,
Someone else willing to shine his light on this ??
Public Class Form1
Private _test As String
Friend Property test() As String
Get
Return _test
End Get
Set(ByVal value As String)
_test = value
End Set
End Property
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim formB As New Form2
formB.Show(Me)
End Sub
Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
_test = "hallo"
End Sub
End Class
Public Class Form2
Private _test As String
Friend Property test() As String
Get
Return _test
End Get
Set(ByVal value As String)
_test = value
End Set
End Property
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim formC As New Form3
formC.Show(Me)
End Sub
Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
_test = "hallo"
End Sub
End Class
Public Class Form3
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
MsgBox(Form1.te st)
MsgBox(Form2.te st)
End Sub
End Class
"tomb" wrote: M. Posseth wrote:
i have 3 forms
Public Class Form1 Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventAr gs) Handles Button1.Click Dim frm As New Form2 frm.Show(Me) End Sub Private _test As String Friend Property test() As String Get Return _test End Get Set(ByVal value As String) _test = value End Set End Property Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventAr gs) Handles MyBase.Load _test = "hallo" End Sub End Class
Public Class Form2 Private _test As String Friend Property test() As String Get Return _test End Get Set(ByVal value As String) _test = value End Set End Property Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventAr gs) Handles Button1.Click Dim frm As New Form3 frm.Show(Me) End Sub Private Sub Form2_Load(ByVa l sender As System.Object, ByVal e As System.EventAr gs) Handles MyBase.Load _test = "hallo" End Sub End Class
Public Class Form3
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventAr gs) Handles Button1.Click MsgBox(Form1.te st)
MsgBox(Form2.te st)
End Sub End Class
why gives pressing the button in form3 the value of form1 but not of form2 ??
i wonder what i am missing
regards
Michel Maybe because you are loading Form1 as Form1, but you are instantiating a new Form2 as frm as a private variable in Form1.
T
Aaarghh :-(
Do i feel stupid ...... Ofcourse now i see what you meant Tom
changed this in form1 and form3
Public Class Form1
Private _test As String
Friend Property test() As String
Get
Return _test
End Get
Set(ByVal value As String)
_test = value
End Set
End Property
Friend formB As Form2
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
formB = New Form2
formB.Show(Me)
End Sub
Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
_test = "hallo"
End Sub
End Class
Public Class Form3
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
MsgBox(Form1.te st)
MsgBox(Form1.fo rmB.test)
End Sub
End Class
and now it works as expected .....
i wil sit in a dark corner for a while and shame ;-|
"tomb" wrote: M. Posseth wrote:
i have 3 forms
Public Class Form1 Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventAr gs) Handles Button1.Click Dim frm As New Form2 frm.Show(Me) End Sub Private _test As String Friend Property test() As String Get Return _test End Get Set(ByVal value As String) _test = value End Set End Property Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventAr gs) Handles MyBase.Load _test = "hallo" End Sub End Class
Public Class Form2 Private _test As String Friend Property test() As String Get Return _test End Get Set(ByVal value As String) _test = value End Set End Property Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventAr gs) Handles Button1.Click Dim frm As New Form3 frm.Show(Me) End Sub Private Sub Form2_Load(ByVa l sender As System.Object, ByVal e As System.EventAr gs) Handles MyBase.Load _test = "hallo" End Sub End Class
Public Class Form3
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventAr gs) Handles Button1.Click MsgBox(Form1.te st)
MsgBox(Form2.te st)
End Sub End Class
why gives pressing the button in form3 the value of form1 but not of form2 ??
i wonder what i am missing
regards
Michel Maybe because you are loading Form1 as Form1, but you are instantiating a new Form2 as frm as a private variable in Form1.
T
I would thought that it is because Feyenoord has won the both major cups
from Holland and was the winer of the final from the playoffs from the
regular competition and was one of the 16 best teams in the Eurocompetition .
But that is another team, so you cannot make a fool of yourself by doing
something stupid as the management from Ajax did like sacking the trainer.
Have you somewhere
private form1 as form1
for sure you don't have that for form2 in my idea.
I find it strange it runs.
Just my thought,
Cor
"M. Posseth" <MP******@discu ssions.microsof t.com> schreef in bericht
news:EB******** *************** ***********@mic rosoft.com... Nope....
just tried it this way , and it behaves exactly the same ,
Someone else willing to shine his light on this ??
Public Class Form1 Private _test As String Friend Property test() As String Get Return _test End Get Set(ByVal value As String) _test = value End Set End Property
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click Dim formB As New Form2 formB.Show(Me) End Sub
Private Sub Form1_Load(ByVa l sender As Object, ByVal e As System.EventArg s) Handles Me.Load _test = "hallo" End Sub End Class
Public Class Form2 Private _test As String Friend Property test() As String Get Return _test End Get Set(ByVal value As String) _test = value End Set End Property
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click Dim formC As New Form3 formC.Show(Me) End Sub
Private Sub Form1_Load(ByVa l sender As Object, ByVal e As System.EventArg s) Handles Me.Load _test = "hallo" End Sub End Class
Public Class Form3
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click MsgBox(Form1.te st)
MsgBox(Form2.te st)
End Sub End Class "tomb" wrote:
M. Posseth wrote:
>i have 3 forms > >Public Class Form1 > Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As >System.EventAr gs) Handles Button1.Click > Dim frm As New Form2 > frm.Show(Me) > End Sub > Private _test As String > Friend Property test() As String > Get > Return _test > End Get > Set(ByVal value As String) > _test = value > End Set > End Property > Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As >System.EventAr gs) Handles MyBase.Load > _test = "hallo" > End Sub >End Class > >Public Class Form2 > Private _test As String > Friend Property test() As String > Get > Return _test > End Get > Set(ByVal value As String) > _test = value > End Set > End Property > Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As >System.EventAr gs) Handles Button1.Click > Dim frm As New Form3 > frm.Show(Me) > End Sub > Private Sub Form2_Load(ByVa l sender As System.Object, ByVal e As >System.EventAr gs) Handles MyBase.Load > _test = "hallo" > End Sub >End Class > >Public Class Form3 > > Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As >System.EventAr gs) Handles Button1.Click > MsgBox(Form1.te st) > > MsgBox(Form2.te st) > > > End Sub >End Class > > >why gives pressing the button in form3 the value of form1 but not of >form2 >?? > >i wonder what i am missing > >regards > >Michel > > > Maybe because you are loading Form1 as Form1, but you are instantiating a new Form2 as frm as a private variable in Form1.
T
"M. Posseth" <MP******@discu ssions.microsof t.com> wrote in message
news:0C******** *************** ***********@mic rosoft.com... Public Class Form3
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click MsgBox(Form1.te st) MsgBox(Form2.te st) End Sub End Class
why gives pressing the button in form3 the value of form1 but not of form2 ??
i wonder what i am missing
As tomb said in his post, the problem is likely that it creates a new
instance of Form2 while it manages to find the existing instance of Form1.
Pass an instance of Form1 and Form2 to Form3 instead. That way you can be
sure about what object you're really using.
First time I see someone using this feature (accessing forms by name instead
of using a variable). I wasn't to thrilled when I saw that MS had included
that in VB 2005. As you just showed it can lead to really weird behaviour.
VB.NET is a perfectly valid OO language, so why not use it as one instead of
trying to go back to old VB6 behaviour?
/claes
Sorry, still able to be manager from Ajax.
However did you try it already with the "owner" property.
Cor
"M. Posseth" <MP******@discu ssions.microsof t.com> schreef in bericht
news:ED******** *************** ***********@mic rosoft.com... Aaarghh :-(
Do i feel stupid ...... Ofcourse now i see what you meant Tom
changed this in form1 and form3
Public Class Form1
Private _test As String Friend Property test() As String Get Return _test End Get Set(ByVal value As String) _test = value End Set End Property Friend formB As Form2 Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click formB = New Form2 formB.Show(Me) End Sub
Private Sub Form1_Load(ByVa l sender As Object, ByVal e As System.EventArg s) Handles Me.Load _test = "hallo" End Sub End Class
Public Class Form3
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click MsgBox(Form1.te st)
MsgBox(Form1.fo rmB.test)
End Sub End Class
and now it works as expected .....
i wil sit in a dark corner for a while and shame ;-|
"tomb" wrote:
M. Posseth wrote:
>i have 3 forms > >Public Class Form1 > Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As >System.EventAr gs) Handles Button1.Click > Dim frm As New Form2 > frm.Show(Me) > End Sub > Private _test As String > Friend Property test() As String > Get > Return _test > End Get > Set(ByVal value As String) > _test = value > End Set > End Property > Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As >System.EventAr gs) Handles MyBase.Load > _test = "hallo" > End Sub >End Class > >Public Class Form2 > Private _test As String > Friend Property test() As String > Get > Return _test > End Get > Set(ByVal value As String) > _test = value > End Set > End Property > Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As >System.EventAr gs) Handles Button1.Click > Dim frm As New Form3 > frm.Show(Me) > End Sub > Private Sub Form2_Load(ByVa l sender As System.Object, ByVal e As >System.EventAr gs) Handles MyBase.Load > _test = "hallo" > End Sub >End Class > >Public Class Form3 > > Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As >System.EventAr gs) Handles Button1.Click > MsgBox(Form1.te st) > > MsgBox(Form2.te st) > > > End Sub >End Class > > >why gives pressing the button in form3 the value of form1 but not of >form2 >?? > >i wonder what i am missing > >regards > >Michel > > > Maybe because you are loading Form1 as Form1, but you are instantiating a new Form2 as frm as a private variable in Form1.
T
Hello Claes
I have and will never run into this problem myself ,,, although i am a
VB6 progger from origin i also never used and will never use code like i
showed in the example .
Someone showed me this problem and i found it interesting enough to
investigate and threw it in the group as i could not explain this behavior to
him myself
ofcourse when ligthning strook and it was clear to me i felt pretty stupid
for not seeing it in forehand ( before the post )
however i am with Cors thought l ,,, why the $%$%% does this even compile
???
( vb makes it to easy to write S#it )
regards
Michel Posseth
"Claes Bergefall" wrote: "M. Posseth" <MP******@discu ssions.microsof t.com> wrote in message news:0C******** *************** ***********@mic rosoft.com... Public Class Form3
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click MsgBox(Form1.te st) MsgBox(Form2.te st) End Sub End Class
why gives pressing the button in form3 the value of form1 but not of form2 ??
i wonder what i am missing
As tomb said in his post, the problem is likely that it creates a new instance of Form2 while it manages to find the existing instance of Form1. Pass an instance of Form1 and Form2 to Form3 instead. That way you can be sure about what object you're really using.
First time I see someone using this feature (accessing forms by name instead of using a variable). I wasn't to thrilled when I saw that MS had included that in VB 2005. As you just showed it can lead to really weird behaviour. VB.NET is a perfectly valid OO language, so why not use it as one instead of trying to go back to old VB6 behaviour?
/claes
Hello M. Posset,
Let's see:
MsgBox(Form1.te st)
MsgBox(Form2.te st)
Where are Form1 and Form2 variables instantiated?
I think you're using VB2005 so you're accesing the default instance of the forms.
Why it works for Form1 and not for Form2?
Because when your application starts, it shows a default instance of Form1; when you invoke Form2.test, the default instance of Form2 is created, but not shown, so the Load event doesn't fire.
Try this (in Form3):
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
MsgBox(Form1.te st)
Form2.Show 'Fires Form2.Load event.
MsgBox(Form2.te st)
End Sub
This way you can see that you're accesing the default instance of Form2, not the instance you were seeing in the screen.
Have always in mind that the default instance of a form is different from any instance that you create.
Regards.
"M. Posseth" <MP******@discu ssions.microsof t.com> escribió en el mensaje news:0C******** *************** ***********@mic rosoft.com...
|
| i have 3 forms
|
| Public Class Form1
| Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
| System.EventArg s) Handles Button1.Click
| Dim frm As New Form2
| frm.Show(Me)
| End Sub
| Private _test As String
| Friend Property test() As String
| Get
| Return _test
| End Get
| Set(ByVal value As String)
| _test = value
| End Set
| End Property
| Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
| System.EventArg s) Handles MyBase.Load
| _test = "hallo"
| End Sub
| End Class
|
| Public Class Form2
| Private _test As String
| Friend Property test() As String
| Get
| Return _test
| End Get
| Set(ByVal value As String)
| _test = value
| End Set
| End Property
| Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
| System.EventArg s) Handles Button1.Click
| Dim frm As New Form3
| frm.Show(Me)
| End Sub
| Private Sub Form2_Load(ByVa l sender As System.Object, ByVal e As
| System.EventArg s) Handles MyBase.Load
| _test = "hallo"
| End Sub
| End Class
|
| Public Class Form3
|
| Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
| System.EventArg s) Handles Button1.Click
| MsgBox(Form1.te st)
|
| MsgBox(Form2.te st)
|
|
| End Sub
| End Class
|
|
| why gives pressing the button in form3 the value of form1 but not of form2
| ??
|
| i wonder what i am missing
|
| regards
|
| Michel
|
"M. Posseth" <MP******@discu ssions.microsof t.com> wrote in message
news:2F******** *************** ***********@mic rosoft.com... Hello Claes
I have and will never run into this problem myself ,,, although i am a VB6 progger from origin i also never used and will never use code like i showed in the example .
Good to hear :-)
Neither will I (or anyone on my team)
Someone showed me this problem and i found it interesting enough to investigate and threw it in the group as i could not explain this behavior to him myself
ofcourse when ligthning strook and it was clear to me i felt pretty stupid for not seeing it in forehand ( before the post )
however i am with Cors thought l ,,, why the $%$%% does this even compile ??? ( vb makes it to easy to write S#it )
Yes, it was interesting. Couldn't understand how it could compile myself
before I remembered seeing something about this feature in the release notes
for VS 2005. Personally I think MS went a step to far in their desire to
please the VB6 programmers.
/claes
/claes This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dmitriy Iassenev |
last post by:
hi,
I found an interesting thing in operator behaviour in C++ :
int i=1;
printf("%d",i++ + i++);
I think the value of the expression "i++ + i++" _must_ be 3, but all the
compilers I tested print 2.
|
by: Bruno van Dooren |
last post by:
Hi All,
i have some (3) different weird pointer problems that have me stumped. i
suspect that the compiler behavior is correct because gcc shows the same
results.
----------------------------------------------
//example 1:
typedef int t_Array;
int main(int argc, char* argv)
|
by: Edd Dawson |
last post by:
Hi. I have a strange problem involving the passing of command line
arguments to a C program I'm writing. I tried posting this in
comp.programming yesterday but someone kindly suggested that I'd have
better luck here. So here goes!
My program ignores any command line arguments, or at least it's
supposed to. However, when I pass any command line arguments to the
program, the behaviour of one of the functions changes mysteriously. I
have...
|
by: Bruno van Dooren |
last post by:
Hi All,
i have some (3) different weird pointer problems that have me stumped. i
suspect that the compiler behavior is correct because gcc shows the same
results.
----------------------------------------------
//example 1:
typedef int t_Array;
int main(int argc, char* argv)
|
by: Arnold Schrijver |
last post by:
I wrote a program that draws items to the screen and maintains a set of
Offset values.
There was a bug in the code, because objects were positioned wrongly. While
debugging
I found some peculiar behavior with the overloaded Property Offsets:
In class CanvasBlock:
------------------------------
Public Enum EOffsetTypes
| |
by: Alexander Inochkin |
last post by:
Hi!
I found same strange behavior of ASP.NET. It is possible this is the bug.
Follow the steps:
|
by: Christian Eder |
last post by:
Hi,
I think I have discovered a problem in context of
metaclasses and multiple inheritance in python 2.4,
which I could finally reduce to a simple example:
Look at following code:
class M_A (type) :
|
by: Bo Yang |
last post by:
Following is my code:
include <iostream>
class Test{
public:
Test(){};
void print(){ std::cout << "OK" << std::endl ; };
};
|
by: somenath |
last post by:
Hi All,
I was going through one of the exercise of one C tutorial .
In that they have given one small code and asked about the output.
#include <stdio.h>
int main(void)
{
int x = 0xFFFFFFF0;
signed char y;
|
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,...
|
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...
| |
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |