Monday, December 10, 2012

Dynamic Array in visual basic


Dim book() As String
Dim bknum As Integer
Private Sub CmdBook_Click()
bknum = InputBox("enter total no. of books to be entered")
ReDim book(bknum) As String
End Sub
Private Sub CmdBookdetail_Click()
List1.Clear
For i = 0 To bknum
book(i) = InputBox("Enter book Name:")
List1.AddItem book(i)
Next
End Sub
Private Sub CmdAdd_Click()
bknum = bknum + 1
ReDim Preserve book(bknum) As String
book(bknum) = InputBox("Enter book Name to be added:")
List1.Clear
For i = 0 To bknum
List1.AddItem book(i)
Next
MsgBox "Book Added"
End Sub
Private Sub CmdExit_Click()
End
End Sub
 



 Output


Note:- please set some property of your control like caption or id corresponding to your control