一道VB课程设计作业,关于小型测试系统,向高手求助,急,急!
答案:1 悬赏:60 手机版
解决时间 2021-10-18 12:19
- 提问者网友:遮云壑
- 2021-10-17 19:10
一道VB课程设计作业,关于小型测试系统,向高手求助,急,急!
最佳答案
- 五星知识达人网友:酒醒三更
- 2021-10-17 19:42
Dim Ans() As StringPrivate Sub Command1_Click() '生成题目按钮Text2 = Int(Val(Text2)) '文本框控件Text2If Text2 <= 0 Then Exit SubText1 = "" '文本框控件Text1Text3 = "" '文本框控件Text3Dim i(), k(), f(3), M As String, j, x, y As Integerf(0) = "+" 'f存放运算符号f(1) = "-"f(2) = "*"f(3) = "/"ReDim k(1 To Text2), i(1 To Text2), Ans(1 To 20) 'k存放计算数字,i存放运算符号 As IntegerFor x = 1 To 20 For j = 1 To Text2 '初始化 k(j) = 0 If j < Text2 Then i(j) = 0 Next j For j = 1 To Text2 'j是计算数字的个数 Do While CInt(k(j)) = 0 k(j) = Int(Rnd() * 100) Loop Next j M = "" For j = 1 To Text2 i(j) = f(Round(Rnd() * 3, 0)) Text1 = Text1 & k(j) M = M & k(j) If j < Text2 Then Text1 = Text1 & i(j) If j < Text2 Then M = M & i(j) Next j Ans(x) = Round(Result(M), 1) '把答案放进数组里,方便评分的时候和学生的答案做对比Text1 = Text1 & vbCrLf 'Text1显示的是题目Text3 = Text3 & Round(Result(M), 1) & " " 'Text3显示的是答案Next xText3 = Trim(Text3)End SubFunction Result(ByVal x As String) '调用EXCEL来计算字符串,调试的时候请先引用Microsoft Excel object libraryDim myobj As ObjectSet myobj = CreateObject("excel.sheet")Set myobj = myobj.Application.ActiveWorkbook.ActiveSheetmyobj.Range("a1").Formula = "= " & x 'Result = myobj.Range("a1").ValueIf Err.Number > 0 Then MsgBox Err.DescriptionSet myobj = NothingEnd FunctionPrivate Sub Command2_Click() '评分按钮Dim f() As String, i As Integer, Score As Singlef = Split(Text4, " ")For i = 0 To UBound(f)If CSng(Val(f(i))) = Ans(i + 1) Then Score = Score + 5 '对比答案,如果正确就加5分,20道题刚好100分//因为f(i)是字符串,所以做对比的时候要把字符串转成数值Debug.Print f(i), Ans(i + 1)Next iMsgBox "分数是" & ScoreEnd Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯