清理字符串
Private Sub Command1_Click()
Dim i As Integer
Dim tex As String
If Text1.Text = "" Then
MsgBox "请输入字符串", vbInformation, "信息提示"
Else
tex = Trim(Text1.Text)
i = 1
Do While (Len(tex) - i) > 0
tex = Left(tex, i) & Trim(Right(tex, Len(tex) - i))
i = i + 1
Loop
End If
Text2.Text = tex
End Sub
抽奖
Private Sub Command1_Click()
Timer1.Enabled = True
Command1.Enabled = False
Command2.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
Text6.Text = Text1.Text & Text2.Text & Text3.Text & Text4.Text & Text5.Text
Command1.Enabled = True
Command2.Enabled = flase
Command3.Enabled = True
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub Timer1_Timer()
Text1.Text = Format(Int(Rnd * 9))
Text2.Text = Format(Int(Rnd * 9))
Text3.Text = Format(Int(Rnd * 9))
Text4.Text = Format(Int(Rnd * 9))
Text5.Text = Format(Int(Rnd * 9))
End Sub
判断闰年
Private Sub Command1_Click()
If dates(Text1.Text) = 1 Then
MsgBox "您输入的年份是闰年!", vbInformation, "信息提示"
Else
MsgBox "您输入的年份不是闰年!", vbInformation, "信息提示"
End If
End Sub
Private Function dates(dat As Integer)
If Val(Text1.Text) Mod 400 = 0 Then
dates = 1
End If
If Val(Text1.Text) Mod 4 = 0 And Val(Text1.Text) Mod 100 <> 0 Then
dates = 1
End If
End Function
使用API函数copyfile进行复制文件
Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
Private Sub Form_Load()
CopyFile "c:\Users\Qi\desktop\1.txt", "c:\Users\Qi\\desktop\12.txt", 0
MsgBox "成功复制文件!", , "提示信息"
End Sub
关闭、打开exe程序,使用WinExec函数
Private Declare Function WinExec Lib "kernel32" (ByVal lpCmdLine As String, ByVal nCmdShow As Long) As Long
Private Sub Command1_Click()
WinExec ("mspaint.exe"), 1
End Sub
Private Sub Form_Load()
Command1.Caption = "调用画图"
Command2.Caption = "关闭画图"
End Sub