VB6 vs VB .NET

  • Thread starter Thread starter Rick Mogstad
  • Start date Start date
R

Rick Mogstad

R said:
FormSomething.TextBox1.Text = "Some text"

But, FormSomething is not the same form as Form1, I can't see the text.....

Is there a way around it or am I stuck?

I assume that Form1 is your startup form? Perhaps use a sub Main as your startup. The problem is
that The form you see is a different instance than FormSomething. They are both of type Form1,
but different instances. If you call the FormSomething.Show then you will see that FormSomething
will pop up, and the text will be correct.
 
R said:
Is there a way around it or am I stuck?

If you want to access an object, you need a reference. If you don't have a
reference you have to make it available. This was the same in VB6.

The .NET Framework contains several hundreds (or thousands) of classes.
There is no reason why classes derived from System.Windows.Forms.Form have a
global, automatically created, automatic instancing and invisible variable
with the same name of the Form, whereas the other hundreds don't have such a
variable.

If you want to have the same behavior as in VB6, you can write in a Module:

Private m_Form1 As Form1

Public Property Form1() As Form1
Get
If m_Form1 Is Nothing Then
m_Form1 = New Form1
End If
Return m_Form1
End Get
Set(ByVal Value As Form1)
m_Form1 = Value
End Set
End Property


Instead, I still would pass the reference to the object that needs it.
 
Check out following article:
http://tinyurl.com/el1

Working with Multiple Forms in Visual Basic .NET: Upgrading to .NET

Describes how working with multiple forms has changed from previous editions
of Microsoft Visual Basic and illustrates several key techniques, including
displaying a second form, changing the appearance of another form, and using
a form as a dialog.

--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
 
* "Armin Zingler said:
The .NET Framework contains several hundreds (or thousands) of classes.
There is no reason why classes derived from System.Windows.Forms.Form have a
global, automatically created, automatic instancing and invisible variable
with the same name of the Form, whereas the other hundreds don't have such a
variable.

Mhm... In VB.NET 2004, default instances will be back.

;-)
 
OK, I tried to make a module named modMain, in there I wrote:
Module modMain

Sub main()

Dim frm As New frmMain

frm.Show()

End Sub

End Module

Then I tried modMain as startup object and I saw the form for 1/10 of a
second before it closed. Same if I use Sub Main as startup.

What am I doing wrong?

Ronny
 
Herfried K. Wagner said:
Mhm... In VB.NET 2004, default instances will be back.

;-)

Yes, unfortunally. :-( Can we switch this off? Something like "Option
DoThingsUnderTheHoodThatIDontWant Off"?
 
Hi Armin,

I do not answer messages with wrong times in future which are from countries
I cannot believe it is an accident.

I thought you had the same idea as me about this kind of things.

Cor
 
Try,

----------------------------
Sub Main()

Dim frm As New frmMain

System.Windows.Forms.Application.Run(frm)

End Sub
----------------------------

This should show frmMain and keep that application running as long as
frmMain stays open.

HTH,

Trev.
 
Hi Jan,

Very good answer to someone before he had sended the message, and than
someone from Norge, do you think that he can understand your question, it is
more something to point R first on the newsgroup .

microsoft.windowsxp.basics

Because I think that someone from Norge who cannot set his system time has
more on such an answer first.

:-)))

Cor
 
Mhm... In VB.NET 2004, default instances will be back.
Yes, unfortunally. :-( Can we switch this off? Something like "Option
DoThingsUnderTheHoodThatIDontWant Off"?

Armin

I agree with Armin

Cor
 
Hi Codemonkey,

Did you not see the question is still not aked?

It is a question for the future, and therefore the answer has to wait.

Cor
 
Hmm, believe it or not, I wil have to check the time on my home PC.
Sorry, but what is the problem with wrong time?
Because the message stay on top for a log time?

Ronny
 
Mobbe...



Cor said:
Hi Jan,

Very good answer to someone before he had sended the message, and than
someone from Norge, do you think that he can understand your question, it is
more something to point R first on the newsgroup .

microsoft.windowsxp.basics

Because I think that someone from Norge who cannot set his system time has
more on such an answer first.

:-)))

Cor



form
 
OK, Cor, I see what you mean. You can wait until tomorrow with your answers.

To all who have answered:
Thank you very much, it vas really helpful.
I'm sorry for the date on my home PC. It seems to be 24 hours to fast, I
will fix it after work today.

Ronny
 
Armin,
Yes, unfortunally. :-( Can we switch this off? Something like "Option
DoThingsUnderTheHoodThatIDontWant Off"?

Looking at the code that Whidbey generated, I saw no reason why you could
not remove the code that was being injected for the default instances.
Similar to how you can remove the code that is injected via VB6 Upgrade
Wizard.

As its straight VB.NET code in the "generated" section. However I did not
verify that it would not come back each time you modified the form. I would
hope MS is smart enough to only add the code when the form is created, not
whenever it is modified.

Note there is some "singleton" code and a custom attribute.

Having an option to turn it off, or a carefully crafted add-in to remove the
code later would be nice options...

Just a thought
Jay
 
R said:
OK, I tried to make a module named modMain, in there I wrote:
Module modMain

Sub main()

Dim frm As New frmMain

frm.Show()

End Sub

End Module

Then I tried modMain as startup object and I saw the form for 1/10 of a
second before it closed. Same if I use Sub Main as startup.

What am I doing wrong?

Ronny

your
startup. The problem is will
see that FormSomething

I know a little late, but I did notice something that I would like to point
out... Variable scope in this case is procedure level. So, frm is dead
after Sub Main finishes, that's why it was disappearing. Here's the
"proper" way of doing it, atleast that's what they say, there's about 20
different ways of doing the same damn thing! LOL

Module StartHere
public m_Form as frmMain

Sub New()
m_Form = New frmMain
m_Form.Show()
End Sub ' End of Sub New
End Module

BTW, I put that comment at the end of every things I do, it keeps things
straight in long functions :)

HTH
Sueffel
 
R,

In VB6, forms' Show() method took an argument to indicate whether the form
was to be modal or modeless. If the form was to be modal, the Show() method
would not end until the form was closed or hidden. If the form was
modeless, the Show() method would cause the form to be displayed and then
would return immediately. So in your code, the form is displayed, Show()
returns immediately, your form object goes out of scope, and the form
disappears. Making the form object a member of your module outside your
subroutine can work, if you really want a modeless form. But if you want a
modal form, so that after you come back from the Show() you know a user has
entered data, call ShowDialog() instead.

The following code will behave as you wanted your code to behave:

Module modMain

Sub main()

Dim frm As New frmMain

frm.ShowDialog()

End Sub

End Module

Now, could somebody please explain to me why VB.Net has the
Application.Run() method?

Rob
 
Back
Top