473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Can't display a form

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
Jun 27 '08 #1
4 1270
My questions are (1) whether this is a correctly model?
No. The form should only be used when you want to display information.
As your program will run mostr of the time without needing to display
anything, you should store your variables in a class.

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.
If you need information to be available again after your program has ended,
and is then started again, you could store the data in a file, or perhaps in
the registry or a database. If the information is only needed while the
program is running, there is no need to do this, just keep your variables in
memory.
I definitely don't want to hard
code it.
If you need the user to be able to change values that your program uses, a
form would be useful for this. Unless it is a very small simple application,
the form is not the best place to hold these variables though
(2) Why does the form just flashed and not stayed open ?
Because your program finished. You have no code after frm.Show()
Try using ShowDialog, instead of Show.
>

Jun 27 '08 #2
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

--

"Phil" wrote:
>
My questions are (1) whether this is a correctly model?

No. The form should only be used when you want to display information.
As your program will run mostr of the time without needing to display
anything, you should store your variables in a class.

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.

If you need information to be available again after your program has ended,
and is then started again, you could store the data in a file, or perhaps in
the registry or a database. If the information is only needed while the
program is running, there is no need to do this, just keep your variables in
memory.
I definitely don't want to hard
code it.

If you need the user to be able to change values that your program uses, a
form would be useful for this. Unless it is a very small simple application,
the form is not the best place to hold these variables though
(2) Why does the form just flashed and not stayed open ?

Because your program finished. You have no code after frm.Show()
Try using ShowDialog, instead of Show.


Jun 27 '08 #3
Phil,

ShowDialog worked. Thanks so much for sharing your thoughts.

Ben

-

"Phil" wrote:
>
My questions are (1) whether this is a correctly model?

No. The form should only be used when you want to display information.
As your program will run mostr of the time without needing to display
anything, you should store your variables in a class.

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.

If you need information to be available again after your program has ended,
and is then started again, you could store the data in a file, or perhaps in
the registry or a database. If the information is only needed while the
program is running, there is no need to do this, just keep your variables in
memory.
I definitely don't want to hard
code it.

If you need the user to be able to change values that your program uses, a
form would be useful for this. Unless it is a very small simple application,
the form is not the best place to hold these variables though
(2) Why does the form just flashed and not stayed open ?

Because your program finished. You have no code after frm.Show()
Try using ShowDialog, instead of Show.


Jun 27 '08 #4
Ben wrote:
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.
Jun 27 '08 #5

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

Similar topics

4
by: Shufen | last post by:
Hi, I'm a newbie that just started to learn python, html and etc. I have some questions to ask and hope that someone can help me on. I'm trying to code a python script (with HTML) to get...
4
by: dmiller23462 | last post by:
Somebody take a look and give me any suggestions? My brain is nuked... Here's my deal....I have online submission forms on my intranet at work here....I am appending to an Access DB with the...
13
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div...
10
by: DettCom | last post by:
Hello, I would like to be able to display or hide fields based on whether a specific Yes/No radio button is selected. This is in conjunction with a posting a just made here in the same group...
1
by: Zambien | last post by:
Well, it's been about a week and I still can't figure this problem out. I've cut the html down to it's bare minimum and when I click on the select buttons in NS, the table gets all skewed. I've...
7
by: Stefan Finzel | last post by:
Hi, is there a way to change the display property on Windows Mobile 2003 SE Mobile/Pocket Internet Explorer? See following example. Please note: visibilty property has the same problem. Is...
1
by: John Phelan-Cummings | last post by:
When I add the name of a new individual in a, bound form, it will not display that person’s name in a label control of a second unbound form. I have a scheduling program that I am working on. ...
2
by: Robert | last post by:
I am trying to give the user dynamic search capabilities to select almost any record in the database from criteria they select. Everything seems to work except when I open the display form to...
4
by: _Raven | last post by:
Okay, I am playing with submitting forms with Ajax. I am trying to adapt this script to my forms: http://www.captain.at/howto-ajax-form-post-get.php I have included my code at the bottom of this...
6
by: Aspiring .NET Programmer | last post by:
Happy Friday everyone!!! I am working on a windows service and a C# application and needed some help with certain functionality. Please read through my issue below. Thanks! I have a windows...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.