NumericUpDown and Closing Dialog Box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AngZangGui
    New Member
    • Jul 2007
    • 11

    NumericUpDown and Closing Dialog Box

    I am new to VB and need to use it for my school project. As the project is about some booking system, I need to enable users to select the time they want to book the facilities.

    I would like to know how can I display the time in a label together in the form of , for example, instead of "9 : 0", I want to have "9 : 00"? I know that the DateTimePicker can easily accomplish what I want but I do not need the time to be precise until seconds.

    Another question is that how do I close the main form after I had opened up another form? I had tried adding "Me.Close" after the code "frmExample.Sho wDialog()" but it does not execute.

    Thanks and sorry if you may find it difficult to understand my English because I do not normally speak or write in English.
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Originally posted by AngZangGui
    Thanks and sorry if you may find it difficult to understand my English because I do not normally speak or write in English.
    Hello, AngZangGui!

    Your English is just fine:-)

    how can I display the time in a label together in the form of , for example, instead of "9 : 0", I want to have "9 : 00"?
    I would say make your label longer, it looks like what you need is 9:00 I will take a good look myself. But there must be a format section in properties that will allow you change a field's date format to what you need.

    how do I close the main form after I had opened up another form? I had tried adding "Me.Close" after the code "frmExample.Sho wDialog()" but it does not execute.

    You started off pretty good, try Me.Close or:

    [CODE=vb]
    ...your code here
    Unload Me
    MyNewForm.Show
    End Sub
    [/CODE]

    I think that's it, with Unload Me you do not truly need Me.Close. You may find where it is important. MyNewForm is the form name to which you need to make visible. You could have also said:

    [CODE=vb]
    ...your code here
    MyOldForm.Visib le=False
    MyNewForm.Visib le=True
    End Sub
    [/CODE]

    Either way your other form would then be visible. Please stay tuned if you need help. Good luck and welcome!
    Last edited by Killer42; Jul 17 '07, 03:12 AM. Reason: Changed CODE tags to CODE=vb :)

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by AngZangGui
      I am new to VB and need to use it for my school project. As the project is about some booking system, I need to enable users to select the time they want to book the facilities.

      I would like to know how can I display the time in a label together in the form of , for example, instead of "9 : 0", I want to have "9 : 00"? I know that the DateTimePicker can easily accomplish what I want but I do not need the time to be precise until seconds.

      Another question is that how do I close the main form after I had opened up another form? I had tried adding "Me.Close" after the code "frmExample.Sho wDialog()" but it does not execute.

      Thanks and sorry if you may find it difficult to understand my English because I do not normally speak or write in English.
      Hi there.

      Firstly, I do normally speak and write English, and I would say yours is excellent. Better than what we see from many native speakers.

      To place a time value in a label in whatever format you like, I'd suggest you play around with the Format() function. I won't go into detail, because I use VB6 (which is about ten years old) and it looks as though you are using a later version. The syntax details are often different.

      As for opening/closing the form, unfortunately I think this is an area which is very different between our versions of VB. But I would ask, are you opening the form as "modal"? You might need to check the documentation for ShowDialog, but I suspect it does so. When you open a "modal" form, it takes control and doesn't return it until you close or hide it. So your Close statement may be executing after your other form has done its thing. You may need to look into an alternative method of opening the form.

      Don't forget, I'm not familiar with the later versions of VB, so if what I said doesn't seem to work out, don't assume you're doing something wrong - there's a good chance it's my fault.

      Comment

      • Dököll
        Recognized Expert Top Contributor
        • Nov 2006
        • 2379

        #4
        We must have been posting the same instant, good advice...

        Comment

        • AngZangGui
          New Member
          • Jul 2007
          • 11

          #5
          Thanks for the all the help and the encouragement. By the way, I'm using vb 2003 because the school lab uses it.

          I managed to display the time as "9:00" but the code I used was a little too crude.
          Here's what I typed:

          [CODE=VB]
          strEndMin = spnEndMin.Text
          If strEndMin < 10 Then
          lblResvEnd.Text = "" & strEndHr & " : 0" & strEndMin
          Else
          lblResvEnd.Text = "" & strEndHr & " : " & strEndMin
          End If
          [/CODE]
          As for the dialog box, I set Me.Visible = False before I opened up my new Dialog.

          Have a nice day. :)
          Last edited by Dököll; Jul 18 '07, 01:13 AM. Reason: Code tags

          Comment

          • Dököll
            Recognized Expert Top Contributor
            • Nov 2006
            • 2379

            #6
            Originally posted by AngZangGui
            Thanks for the all the help and the encouragement. By the way, I'm using vb 2003 because the school lab uses it.

            I managed to display the time as "9:00" but the code I used was a little too crude.
            Here's what I typed:

            [CODE=VB]
            strEndMin = spnEndMin.Text
            If strEndMin < 10 Then
            lblResvEnd.Text = "" & strEndHr & " : 0" & strEndMin
            Else
            lblResvEnd.Text = "" & strEndHr & " : " & strEndMin
            End If
            [/CODE]
            As for the dialog box, I set Me.Visible = False before I opened up my new Dialog.

            Have a nice day. :)
            Still you're using a better version than I am. Am I to guess that you are okay now, by the way, regarding the above?

            Comment

            • AngZangGui
              New Member
              • Jul 2007
              • 11

              #7
              Originally posted by Dököll
              Still you're using a better version than I am. Am I to guess that you are okay now, by the way, regarding the above?
              Except for the closing of the dialog box, I'm quite fine. I just realised that I never really close the dialog box, merely making it invisible to the user. Perhaps I try something else later when I get home.

              Comment

              Working...