Option Explicit'类模块Private mHour As Integer      
Private mMinute As Integer
Private mSecond As IntegerPublic 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 ToFormatTime() As String    '24小时制
   ToFormatTime = Format$(mHour, "00") & ":" & Format$(mMinute, "00") & ":" & Format$(mSecond, "00")End FunctionPublic Function ToStandardTime() As String    '(12小时制)
   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
'form窗体里的代码
Option ExplicitPrivate Sub Form_Load()
   Dim t As New CTime     '调用类
   
   Print "标准时间为:" & t.ToStandardTime()
   Print "24小时制时间为:" & t.ToFormatTime()
   Print
   
   Call t.SetTime(17, 28, 46)
   
   Print "标准时间为:" & t.ToStandardTime()
   Print "24小时制时间为:" & t.ToFormatTime()
   
End Sub运行后为什么窗体上什么都没显示?

解决方案 »

  1.   

    修改如下:
    'form窗体里的代码
    Option ExplicitPrivate Sub Form_Load()
       Dim t As New Ctime     '调用类
       
       Me.AutoRedraw = True
       
       Print "标准时间为:" & t.ToStandardTime()
       Print "24小时制时间为:" & t.ToFormatTime()
       Print
       
       Call t.SetTime(17, 28, 46)
       
       Print "标准时间为:" & t.ToStandardTime()
       Print "24小时制时间为:" & t.ToFormatTime()
       
    End Sub
      

  2.   

    同意楼上的,加上
       Me.AutoRedraw = True
      

  3.   

    Private Sub Form_Load()
       Dim t As New Class1       '调用类
       
       Debug.Print "标准时间为:" & t.ToStandardTime()
       Debug.Print "24小时制时间为:" & t.ToFormatTime()
       Print
       
       Call t.SetTime(17, 28, 46)
       
       Debug.Print "标准时间为:" & t.ToStandardTime()
       Debug.Print "24小时制时间为:" & t.ToFormatTime()
       
    End Sub在立即窗口看一下.可以了.
    或者Private Sub Form_Load()
       Dim t As New Class1       '调用类
       Form1.AutoRedraw = True
       Print "标准时间为:" & t.ToStandardTime()
       Print "24小时制时间为:" & t.ToFormatTime()   Call t.SetTime(17, 28, 46)   Print "标准时间为:" & t.ToStandardTime()
       Print "24小时制时间为:" & t.ToFormatTime()
      
    '
    End Sub