在窗体中引用控件(名称为commondialog1),使用commondialog1showopen就可以出现
了,该控件具体用法你可以看看msdn
for
vb60,中的"commondialog
控件",这里不再重复……
1输入Private Sub Form1 Click()EndEnd Sub
2输入Private Sub Command1_Click()
3输入UnloadmeEnd Sub即完成
扩展资料
在VB中,注释有2种方式。
1以Rem关键字开头,并且Rem关键字与注释内容之间要加一个空格。注释可以是单独的一行,也可以写在其他语句行的后面。如果在其他语句行后使用Rem关键字,则必须使用冒号(:)与语句隔开。
2也可以使用一个撇号来代替Rem关键字,若使用撇号,则在其他语句行使用时不必加逗号。
参考资料:
'
check1、check2、check3为checkbox控件数组'check1、check2、check3的style属性设置为1
Private Sub Form_Load()
Dim i As Integer
Check1(0)Caption = "除7余0"
For i = 1 To 6
Load Check1(i)
Check1(i)Left = Check1(i - 1)Left + 800
Check1(i)Top = Check1(i - 1)Top
Check1(i)Caption = "除7余" & i
Check1(i)Visible = True
Next i
Check2(0)Caption = "除8余0"
For i = 1 To 7
Load Check2(i)
Check2(i)Left = Check2(i - 1)Left + 800
Check2(i)Top = Check2(i - 1)Top
Check2(i)Caption = "除8余" & i
Check2(i)Visible = True
Next i
Check3(0)Caption = "1到5"
For i = 1 To 3
Load Check3(i)
Check3(i)Left = Check3(i - 1)Left + 1500
Check3(i)Top = Check3(i - 1)Top
Check3(i)Caption = i 5 + 1 & "到" & (i + 1) 5
Check3(i)Visible = True
Next i
Command1Caption = "清除"
Command2Caption = "统计"
Text1Text = ""
Text2Text = ""
End Sub
Private Sub Command1_Click()
Dim i As Integer
For i = 0 To Check1UBound
Check1(i)Value = vbUnchecked
Next
For i = 0 To Check2UBound
Check2(i)Value = vbUnchecked
Next
For i = 0 To Check3UBound
Check3(i)Value = vbUnchecked
Next
Text1Text = ""
Text2Text = ""
End Sub
Private Sub Command2_Click()
Dim i As Integer, j As Integer, m As Integer
Dim s As String
Dim n(1 To 20) As Integer
For i = 0 To Check1UBound
If Check1(i)Value = vbChecked Then
s = s & " " & Check1(i)Caption
For j = 1 To 20
If j Mod 7 = i Then
n(j) = n(j) + 1
End If
Next j
End If
Next
For i = 0 To Check2UBound
If Check2(i)Value = vbChecked Then
s = s & " " & Check2(i)Caption
For j = 1 To 20
If j Mod 8 = i Then
n(j) = n(j) + 1
End If
Next j
End If
Next
For i = 0 To Check3UBound
If Check3(i)Value = vbChecked Then
s = s & " " & Check3(i)Caption
For j = i 5 + 1 To (i + 1) 5
n(j) = n(j) + 1
Next j
End If
Next
Text1Text = Trim(s)
s = ""
j = 0
For i = 1 To 20
If n(i) > m Then
m = n(i)
End If
Next
For i = 0 To m
If s = "" Then
s = i & "次:"
Else
s = s & vbCrLf & i & "次:"
End If
For j = 1 To 20
If n(j) = i Then
s = s & j & ","
End If
Next
Next
Text2Text = s
End Sub额……仅供参考,没装VB,直接在这里打了:
function F(byval x as double) as double
if x<=-2 then
F=xx
else
if x>-2 and x<=2 then
F=abs(x)
else
if x>2 and x<=8 then
F=x+1 '图中的符号看不清,好像是+号,如果错了自己修改下吧
else
F=0-x
end if
end if
end if
end function程序界面上有几个按钮,分别代表了不同的颜色,点击不同的按钮,text1backcolor显示相应的颜色如果是这样的话,就可以这样编写代码:Private Sub Command1_Click()
Text1BackColor = RGB(255, 0, 0)
End Sub
Private Sub Command2_Click()
Text1BackColor = RGB(0, 255, 0)
End Sub
Private Sub Command3_Click()
Text1BackColor = RGB(0, 0, 255)
End Sub
你也可以用一个按钮实现颜色的循环变换
Dim i As Integer
Private Sub Form_Load()
i = 1
End Sub
Private Sub Command4_Click()
If i = 1 Then
Text1BackColor = RGB(255, 0, 0)
i = i + 1
ElseIf i = 2 Then
Text1BackColor = RGB(0, 255, 0)
i = i + 1
Else
Text1BackColor = RGB(0, 0, 255)
i = 1
End If
End Sub
直接用MSGBOX函数即可。不需要控件。代码如下:Private Sub Command1_Click()
x = MsgBox("确定要退出吗?", vbYesNo, "提示")
If x = vbYes Then
End
End If
End Sub
VB的系统特性:
1工程限制:
实际文本之前最多只能有256 个空格的前导,在一个逻辑行中最多只能有25 个续行符。
2过程、类型和变量:
对每个模块的过程数没有限制。每个过程可包含至多64K 的代码。如果过程或模块超过这一限制,Visual Basic 便产生编译时间错误。如果遇到这种错误,可将特别大的过程分割成若干个较小的程,或将模块级声明移到另一模块,来避免此类错误发生。Visual Basic 用表来保存代码中的标识符名(变量、过程、常量等)。每个表限于64K。
3动态链接库声明表:
每个窗体和代码模块使用一个描述动态链接库入口点的结构的表。每个结构约40 个字节,表的大小限于64K,形成每个模块大约有1500 个声明。
4工程名表:
整个应用程序用一张包含所有名称的表。这些名称包括:常量名、变量名、自定义的类型定义名、模块名、DLL 过程声明名。对工程名表总大小没有限制,但是区分大小写的条目不得超过32K。如果超过了32K 的限制,可以在不同的模块中重新使用private 标识符以限制区分大小写的条目数到达32K。
5输入表:
在不同的模块中每引用一个标识符,便在输入表中创建一个条目。每一个这样的入口最小是24 字节,但限于64K,这样每个模块大约可以有2000 个引用。
'check1、check2、check3为checkbox控件数组'check1、check2、check3的style属性设置为1
Private Sub Form_Load()
Dim i As Integer
Check1(0)Caption = "除7余0"
For i = 1 To 6
Load Check1(i)
Check1(i)Left = Check1(i - 1)Left + 800
Check1(i)Top = Check1(i - 1)Top
Check1(i)Caption = "除7余" & i
Check1(i)Visible = True
Next i
Check2(0)Caption = "除8余0"
For i = 1 To 7
Load Check2(i)
Check2(i)Left = Check2(i - 1)Left + 800
Check2(i)Top = Check2(i - 1)Top
Check2(i)Caption = "除8余" & i
Check2(i)Visible = True
Next i
Check3(0)Caption = "1到5"
For i = 1 To 3
Load Check3(i)
Check3(i)Left = Check3(i - 1)Left + 1500
Check3(i)Top = Check3(i - 1)Top
Check3(i)Caption = i 5 + 1 & "到" & (i + 1) 5
Check3(i)Visible = True
Next i
Command1Caption = "清除"
Command2Caption = "统计"
Text1Text = ""
Text2Text = ""
End Sub
Private Sub Command1_Click()
Dim i As Integer
For i = 0 To Check1UBound
Check1(i)Value = vbUnchecked
Next
For i = 0 To Check2UBound
Check2(i)Value = vbUnchecked
Next
For i = 0 To Check3UBound
Check3(i)Value = vbUnchecked
Next
Text1Text = ""
Text2Text = ""
End Sub
Private Sub Command2_Click()
Dim i As Integer, j As Integer, m As Integer
Dim s As String
Dim n(1 To 20) As Integer
For i = 0 To Check1UBound
If Check1(i)Value = vbChecked Then
s = s & " " & Check1(i)Caption
For j = 1 To 20
If j Mod 7 = i Then
n(j) = n(j) + 1
End If
Next j
End If
Next
For i = 0 To Check2UBound
If Check2(i)Value = vbChecked Then
s = s & " " & Check2(i)Caption
For j = 1 To 20
If j Mod 8 = i Then
n(j) = n(j) + 1
End If
Next j
End If
Next
For i = 0 To Check3UBound
If Check3(i)Value = vbChecked Then
s = s & " " & Check3(i)Caption
For j = i 5 + 1 To (i + 1) 5
n(j) = n(j) + 1
Next j
End If
Next
Text1Text = Trim(s)
s = ""
j = 0
For i = 1 To 20
If n(i) > m Then
m = n(i)
End If
Next
For i = 0 To m
If s = "" Then
s = i & "次:"
Else
s = s & vbCrLf & i & "次:"
End If
For j = 1 To 20
If n(j) = i Then
s = s & j & ","
End If
Next
Next
Text2Text = s
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)