VisualBasic是微软公司推出的可视化编程工具MSDN之一,是目前世界上使用最广泛的程序开发工具。
VB的语法的和QBASIB语言是基本相同的,也就是说它的语法是最容易被初学者所接受的。另外VB提供的是可视化的开发环境,我们可以象搭积木一样构建出程序的界面,而且VB提供了丰富的控件组,省去了我们自己写代码实现这些效果的麻烦,这样我们就能把更多的精力放在程序功能的实现上,所以VB学起来简单,用起来方便。
变量定义面变量名x,y换别x1y1等
Dim
x1
As
Integer
Private
Sub
Command1_Click()'+按钮
x1
=
x1
+
1
MeCaption
=
x1
End
Sub
Private
Sub
Command2_Click()'-按钮
x1=
x1
-
1
MeCaption
=
x1
End
Sub
'用法:: AA "1234"
Function AA(ByVal x As String) As String
Dim ns As Integer
ns = Len(x)
Dim n() As String
Dim w() As Integer
ReDim n(ns)
ReDim w(ns)
Dim i As Integer
For i = 1 To ns
n(i) = Mid(x, ns - i + 1, 1)
Next
Dim str As String
BB n, w, 0, str
MsgBox str
Open "c:\1txt" For Output As #1 ''输出文件句自己改
Print #1, str
Close #1
End Function
Function BB(ByRef n() As String, w() As Integer, ByVal k As Integer, s As String)
Dim i As Integer, j As Integer
Dim b As Boolean
For i = 1 To UBound(n)
b = False
For j = 1 To k
If i = w(j) Then
b = True
Exit For
End If
Next
If Not b And k + 1 <= UBound(n) Then
w(k + 1) = i
BB n, w, k + 1, s
End If
Next
If UBound(w) = k Then
For i = 1 To UBound(w)
s = s & n(w(i))
Next
s = s & vbCrLf
Exit Function
End If
End Function
程序包含一个标签和一个间隔1秒的时间控件
Private xx(1 To 5) As String
Private i As Integer, f As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 112 Then
f = MsgBox("你按了F1,继续吗?", vbYesNo + vbInformation, "提示")
If f = vbYes Then
Timer1Enabled = True
Else
Call Form_KeyDown(113, 0)
End If
ElseIf KeyCode = 113 Then
MsgBox "你按了F2键,结束应用程序!"
End
End If
End Sub
Private Sub Form_Load()
xx(1) = "aaaaaaaaaa"
xx(2) = "bbbbbbbbbb"
xx(3) = "cccccccccc"
xx(4) = "dddddddddd"
xx(5) = "请按F1、F2"
i = 1
End Sub
Private Sub Timer1_Timer()
Label1Caption = xx(i)
If xx(i) = "请按F1、F2" Then
Timer1Enabled = False
Call Form_KeyDown(112, 0)
End If
i = i + 1
If i > 5 Then i = 1
End Sub
你也可以手动按F1、F2 效果一样!
代码改为:Private Sub Form_Click()Dim a, b, c, d As StringDim sum, aver As Longa = Val(InputBox("请输入第一个数"))
b = InputBox("请输入第二个数")
c = InputBox("请输入第三个数")
d = InputBox("请输入第四个数")
sum = a + b + c + d
aver = sum / 4
Print "所输入的4个数字分别是"; a, b, c, d
Print "4个数字的和为"; sum
Print "4个数字的平均值为"; averEnd Sub VB60下调试通过。
其实不用Hook,也不用模块,检查系统闲置时间已有专用函数,不必这么复杂。
完整代码如下:
Option Explicit
Private Declare Function GetLastInputInfo Lib "user32" (plii As LASTINPUTINFO) As Boolean
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Type LASTINPUTINFO
cbSize As Long
dwTime As Long
End Type
Dim lii As LASTINPUTINFO
Private Sub Form_Load()
Timer1Interval = 1000
liicbSize = Len(lii)
End Sub
Private Sub Timer1_Timer()
If GetLastInputInfo(lii) Then
If (GetTickCount - liidwTime) / 60000 >= 15 Then
Shell "shutdownexe -s -t 180"
Call MsgBox("由于本机15分钟没有 *** 作,如果3分钟后没有反应,系统将强制关机", vbYesNo + vbExclamation + vbDefaultButton2, "提示")
End If
End If
End Sub
Private Sub form_click()
MeShow
m = 10
n = 1
Print Int(Rnd (m - n - 1) + n + 1)
End Sub
第二题
Private Sub Form_Load()
Timer1Enabled = True
Timer1Interval = 1000
End Sub
Private Sub Timer1_Timer()
Cls
Print Format(Now, "long date") & " " & Time
End Sub
以上就是关于vb是什么 怎么用它来编写小程序啊、全部的内容,包括:vb是什么 怎么用它来编写小程序啊、、VB设计一个简单的小程序、如何用VB编写一个生成文本的小程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)