?
Solved

A Question on Print keyword

Posted on 2005-03-08
3
Medium Priority
?
244 Views
Last Modified: 2010-08-05

Hi,

I am still new in VB..And here is my question.

I created a CTime1 class:

Option Explicit

Private mHour As Integer
Private mMinute As Integer
Private mSecond As Integer

Public Sub SetTime(ByVal h As Integer, ByVal m As Integer, ByVal s As Integer)
    mHour = IIf((h >= 0 And h < 24), h, 0)
    mMinute = IIf((m >= 0 And m < 60), m, 0)
    mSecond = IIf((s >= 0 And s < 60), s, 0)
   
End Sub

Public Function ToUniversalTime() As String
    ToUniversalTime = Format$(mHour, "00") & ":" & Format$(mMinute, "00") & ":" & _
    Format$(mSecond, "00")
   
End Function

Public Function ToStandardTime() As String
    Dim h As Integer
    h = IIf((mHour = 12 Or mHour = 0), 12, mHour Mod 12)
   
    ToStandardTime = h & ":" & Format$(mMinute, "00") & ":" & Format$(mSecond, "00") & " " & _
    IIf(mHour < 12, "AM", "PM")
   
End Function





Then in my main form, I have

Private Sub Form_Load()
        Dim t As New CTime1
        Print "Initial Standard Time is : " & t.ToStandardTime()
        Print "Initial Universal Time is : " & t.ToUniversalTime()
       
        Print
       
        Call t.SetTime(17, 28, 46)
        Print "Standard Time after Calling SetTime: " & t.ToStandardTime
        Print "Universal Time after Calling SetTime: " & t.ToUniversalTime
       
        Print
       
        Call t.SetTime(5, 44, 99)
       
        Print "Standard Time after Attempting Invalid Settings: " & t.ToStandardTime
        Print "Universal Time after Attempting Invalid Settings: " & t.ToUniversalTime
End Sub



However, it does not print anything on my form. I find it very weird....

But If instead of putting it codes in Form_Load(), I create a button called Command1 and put the code in

Private Sub Command1_Click()

        Dim t As New CTime1
        Print "Initial Standard Time is : " & t.ToStandardTime()
        Print "Initial Universal Time is : " & t.ToUniversalTime()
       
        Print
       
        Call t.SetTime(17, 28, 46)
        Print "Standard Time after Calling SetTime: " & t.ToStandardTime
        Print "Universal Time after Calling SetTime: " & t.ToUniversalTime
       
        Print
       
        Call t.SetTime(5, 44, 99)
       
        Print "Standard Time after Attempting Invalid Settings: " & t.ToStandardTime
        Print "Universal Time after Attempting Invalid Settings: " & t.ToUniversalTime
End Sub



When I press the command1 button, it display on the form....I just don't understand it works for the Command1_Click() and does not work for Form_Load()
0
Comment
Question by:TungVan
3 Comments
 
LVL 19

Accepted Solution

by:
Shauli earned 120 total points
ID: 13489952
Try the Form_Activate event. You try to print while the form is stil loading ("not there yet")

S
0
 
LVL 32

Assisted Solution

by:Erick37
Erick37 earned 80 total points
ID: 13490037
When you print, make sure the form is visible first.  You may also want to set the Autoredraw property true so that anything you draw to the form will stay there and not be erased when covered by other windows or when the form is minimized, etc.

Private Sub Form_Load()
       
        Dim t As New CTime1
 '=======================
        Me.Show     'show the form
        Me.AutoRedraw = True     'keeps the form's image persistent
'========================

        Print "Initial Standard Time is : " & t.ToStandardTime()
        Print "Initial Universal Time is : " & t.ToUniversalTime()
       
        Print
       
       'and so on...

'========================
        Me.Refresh    'refresh the form display
'========================

End Sub
0
 

Author Comment

by:TungVan
ID: 13490049

Thx..it works...:)....I tried to use function Show, and it also works...thank you

Private Sub Form_Load()
    CTime.Show 1
   
    Dim t As New CTime1
    Print "Initial Standard Time is : " & t.ToStandardTime()
    Print "Initial Universal Time is : " & t.ToUniversalTime()
       
    Print
       
    Call t.SetTime(17, 28, 46)
    Print "Standard Time after Calling SetTime: " & t.ToStandardTime
    Print "Universal Time after Calling SetTime: " & t.ToUniversalTime
       
    Print
       
    Call t.SetTime(5, 44, 99)
       
    Print "Standard Time after Attempting Invalid Settings: " & t.ToStandardTime
    Print "Universal Time after Attempting Invalid Settings: " & t.ToUniversalTime
   

End Sub
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question