1. Buka Aplikasi Visual Basic 6.0
2. Desain Form seperti ini
3. Ubah Property
Form1 - Name - FmArrayTest
Form1 - Caption - Array Test
List1-Name-List1
Command1-Caption-Input
Command2-Caption-Redim
Combo1-Name-Combo1
Text1-Name-Text1
4. Copy code berikut lalu klik View Code dan pastekan
Dim NamaSiswa() As String
Private Sub Command1_Click()
Dim no As Integer, i As Integer
no = CInt(Combo1.Text)
NamaSiswa(no) = InputBox("Tuliskan nama siswa no : " & no, "Input Nama Siswa")
If NamaSiswa(no) <> "" Then
List1.Clear
For i = 1 To UBound(NamaSiswa)
List1.AddItem "NamaSiswa (" & i & ")=" & NamaSiswa(i)
Next i
End If
End Sub
Private Sub Command2_Click()
Dim num As Integer, i As Integer
If Not IsNumeric(Text1.Text) Then Exit Sub
num = CInt(Text1.Text)
ReDim NamaSiswa(1 To num)
ReDim Preserve NamaSiswa(1 To num)
Combo1.Clear
List1.Clear
For i = 1 To UBound(NamaSiswa)
Combo1.AddItem i
List1.AddItem "NamaSiswa(" & i & ")=" & NamaSiswa(i)
Next i
Combo1.ListIndex = 0
End Sub
Private Sub Form_Load()
Dim i As Integer
ReDim NamaSiswa(1 To 5)
For i = 1 To 5
Combo1.AddItem i
Next i
Combo1.ListIndex = 0
End Sub
5. Jalankan Program dengan menekan F5, maka tampilannya akan seperti ini
Download Program Array Test Visual Basic 6.0
SELAMAT MENCOBA...!!!
No comments:
Post a Comment