|
-
Jan 31st, 2004, 01:50 AM
#1
Thread Starter
Lively Member
Problem with Sub Main
I have a sub Main() as the start up for my project.
VB Code:
Module Module1
Public Sub Main()
Dim myForm As New FrmLogin()
'do something
myForm.Show()
myForm.Activate()
End Sub
End Module
It shows the FrmLogin, and then the application exits.
Why it happens like this and how to make the application to run?
I have place the typical login entry controls in the FrmLogin form, with no code written by me.
-
Jan 31st, 2004, 02:05 AM
#2
Fanatic Member
u need to show the form by using showdialogue method
VB Code:
Module Module1
Public Sub Main()
Dim myForm As New FrmLogin()
'do something
myForm.ShowDialogue()
End Sub
End Module
-
Jan 31st, 2004, 02:11 AM
#3
Thread Starter
Lively Member
Thanks pvBangera, it solved the problem.
So confusing, in VB we needed only to call the .Show() method....
-
Jan 31st, 2004, 04:26 AM
#4
PowerPoster
Hi,
"Module Module1
Public Sub Main()
Dim myForm As New FrmLogin()
'do something
myForm.ShowDialogue()
End Sub
End Module"
Not good. That way MyForm will have to stay open. A better way is to replace
myForm.ShowDialog
with
Application.Run(myForm)
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jan 31st, 2004, 07:49 AM
#5
Frenzied Member
There's also a scope issue. You can declare the form as a global variable in the module, then .show() in sub main will work.
-
Jan 31st, 2004, 01:37 PM
#6
PowerPoster
Hi salvelinus
"There's also a scope issue. You can declare the form as a global variable in the module, then .show() in sub main will work."
Not in my copy of VB.NET. Have you tried it?
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jan 31st, 2004, 01:58 PM
#7
Frenzied Member
Originally posted by taxes
Hi salvelinus
"There's also a scope issue. You can declare the form as a global variable in the module, then .show() in sub main will work."
Not in my copy of VB.NET. Have you tried it?
Yes, the other day. I've got VB 2002. If I declared the form in Sub Main, then did Application.Run, the form would briefly flash into existance, then disappear. The app would still be listed as running, according to the IDE, but no forms were visible. My maybe faulty assumption is that it was a scope issue, because when I declared the form as global, it worked fine. It also allowed me to access/manipulate values on the form from other forms.
If the event/function/procedure where the form is declared doesn't exit until the form is closed, then you're ok. But if you need the form after the e/f/p, you're out of luck.
VB Code:
private sub DoSub()
dim frmX as New frmOtherForm
dim i as integer
'yada yada
Exit Sub
i is out of scope once Exit Sub executes. Shouldn't it be the same for frmX?
-
Jan 31st, 2004, 04:16 PM
#8
PowerPoster
Hi Salvelinus,
"Yes, the other day. I've got VB 2002. If I declared the form in Sub Main, then did Application.Run, the form would briefly flash into existance, then disappear. "
Yup! That is why I said it does not work
"The app would still be listed as running, according to the IDE, but no forms were visible. "
No. The application ends and you are back in the Design environment.
" My maybe faulty assumption is that it was a scope issue, because when I declared the form as global, it worked fine. "
If you use Form.Show in the Sub Main, it does not matter whether you declare the Form public or otherwise. The result will still be that the form flashes and the programme ends. You either use Form.ShowDialog or Application.run(Form)
"It also allowed me to access/manipulate values on the form from other forms."
I can't understand this. The programme has finished and nothing is accessible. I am obviously misunderstanding you.
"If the event/function/procedure where the form is declared doesn't exit until the form is closed, then you're ok. But if you need the form after the e/f/p, you're out of luck. "
Understood, but you are not going to design the application to perform one routine.
"i is out of scope once Exit Sub executes. Shouldn't it be the same for frmX?"
Certainly. But we are talking about starting from a module Sub Main
I think the best practice is to use the Application.Run method in a Sub Main. This then gives you total freedom.
Can any of you guys please say if I am wrong and also tell me why when the form which starts the application, whether from a module Sub Main or not, is closed, all other forms close - unless those other forms were opened with a ShowDialog method in the Sub Main?
Regards,
Last edited by taxes; Jan 31st, 2004 at 04:21 PM.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|