rst.Open "select * from table1", conn, adOpenDynamic, adLockOptimistic Set DataGrid1.DataSource = rst
End Sub
'======================================================== '八、日期函数的使用以及使用FileExists判断文件是否存在 '======================================================== Private Sub Command1_Click() If IsNumeric(Text1.Text) And InStr(Text1.Text, ".") = 0 And InStr(Text1.Text, "-") = 0 Then If CLng(Text1.Text) > 0 And CLng(Text1.Text) <= 12 Then MsgBox DateDiff("d", DateSerial(Year(Now()), Text1.Text, 1), DateAdd("m", 1, DateSerial(Year(Now()), Text1.Text, 1))) Else MsgBox "Error" End If Else MsgBox "Error, Wrong Value" End If End Sub
Private Sub Command2_Click() Dim fso As Object Set fso = CreateObject("Scripting.FileSystemObject") If fso.FileExists("C:\command.com") = True Then MsgBox "C:\Command.com 文件已存在" Else MsgBox "C:\Command.com 文件不存在" End If
Private Sub Command1_Click() Dim a, b As Long Dim c As String a = Text1.Text Do If a = 0 Then Exit Do If a > 1 Then b = a Mod 2 Else b = a End If c = CStr(b) & CStr(c) a = a \ 2 Loop Text2.Text = c End Sub
Private Sub Command2_Click() Dim a, b As String Dim i, c, d As Long a = Text2.Text
For i = 1 To Len(a) c = CLng(Mid(a, i, 1)) If c = 1 Then d = d + 2 ^ (Len(a) - i) End If Next Text3.Text = d End Sub
'======================================================== '十七、在容器中移动控件 '======================================================== Pu