以下有一道VB题目,请指教!

来源:百度知道 编辑:UC知道 时间:2024/09/28 09:42:27
题目是:已知学号由6个数码组成,如032343001,其中从左算起前2位表示年级,第5个数码表示学生类型,学生类型规定如下:2-博士生,3-硕士生,4-本科生,5-专科生,设计程序,从文本框中输入一个学号,经过判断后,杂另外两个文本框中显示该生的年级及学生类型。
程序如下:
Private Sub Command1_Click()
Dim y As Long, a As Integer
Dim b As Integer, c As Integer
Dim d As Integer, e As Integer
Dim f As Integer, g As Integer
Dim h As Integer, i As Integer
y = Val(Text1.Text)
y = abcdefghi
If b = 1 Then
Text2.Text = "一年级"
ElseIf b = 2 Then
Text2.Text = "二年级"
ElseIf b = 3 Then
Text2.Text = "三年级"
Else
Text2.Text = "四年级"
End If
If e = 2 Then
Text3.Text = "博士生"
ElseIf e = 3 Then
Text3.Text = "硕士生"
ElseIf e = 4 Then
Text3.Text = "本科生"
Else
Text3.Text = "专科生"
End If
End Sub

但运行不成功,请指教!

你要的程序代码来了,我已经验证OK!!!

Private Sub Command1_Click()
Dim str As String
str = Text1.Text
Select Case Val(Left(Text1.Text, 2))
Case 1
Text2.Text = "一年级"
Case 2
Text2.Text = "二年级"
Case 3
Text2.Text = "三年级"
Case Else
Text2.Text = "四年级"
End Select
Select Case Val(Mid(Text1.Text, 5, 1))
Case 2
Text3.Text = "博士生"
Case 3
Text3.Text = "硕士生"
Case 4
Text3.Text = "本科生"
Case Else
Text3.Text = "专科生"
End If
End Sub

不要定义太多的变量,占内存啊!我也是VB爱好者,以后要多互相学习了!!!

y = Val(Text1.Text)
y = abcdefghi
改为:

b = Val((MidText1.Text, 1, 2)))
e = Val((MidText1.Text, 5, 1)))


y = Val(Text1.Text)
y = abcdefghi
改为
b = Val(Mid(Text1.Text, 1, 2))
e = Val(Mid(Text1.Text, 5, 1))

VB垃圾