我的问题是选择案例和记录结构:不知道如何从选择案例的返回显示网格上的字符串
这是我的分析代码:
Option Explicit On
Option Infer Off
Option Strict On
Public Class Form1
Private total As Integer
Private Structure NGO
Public name As String
Public leader As String
Public supporters As Integer
Public hours As Integer
Public average As Double
Public ratio As Double
Public status As String
Public numgroups As Integer
End Structure
Private groups As NGO
Private Sub display(ByVal r As Integer, ByVal c As Integer, ByVal t As String)
grd.Row = r
grd.Col = c
grd.Text = t
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
display(0, 2, "Leader")
display(0, 3, "Supporters")
display(0, 1, "Hours spent")
display(0, 4, " Level")
groups.numgroups = CInt(InputBox("input number of groups"))
grd.Rows = groups.numgroups + 2
display(groups.numgroups + 1, 0, "Total")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim x As Integer
For x = 1 To groups.numgroups
groups.name = CStr(InputBox("name of group no. " & CStr(x)))
display(x, 0, CStr(groups.name))
groups.hours = CInt(InputBox("input the number of hours of group no. " & CStr(x)))
display(x, 1, CStr(groups.hours))
groups.supporters = CInt(InputBox("number of supporters of group no. " & CStr(x)))
display(x, 3, CStr(groups.supporters))
groups.leader = CStr(InputBox("name of the person in charge of group no. " & CStr(x)))
groups.status = CStr(InputBox("enter the level of group no." & CStr(x)))
display(x, 2, CStr(groups.leader))
total = total + groups.hours
Next x
display(x, 1, CStr(total))
groups.average = total / groups.hours
groups.ratio = groups.supporters / groups.average
End Sub
Private Function leveldetermine(ByVal level As Double) As Double
Select Case level
Case 1 To 10
End Select
Return MsgBox("not great")
Select Case level
Case 11 To 15
End Select
Return MsgBox("average")
Select Case level
Case 16 To 20
End Select
Return MsgBox("awesome")
End Function
Private Sub btn2_Click(sender As Object, e As EventArgs) Handles btn2.Click
End Sub
End Class
答案 0 :(得分:0)
首先,您的Select..Case..End Select块结构不正确 - 它也应该是子而不是函数,因为代码不会返回值。
Private Sub leveldetermine(ByVal level As Double)
Select Case level
Case 1 To 10
MsgBox("not great")
Case 11 To 15
MsgBox("average")
Case 16 To 20
MsgBox("awesome")
End Select
End Sub