求VB大佬看看!!谢谢!!代码怎么写!!
本程序使用了控件数组:
代码:
Private Type Student
Stu_ID As String
Name As String
Sex As String
PoliticalOrientation(1) As String
End Type
Private Sub Command1_Click()
Dim Stud As Student
With Stud
.Stu_ID = Text1.Text
.Name = Text2.Text
For i = 0 To 1
If Option1(i).Value Then .Sex = Option1(i).Caption
If Check1(i).Value Then
.PoliticalOrientation(i) = Check1(i).Caption
Else
.PoliticalOrientation(i) = "非" + Check1(i).Caption
End If
Next i
Picture1.Print "学号:" + .Stu_ID
Picture1.Print "姓名:" + .Name
Picture1.Print "性别:" + .Sex
Picture1.Print "政治面貌1:" + .PoliticalOrientation(0)
Picture1.Print "政治面貌2:" + .PoliticalOrientation(1)
Picture1.Print
Open "E:\DataFile.txt" For Append As #1
Write #1, .Stu_ID; .Name; .Sex, .PoliticalOrientation(0); .PoliticalOrientation(1)
Close #1
End With
End Sub
运行效果:
Dim i As Integer, n As Integer, a(6) As Integer
n = 6
Open "D:\1122.txt" For Append As #1
Randomize
For i = 1 To n
a(i) = Int(Rnd * 1000 + 1)
Print #1, a(i)
Next i
Close #1
读文件
Dim s As String
Dim filename As String
filename = shuxiang & xingzuo & ".txt"
Open filename For Input As #1
Do While Not EOF(1)
Line Input #1, s
Print s
Loop
Close #1