?
Solved

A Question on Print keyword

Posted on 2005-03-08
3
Medium Priority
?
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month10 days, 19 hours left to enroll

770 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