Can't display a form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?QmVu?=

    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


  • Phil

    #2
    Re: Can't display a form

    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.
    >

    Comment

    • =?Utf-8?B?QmVu?=

      #3
      Re: Can't display a form

      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.
      >
      >
      >

      Comment

      • =?Utf-8?B?QmVu?=

        #4
        Re: Can't display a form

        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.
        >
        >
        >

        Comment

        • Phill W.

          #5
          Re: Can't display a form

          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.GetUpperBo und( 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.

          Comment

          Working...