Can't display a form

B

Ben

Hi all,

I am trying to write a test console app in vb2008 express. Below is the
code:

Module Module1
Sub Main()
Dim frm As New Form1
MsgBox("a test message")
'frm.Visible = True
frm.Show()
End Sub
End Module


I have a form1. I was able to run it from the command line and have a
message box display. But when it tried to display form1, it just flashed and
went away. It did not stay on sccreen as I had thought.

I wanted to build a console application running off the server, but I use a
form to hold information for it to runs. I would use the form also for
maintenance purpose, because the information on the form can change.

Under normal operation, the application would launch, then loads the form
but remain not visible. From there the application retrieves the necessary
information to run from the form. Once it reads off the information, it
continues to run until completion.

And when I run the application from the command line with a switch like
this: myapp -d or myapp /d it should immediately display form1, where I
update my information. Form1 contains information the console application
uses to run.

My questions are (1) whether this is a correctly model? I thought about
using reading the information off a txt file but since it can be deleted or
tampered, I decided to use a form instead. I definitely don't want to hard
code it. (2) Why does the form just flashed and not stayed open ?

Thanks for sharing your thoughts.

Ben
 
B

Ben

Phil,

My predicament is that the parameters change, albeit, infrequently. But
when it does, the user need to be able to make changes so that it runs
correctly in subsequent runs. Hard coding just doesn't seem to make a lot of
sense, as it entail a recompile everytime things change.

Thanks again,

Ben
 
P

Phill W.

Ben said:
I have a form1. I was able to run it from the command line and have a
message box display. But when it tried to display form1, it just flashed and
went away. It did not stay on sccreen as I had thought.

To get a .Net Form up and running, you have to give it a Windows Message
Loop to live in; just Loading it doesn't do the trick any more.

Application.Run( frm )

will do the trick, though.
I wanted to build a console application running off the server, but I use a
form to hold information for it to runs. I would use the form also for
maintenance purpose, because the information on the form can change.

No reason you can't do that. A Form is just a Class you can see.

[Shared] Function Main( Byval args as String() ) as Integer
Dim iResult as Integer

Dim frm as New Form1

If args.GetUpperBound( 0 ) >= 0 _
AndAlso args( 0 ) = "/d" _
Then
Application.Run( frm )
iResult = 0
Else
iResult = DoUsefulStuff( frm )
End If

Return iResult
End Function

Private [Shared] Function DoUsefulStuff( _
ByVal frm as Form1 _
) as Integer
' In here, you can use any of the Public properties
' and methods on Form1.

Return ??
End Function

HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top