VB简单小程序

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Option Explicit

Dim a As Single

Dim b As Single

Dim c As Single

Private Sub cmdCount_Click()

Dim count1 As Integer

Static count2 As Integer

count1 = count1 + 1

count2 = count2 + 1

Label3.Caption = "普通局部变量计数值:" & count1

Label4.Caption = "静态局部变量计数值:" & count2

End Sub

Private Sub Command1_Click()

a = Val(Text1. Text)

b = Val(Text2.Text)

c = a * b

Text3.Text = c

End Sub

Private Sub Command2_Click()

Text1.Text = ""

Text2.Text = ""

Text3.Text = ""

End Sub

Private Sub Command3_Click()

Const pi As Double = 3.1415926

Dim rad As Integer

Dim area As Double

Dim pre As Double

rad = 10

‘此处改为rad=val(InputBox("输入数值"))试一下

area = rad * rad * pi

pre = 2 * pi * rad

Text4.Text = "半径=" & rad & "周长=" & pre & "面积=" & area End Sub

Private Sub Command4_Click()

Dim x As Integer

Dim a As Integer

Dim b As Integer

Dim c As Integer

x = Val(InputBox("输入数值"))

a = Int(x / 10)

b = x Mod 10

c = b * 10 + a

Label5.Caption = "转换前:" & x Label6.Caption = "转换后:" & c End Sub

Private Sub Command5_Click() Dim x As Single

Dim a As Integer

Dim b As Single

x = Val(InputBox("输入数值"))

a = Sqr(x)

b = Sqr(x)

Label7.Caption = a

Label8.Caption = b

End Sub

Private Sub Command6_Click() Dim a, b, c As Single

a = Val(Text6.Text)

b = (a - 32) * 5 / 9

Text5.Text = b

End Sub

Private Sub Command7_Click()

'Dim a As Single

'a = Val(Text7.Text)

'If a < 100 Then

' Text8.Text = "a小与100"

'Else

' Text8.Text = "a大于100"

' End If

Text8.Text = IIf(100 <> 99, 100, 99) End Sub

Private Sub Command8_Click()

Dim str As String

Dim a, b, c, d, e As Single

Dim X1, X2 As Single

a = Val(Text9.Text)

b = Val(Text10.Text)

c = Val(Text11.Text)

If a = 0 Then

str = MsgBox("输入参数不是二次方程", 5 + 32)

Else

d = b * b - 4 * a * c

e = -b / 2 * a

If d = 0 Then

Label14.Caption = Label14.Caption & "x1=x2=" & e

ElseIf d < 0 Then

Label14.Caption = "无解"

Else

X1 = (-b - Sqr(d)) / (2 * a)

X2 = (-b + Sqr(d)) / (2 * a)

Label14.Caption = Label14.Caption & "x1=" & X1 & " " & "x2=" & X2

End If

End If

End Sub

Private Sub Form_Load()

Print Tab(14); String(27, "_")

Dim a, b, c, d, e As Single

Dim X1, X2 As Single

End Sub

Private Sub Label13_Click()

a = Val(Text9.Text)

b = Val(Text10.Text)

c = Val(Text11.Text)

Label13.Caption = Label13.Caption & a & "x2" & "+" & b & "x" & "+" & c & "=0" End Sub

相关文档
最新文档