编写VB程序。。。输入5个学生的姓名,年龄,性别,分别放在三个数组中.再输出这5个学生的信息
Dim NAM() As String 'dim 和ststic的区别,在timer实践中,每次执行一次timer事件,用dim 定义的通用变量值会不会改变
Dim AGE() As String
Dim SEX() As String
Dim TEM As Integer
Private Sub Command1_Click()
ReDim Preserve NAM(1 To TEM)
ReDim Preserve AGE(1 To TEM)
ReDim Preserve SEX(1 To TEM)
NAM(TEM) = Text1.Text
AGE(TEM) = Text2.Text
SEX(TEM) = Text3.Text
TEM = TEM + 1
End Sub
Private Sub Form_Load()
TEM = 1
End Sub
Private Sub Label4_Click()
For i = 1 To UBound(NAM)
Text4.Text = Text4.Text & "姓名:" & NAM(i) & vbCrLf & "年龄:" & AGE(i) & vbCrLf & "性别:" & SEX(i) & vbCrLf
Next i
End Sub
Private Type StudentInformation
Name as String
Age as Long
Sex as Boolean
End Type
Dim Std(4) as StudentInformation
//输入按钮事件添加代码
Dim strTmp as String
Dim str() as String
Dim i as Long
For i=0 to 4
strTmp = InputBox("请输入姓名,年龄,性别")
str = split(strTmp,",")
Std(i).Name = str(0)
Std(i).Age = str(1)
if str(2) = "男" then
Std(i).Sex = Ture
else
Std(i).Sex = False
End If
Next
//输出按钮事件代码
Dim i as Long
Dim tmp as String
For i=0 to 4
tmp = tmp & "姓名:" & Std(i).Name & " " & "年龄:" & Std(i).Age & " " & "性别:" & IIF(Std(i).Sex,"男","女") & vbCrLf
Next
Text1 = tmp
Dim Xm(5) As String
Dim Nl(5) As Integer
Dim Xb(5) As String
For i = 1 To 5
Xm(i) = InputBox("请输入第 " & i & " 名学生的姓名:")
Nl(i) = InputBox("请输入第 " & i & " 名学生的年龄:")
Xb(i) = InputBox("请输入第 " & i & " 名学生的性别:")
Next i
Print "姓名", "年龄", "性别"
For i = 1 To 5
Print Xm(i), Nl(i), Xb(i)
Next i
End Sub
每个循环5次,输入5个学生信息
a(1)=inputbox("请输入学生姓名")
具体就不写完整的代码了。实在是太简单的题目。