VB 程序设计
Dim a, b, c, d, e, f, g, h, i As Integer
Private Sub rmbCound(ByVal rmb As Double)
a = Int(rmb / 100)
b = Int((rmb - a * 100) / 50)
c = Int((rmb - a * 100 - b * 50) / 10)
d = Int((rmb - a * 100 - b * 50 - c * 10) / 5)
e = Int((rmb - a * 100 - b * 50 - c * 10 - d * 5) / 1)
f = Int((rmb - a * 100 - b * 50 - c * 10 - d * 5 - e * 1) / 0.5)
g = Int((rmb - a * 100 - b * 50 - c * 10 - d * 5 - e * 1 - f * 0.5) / 0.1)
h = Int((rmb - a * 100 - b * 50 - c * 10 - d * 5 - e * 1 - f * 0.5 - g * 0.1) / 0.05)
i = (rmb - a * 100 - b * 50 - c * 10 - d * 5 - e * 1 - f * 0.5 - g * 0.1 - h * 0.05) / 0.01
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 And IsNumeric(Text1.Text) Then
Call rmbCound(Val(Text1.Text))
Print "100元[" & a & "]张 " & _
"50元[" & b & "]张 " & _
"10元[" & c & "]张 " & _
"5元[" & d & "]张 " & _
"1元[" & e & "]张 " & _
"5角[" & f & "]张 " & _
"1角[" & g & "]张 " & _
"5分[" & h & "]张 " & _
"1分[" & i & "]张 "
End If
End Sub
这里主要考察的是 Sin 和 Cos 这两个函数的应用,假设文本框名称为 Text1,要显示结果的标签儿名称为 Label1,那么求正弦值的关键代码为:
Label1.Caption = CStr(Sin(Text1.Text))求余弦值的关键代码为:
Label1.Caption = CStr(Cos(Text1.Text))
完整代码需要再加 If 判断语句、CommandButton_Click() 事件等,把这些组织起来就是一个小程序了。
如你所愿:
Dim answer(1 To 20) As Single
Dim tt As Integer
Dim cl As String
Private Sub Command1_Click()
Text1.Text = ""
tt = 10
Timer1.Enabled = True
cl = Chr(13) & Chr(10)
Dim i As Integer
For i = 1 To 20
Call pro(i)
Next i
Text1.Text = Text1.Text & "注: Mod为求余运算 "
End Sub
Private Sub pro(ByVal var As Integer)
Text1.FontSize = 18
Dim m1%
Dim m2%
Dim sign%
Dim sg$
Randomize
m1 = Int(100 * Rnd + 1)
m2 = Int(100 * Rnd + 1)
sign = Int(4 * Rnd + 1)
Select Case sign
Case 1
sg = "+": answer(var) = m1 + m2
Case 2
sg = "-": answer(var) = m1 - m2
Case 3
sg = "*": answer(var) = m1 * m2
Case Else
sg = "Mod"
If m2 = 0 Then
Call pro(var)
Else
answer(var) = m1 Mod m2
End If
End Select
Text1.Text = Text1.Text & "(" & var & ")" & "." & m1 & sg & m2 & "=?" & cl
End Sub
Private Sub Command2_Click()
Call test
End Sub
Private Sub Form_Load()
Text2.FontSize = 18
Label1.FontSize = 18
Label2.FontSize = 14
Label3.FontSize = 14
Command1.FontSize = 18
Command2.FontSize = 18
Form1.Caption = "小学算术"
Label1.Caption = "题目:"
Command1.Caption = "出题"
Command2.Caption = "提交答案"
Label3.Caption = "每个答案用空格隔开"
Timer1.Interval = 1000
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
If tt = 0 Then
Timer1.Enabled = False
Call test
Else
tt = tt - 1
Label2.Caption = "你还有" & tt & "秒完成题目"
End If
End Sub
Private Sub test()
Dim right As Integer
right = 0
Timer1.Enabled = False
Dim rep
rep = Split(Text2.Text)
For i = 1 To UBound(rep) + 1
If answer(i) = rep(i - 1) Then
right = right + 1
End If
Next i
MsgBox ("您一答对了" & right & "道题!")
End Sub
这个简单,只是花时间去做得很,才100分,不值得。
最多两个小时搞定。查查资料你就会做了。
timer*1
text*1
label*1
command*1
msgbox*1times
已发邮箱
以下是代码
Option Explicit
Option Base 1
Dim a(20, 4) As Integer, b(20) As Integer
Dim i%, n%, j%
Private Sub Command1_Click()
If Val(Text1.Text) = a(j + 1, 3) Then
List1.RemoveItem (j)
List1.AddItem (Label1.Caption & "=" & Text1.Text & Space(2) & "√"), j
n = n + 1
Else
List1.RemoveItem (j)
List1.AddItem (Label1.Caption & "=" & Text1.Text & Space(2) & "×"), j
End If
End Sub
Private Sub Command2_Click()
Randomize
For i = 1 To 20
a(i, 1) = Int(Rnd * (100 - 1 + 1)) + 1
b(i) = Int(Rnd * (2 - 1 + 1)) + 1 'b=1减,b=2加
Next i
For i = 1 To 20
If b(i) = 1 Then
a(i, 2) = Int(Rnd * (a(i, 1) - 1 + 1)) + 1
Else
a(i, 2) = Int(Rnd * (100 - 1 + 1)) + 1
End If
Next i
For i = 1 To 20
If b(i) = 1 Then
a(i, 3) = a(i, 1) - a(i, 2)
List1.AddItem (LTrim(Str$(a(i, 1))) & "-" & LTrim(Str$(a(i, 2))))
Else
a(i, 3) = a(i, 1) + a(i, 2)
List1.AddItem (LTrim(Str$(a(i, 1))) & "+" & LTrim(Str$(a(i, 2))))
End If
Next i
Command1.Enabled = True
Command2.Enabled = False
Timer1.Enabled = True
End Sub
Private Sub Command3_Click()
Text2.Text = LTrim(Str(n))
Text3.Text = LTrim(Str(n * 5))
End Sub
Private Sub Command4_Click()
List1.Clear
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Label1.Caption = ""
Command2.Enabled = True
n = 0
End Sub
Private Sub Command5_Click()
End
End Sub
Private Sub Form_Load()
Timer1.Interval = 30 * 1000
End Sub
Private Sub List1_Click()
Label1.Caption = List1.List(List1.ListIndex)
j = List1.ListIndex
Debug.Print j
Text1.Text = ""
Text1.SetFocus
End Sub
Private Sub Timer1_Timer()
MsgBox "Time's up!" & Chr(10) & "你答对了" & n & "道题. 得分为" & n * 5 & "分"
List1.Clear
Label1.Caption = ""
Text1.Text = ""
Timer1.Enabled = False
End Sub
'timer.interval值自己改改吧,单位是毫秒
房健朝阳: VB 是Visual Basic编程语言 编写计算机程序需要使用计算机编程语言.计算机编程语言是人和计算机“对话”的桥梁.就像人类的语言一样,计算机编程语言也有很多.目前较为广泛使用的语言有“C++”、“Pascal”、“Basic”等.在众多...
大同县18210686499: vb程序设计?
房健朝阳: 将下面代码放入VB中,建一个按钮即可:(这段代码是求所有两位随机数内的所有质数,经调试,可用) Private Sub Command1_Click() Dim i, j, m, k As Integer Dim s(99) As Integer Dim n As Boolean n = True '对质数的判断,如果是真,则为...
大同县18210686499: 什么是计算机vb程序设计?
房健朝阳: VB就是Visual Basic,本身就是一种编程语言.
大同县18210686499: vb程序设计?
房健朝阳: Private Sub Form_Load() Dim a For i = 1 To 3 a = InputBox("提示", "请输入密码!") If a = "密码" Then MsgBox "欢迎使用本程序!" Exit Sub Else MsgBox "密码错误,请重新输入" End If Next i End Sub
大同县18210686499: VB程序设计??
房健朝阳: VB程序设计基础 一、程序设计是指为计算机编制一些软件和程序.学习的目的是理解计算机的工作方式和运行的方式. VB是经典的编程设计语言,也是基础语言之一,简单易学,功能强大,深受广大初学者的喜爱. VB是运行在Windows视窗...
大同县18210686499: VB程序设计是用来干什么 的 - ?
房健朝阳: VB编写计算机程序需要使用计算机编程语言,是用来设计一些应用桌面程序的.
大同县18210686499: VB程序设计?
房健朝阳: '用inputbox 输出2个数a、n,当2个数小于1或者大于9时,MSGBOX提示"a必须在1-9之间,请重新输入".然后重新出现inputbox. '当输出都在1-9之间时,S=a+aa+aaa+……+aaaa…a(n个a,a为1-9之间的任意一个数字)..如输入2,4.则为2...
大同县18210686499: vb 程序设计 - ?
房健朝阳: Private Sub Command1_Click() Dim x(9) As Integer Dim i As Integer Dim temp As Integer For i = 0 To 9 Randomize x(i) = Int(Rnd * 200) - 100 Next For i = 0 To 9 If x(0)temp = x(i) x(i) = x(0) x(0) = temp End If If x(9) > x(i) Then temp = x(i) x(i) = x(9) x(...
大同县18210686499: VB程序设计 - ?
房健朝阳: Private Sub Command1_Click() Dim M As Integer, N As Integer mot = Val(Text1.Text) N = Val(Text2.Text) If mot >= 7 And mot20 Then Label1.Caption = "15%" Else Label1.Caption = "5%" End If Else If N > 20 Then Label1.Caption = "30%" Else Label1.Caption = "20%" End If End If End Sub