VB程序学习代码记录20160719

来源:互联网 发布:淘宝无需物流算销量吗 编辑:程序博客网 时间:2024/05/15 05:08

IsNull函数

Private Sub Form_Click()    Dim num    Print IsNull(num)    num = ""    Print IsNull(num)    num = "abcd"    Print IsNull(num)    num = Null    Print IsNull(num)End Sub

IsNumeric函数

Private Sub Form_Click()    Print IsNumeric(62)    Print IsNumeric(62.5)    Print IsNumeric("changchun")    Print IsNumeric(#4/1/2006#)    Print IsNumeric(Null)End Sub

Date、Now、Time函数

Private Sub Form_Click()    Print "系统日期" & Date    Print "系统日期和时间" & Now    Print "系统时间" & TimeEnd Sub

Timer函数

Dim time_startPrivate Sub Command1_Click()    If Command1.Caption = "开始计时" Then        time_start = Timer        Command1.Caption = "停止"        Timer1.Enabled = True    ElseIf Command1.Caption = "停止" Then        Timer1.Enabled = False        Command1.Caption = "开始计时"    End IfEnd SubPrivate Sub Command2_click()    Text1.Text = ""    Text2.Text = ""End SubPrivate Sub Timer1_Timer()    Text2.Text = Timer - time_startEnd SubPrivate Sub Timer2_Timer()    Text1.Text = NowEnd Sub

Weekday函数

Private Sub Form_Click()    Dim day As String    Dim n As Integer    n = Weekday(Date)    If n = 1 Then day = "Sunday"    If n = 2 Then day = "Monday"    If n = 3 Then day = "Tuesday"    If n = 4 Then day = "Wednesday"    If n = 5 Then day = "Thursday"    If n = 6 Then day = "Friday"    If n = 7 Then day = "Saturday"    Print "今天是" & dayEnd Sub

year、month、day函数

Private Sub Form_Click()    Print Year(Date) & "年" & Month(Date) & "月" & day(Date) & "日"End Sub

hour、minute、second函数

Private Sub Form_Click()    Print Hour(Now) & "点" & Minute(Now) & "分" & Second(Now) & "秒"End Sub

随机函数

Private Sub Command1_Click()   num = Int(Rnd * 6) + 1   Label1.Caption = num & "点"   display (num)End SubPrivate Sub Form_Activate()    For i = 0 To 6        Shape2(i).FillColor = &H0&        Shape2(i).FillStyle = 0        Shape2(i).Shape = 3        Shape2(i).Visible = False    Next i    Shape1.FillColor = &HFFFFFF    Shape1.FillStyle = 0    Shape1.Shape = 5    Randomize Timer    Label1.Caption = "1点"    display (1)End SubSub display(a)    For i = 0 To 6        Shape2(i).Visible = False    Next i    For i = 0 To 6        If i <> 2 Or i <> 4 Then            Shape2(i).FillColor = &H0&        End If    Next i    Select Case a    Case 1        Shape2(3).FillColor = &H0&        Shape2(3).Visible = True    Case 2        Shape2(0).Visible = True        Shape2(6).Visible = True    Case 3        Shape2(0).Visible = True        Shape2(3).Visible = True        Shape2(6).Visible = True    Case 4        For i = 0 To 6            If i = 0 Or i = 2 Or i = 4 Or i = 6 Then                Shape2(i).Visible = True            End If        Next i    Case 5        For i = 0 To 6            If i = 0 Or i = 2 Or i = 3 Or i = 4 Or i = 6 Then                Shape2(i).Visible = True            End If        Next i    Case 6        For i = 0 To 6            If i <> 3 Then                Shape2(i).Visible = True            End If        Next i    End SelectEnd Sub
0 0
原创粉丝点击