[英]Arrangements, Visual basic, excel
An instructor has a class of 25 students.一位讲师有 25 名学生的 class。 Each student is identified by a number from 1 to 25. All tests are stored in a two-dimensional array, with each column containing the grades for each test.每个学生由 1 到 25 之间的数字标识。所有测试都存储在一个二维数组中,每列包含每个测试的成绩。 The instructor would like to enter the student number and the test number and have the grade for that test printed on the monitor.教师想输入学生编号和考试编号,并在显示器上打印该考试的成绩。 Develop a solution to output the needed information.开发解决方案 output 所需信息。
Sub Button1_Click()
Dim StudentVolume(1 To 25, 2 To 5) As Single
Dim StudentID As Integer, Grade As String, TestNumber As Integer
For StudentID = 1 To 25 'outer loop start'
For TestNumber = 1 To 5 'inner loop start'
StudentVolume(StudentID, TestNumber) = InputBox("Enter Student Volume")
If Grade >= 100 And Grade <= 90 Then
Grade = A
Else
If Grade >= 89 And Grade <= 80 Then
Grade = B
Else
If Grade >= 79 And Grade <= 70 Then
Grade = C
Else
If Grade >= 69 And Grade <= 60 Then
Grade = D
Else
If Grade >= 59 And Grade <= 0 Then
Grade = F
End If
End If
End If
End If
End If
Cells(StudentID, Grade) = StudentVolume(StudentID, Grade)
Next TestNumber 'inner loop end'
Next StudentID 'outer loop end'
End Sub
Well, we are not Homework solution providers or other code writing service.好吧,我们不是作业解决方案提供商或其他代码编写服务。 Looking at the code provided you need to be aware of the four key practises for novice VBA programmers看提供的代码你需要了解新手VBA程序员的四个关键实践
Always, always, always put Option Explicit at the start of each Class/Form/Module.总是,总是,总是把 Option Explicit 放在每个 Class/Form/Module 的开头。
Use F1 to get help.使用 F1 获取帮助。 In the VBA IDE put your cursor on a VBA or Office object and press F1. In the VBA IDE put your cursor on a VBA or Office object and press F1. The MS help page for that item will load.该项目的 MS 帮助页面将加载。 Make sure you read and understand the help page.确保您阅读并理解帮助页面。
Compile your code before you try to Run it.在尝试运行代码之前编译代码。 In the VBA IDE use Debug.Compile Project在VBA IDE中使用Debug.Compile工程
Install the fantastic free Rubberduck addin for VBA.为 VBA 安装出色的免费 Rubberduck 插件。 In particular, pay attention to the code inspections, they are a great learning resource for VBA and the Office applications.特别要注意代码检查,它们是 VBA 和 Office 应用程序的一个很好的学习资源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.