
完全按照要求做的~~
Private Sub Command1_Click()
Label1Caption = "中文字体示例"
Label1Font = "宋体"
End Sub
Private Sub Command2_Click()
Label1Font = "楷体_GB2312"
End Sub
Private Sub Command3_Click()
Label1FontBold = True
End Sub
Private Sub Command4_Click()
Label1FontSize = Form1FontSize + 2
End Sub
Private Sub Command5_Click()
Label1FontSize = Form1FontSize - 2
End Sub
Private Sub Command6_Click()
Label1Caption = ""
End Sub
Private Sub Form_click()
End
End Sub
vb可以写的程序很多,比如我学的就是用于测绘方面的
对于初学者来说,简单的啊需要了解vb的三要素“对象”“事件”“方法”
比如单机窗体加载一张作为背景:
private sub form1_()load
form1picture=loadpicture("") ,""号内为需要加载的的路径后面在加上\名格式。就可以了
end sub
再如单机命令按钮,窗体出现文字:
private sub command_()click
print"你好" '因号内为你要窗体显示的文字
end sub
VERSION 500
Begin VBForm Form1
Caption = "Form1"
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VBCommandButton Command1
Caption = "Max!"
Height = 375
Left = 2280
TabIndex = 5
Top = 1680
Width = 975
End
Begin VBTextBox Text5
Height = 375
Left = 960
TabIndex = 4
Top = 2160
Width = 1215
End
Begin VBTextBox Text4
Height = 375
Left = 960
TabIndex = 3
Top = 1680
Width = 1215
End
Begin VBTextBox Text3
Height = 375
Left = 960
TabIndex = 2
Top = 1200
Width = 1215
End
Begin VBTextBox Text2
Height = 375
Left = 960
TabIndex = 1
Top = 720
Width = 1215
End
Begin VBTextBox Text1
Height = 375
Left = 960
TabIndex = 0
Top = 240
Width = 1215
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Dim a(3) As Long
Dim nMax As Long
Dim i As Integer
a(0) = Val(Text1)
a(1) = Val(Text2)
a(2) = Val(Text3)
a(3) = Val(Text4)
nMax = 0
For i = 0 To 3
If nMax < a(i) Then nMax = a(i)
Next
Text5 = nMax
End Sub
把以上存为frm即可~运行就是了。支持任意多的文本框。
完全版的前后台代码
'请把下面的保存为 form1frm
VERSION 500
Begin VBForm Calculator
BorderStyle = 1 'Fixed Single
Caption = "计算器"
ClientHeight = 2970
ClientLeft = 2580
ClientTop = 1485
ClientWidth = 3270
ClipControls = 0 'False
BeginProperty Font
Name = "System"
Size = 975
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Icon = "CALCfrx":0000
LinkMode = 1 'Source
LinkTopic = "Form1"
MaxButton = 0 'False
PaletteMode = 1 'UseZOrder
ScaleHeight = 2970
ScaleWidth = 3270
WhatsThisHelp = -1 'True
Begin VBCommandButton Number
Caption = "7"
Height = 480
Index = 7
Left = 120
TabIndex = 7
Top = 600
Width = 480
End
Begin VBCommandButton Number
Caption = "8"
Height = 480
Index = 8
Left = 720
TabIndex = 8
Top = 600
Width = 480
End
Begin VBCommandButton Number
Caption = "9"
Height = 480
Index = 9
Left = 1320
TabIndex = 9
Top = 600
Width = 480
End
Begin VBCommandButton Cancel
Caption = "C"
Height = 480
Left = 2040
TabIndex = 10
Top = 600
Width = 480
End
Begin VBCommandButton CancelEntry
Caption = "CE"
Height = 480
Left = 2640
TabIndex = 11
Top = 600
Width = 480
End
Begin VBCommandButton Number
Caption = "4"
Height = 480
Index = 4
Left = 120
TabIndex = 4
Top = 1200
Width = 480
End
Begin VBCommandButton Number
Caption = "5"
Height = 480
Index = 5
Left = 720
TabIndex = 5
Top = 1200
Width = 480
End
Begin VBCommandButton Number
Caption = "6"
Height = 480
Index = 6
Left = 1320
TabIndex = 6
Top = 1200
Width = 480
End
Begin VBCommandButton Operator
Caption = "+"
Height = 480
Index = 1
Left = 2040
TabIndex = 12
Top = 1200
Width = 480
End
Begin VBCommandButton Operator
Caption = "-"
Height = 480
Index = 3
Left = 2640
TabIndex = 13
Top = 1200
Width = 480
End
Begin VBCommandButton Number
Caption = "1"
Height = 480
Index = 1
Left = 120
TabIndex = 1
Top = 1800
Width = 480
End
Begin VBCommandButton Number
Caption = "2"
Height = 480
Index = 2
Left = 720
TabIndex = 2
Top = 1800
Width = 480
End
Begin VBCommandButton Number
Caption = "3"
Height = 480
Index = 3
Left = 1320
TabIndex = 3
Top = 1800
Width = 480
End
Begin VBCommandButton Operator
Caption = "X"
Height = 480
Index = 2
Left = 2040
TabIndex = 14
Top = 1800
Width = 480
End
Begin VBCommandButton Operator
Caption = "/"
Height = 480
Index = 0
Left = 2640
TabIndex = 15
Top = 1800
Width = 480
End
Begin VBCommandButton Number
Caption = "0"
Height = 480
Index = 0
Left = 120
TabIndex = 0
Top = 2400
Width = 1080
End
Begin VBCommandButton Decimal
Caption = ""
Height = 480
Left = 1320
TabIndex = 18
Top = 2400
Width = 480
End
Begin VBCommandButton Operator
Caption = "="
Height = 480
Index = 4
Left = 2040
TabIndex = 16
Top = 2400
Width = 480
End
Begin VBCommandButton Percent
Caption = "%"
Height = 480
Left = 2640
TabIndex = 17
Top = 2400
Width = 480
End
Begin VBLabel Readout
Alignment = 1 'Right Justify
BackColor = &H0000FFFF&
BorderStyle = 1 'Fixed Single
Caption = "0"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00000000&
Height = 375
Left = 120
TabIndex = 19
Top = 105
Width = 3000
End
End
Attribute VB_Name = "Calculator"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' --------------------------------------------------------------------------
' 版权所有 (C) 1994 Microsoft Corporation
'
' 您可以免费以任何方式使用、修改、复制并分发您认为有用的
' 示例应用程序文件 (或任何修改过的版本)。Microsoft 对任何
' 示例应用程序文件不做任何保证,不负任何责任和义务。
' --------------------------------------------------------------------------
Option Explicit
Dim Op1, Op2 ' 前面输入的 *** 作数
Dim DecimalFlag As Integer ' 小数点仍然存在吗?
Dim NumOps As Integer ' *** 作数个数
Dim LastInput ' 指示上一次按键事件的类型
Dim OpFlag ' 指示未完成的 *** 作
Dim TempReadout
' C (取消) 按钮的 Click 事件过程
' 重新设置显示并初始化变量
Private Sub Cancel_Click()
Readout = Format(0, "0")
Op1 = 0
Op2 = 0
Form_Load
End Sub
' CE (取消输入) 按钮的 Click 事件过程
Private Sub CancelEntry_Click()
Readout = Format(0, "0")
DecimalFlag = False
LastInput = "CE"
End Sub
' 小数点 () 按钮的 Click 事件过程
' 如果上一次按键为运算符,初始化 readout 为 "0";
' 否则显示时追加一个小数点
Private Sub Decimal_Click()
If LastInput = "NEG" Then
Readout = Format(0, "-0")
ElseIf LastInput <> "NUMS" Then
Readout = Format(0, "0")
End If
DecimalFlag = True
LastInput = "NUMS"
End Sub
' 窗体的初始化过程
' 设置所有变量为其初始值
Private Sub Form_Load()
DecimalFlag = False
NumOps = 0
LastInput = "NONE"
OpFlag = " "
Readout = Format(0, "0")
'DecimalCaption = Format(0, "")
End Sub
' 数字键 (0-9) 的 Click 事件过程
' 向显示中的数追加新数
Private Sub Number_Click(Index As Integer)
If LastInput <> "NUMS" Then
Readout = Format(0, "")
DecimalFlag = False
End If
If DecimalFlag Then
Readout = Readout + Number(Index)Caption
Else
Readout = Left(Readout, InStr(Readout, Format(0, "")) - 1) + Number(Index)Caption + Format(0, "")
End If
If LastInput = "NEG" Then Readout = "-" & Readout
LastInput = "NUMS"
End Sub
' 运算符 (+, -, x, /, =) 的 Click 事件过程
' 如果接下来的按键是数字键,增加 NumOps。
' 如果有一个 *** 作数,则设置 Op1。
' 如果有两个 *** 作数,则将 Op1 设置为 Op1 与
' 当前输入字符串的运算结果,并显示结果
Private Sub Operator_Click(Index As Integer)
TempReadout = Readout
If LastInput = "NUMS" Then
NumOps = NumOps + 1
End If
Select Case NumOps
Case 0
If Operator(Index)Caption = "-" And LastInput <> "NEG" Then
Readout = "-" & Readout
LastInput = "NEG"
End If
Case 1
Op1 = Readout
If Operator(Index)Caption = "-" And LastInput <> "NUMS" And OpFlag <> "=" Then
Readout = "-"
LastInput = "NEG"
End If
Case 2
Op2 = TempReadout
Select Case OpFlag
Case "+"
Op1 = CDbl(Op1) + CDbl(Op2)
Case "-"
Op1 = CDbl(Op1) - CDbl(Op2)
Case "X"
Op1 = CDbl(Op1) CDbl(Op2)
Case "/"
If Op2 = 0 Then
MsgBox "除数不能为 0", 48, "计算器"
Else
Op1 = CDbl(Op1) / CDbl(Op2)
End If
Case "="
Op1 = CDbl(Op2)
Case "%"
Op1 = CDbl(Op1) CDbl(Op2)
End Select
Readout = Op1
NumOps = 1
End Select
If LastInput <> "NEG" Then
LastInput = "OPS"
OpFlag = Operator(Index)Caption
End If
End Sub
' 百分比键 (%) 的 Click 事件过程
' 计算并显示第一个 *** 作数的百分数
Private Sub Percent_Click()
Readout = Readout / 100
LastInput = "Ops"
OpFlag = "%"
NumOps = NumOps + 1
DecimalFlag = True
End Sub
Dim sec, min, h
Private Sub Command1_Click()
Timer1Enabled = True
h = Text1Text
min = Text2Text
sec = Text3Text
Timer2Enabled = False
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Form1BackColor = &HFFFF00
Timer1Enabled = False
Timer1Interval = 1000
Timer2Enabled = True
Timer2Interval = 1000
Text1Text = 2
Text2Text = "00"
Text3Text = "00"
Command2Caption = "退出"
Command1Caption = "开始倒计时"
End Sub
Private Sub Timer1_Timer()
If sec > 0 Then
sec = sec - 1
Else:
If (min > 0 Or h > 0) Then
sec = 59
End If
If min > 0 Then
min = min - 1
Else:
If h > 0 Then
min = 59
End If
If h > 0 Then
h = h - 1
Else: Timer1Enabled = False
CreateObject("SAPISpVoice")Speak "GAME OVER!"
Form1BackColor = &HFF
End If
End If
End If
Text1Text = h
Text2Text = min
Text3Text = sec
Label6Caption = Now
End Sub
Private Sub Timer2_Timer()
Label6Caption = Now
End Sub
以上就是关于vb设计一个程序全部的内容,包括:vb设计一个程序、一般用vb编写什么程序具体举几个简单的例子、用VB写出的设计程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)