Login or Sign Up
Logging in...
Remember me
Log in
Or
Sign Up
Forgot password or user name?
Log in with
Search in titles only
Search in Visual Basic only
Search
Advanced Search
Forums
Product Launch
Updates
Today's Posts
Member List
Calendar
Home
Forum
Topic
Visual Basic
creating an array at runtime
Collapse
X
Collapse
Posts
Latest Activity
Photos
Page
of
1
Filter
Time
All Time
Today
Last Week
Last Month
Show
All
Discussions only
Photos only
Videos only
Links only
Polls only
Events only
Filtered by:
Clear All
new posts
Previous
template
Next
rekhamanoj
New Member
Join Date:
Mar 2008
Posts:
3
#1
creating an array at runtime
Mar 22 '08, 11:40 AM
hello all
how to create an array at runtime in vb
kadghar
Recognized Expert
Top Contributor
Join Date:
Apr 2007
Posts:
1302
#2
Mar 24 '08, 03:53 PM
Originally posted by
rekhamanoj
hello all
how to create an array at runtime in vb
yo cannot create it at run time, you must have it already defined. But, you can define it as:
dim MyArr()
and then, during runtime, you can ReDim it:
ReDim MyArr(1 to n, 1 to m)
You can also have a Variant, and if you asign some list, range, collection, etc to it, it'll become a Variant's array.
HTH
Comment
Post
Cancel
jg007
Contributor
Join Date:
Mar 2008
Posts:
283
#3
Mar 24 '08, 07:04 PM
depends what type of array you mean , I have used the code below to create and array of labels on runtime
[CODE=vbnet]
Public Class Form1
Public Mylabel(4) As System.Windows. Forms.Label
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
Dim n As Integer
' text for diverted tasks
Dim Div_text(4) As String
Div_text(1) = "A"
Div_text(2) = "B"
Div_text(3) = "C"
Div_text(4) = "D"
'add labels to array
For n = 1 To 4
Mylabel(n) = New System.Windows. Forms.Label
Next n
' set up label size and location
For n = 1 To 4
Mylabel(n).Text = New String(Div_text (n))
Mylabel(n).Loca tion = New System.Drawing. Point(200, (22 * n) - 10)
' add label to form
Me.Controls.Add (Mylabel(n))
Next
End Sub[/CODE]
Last edited by
Killer42
;
Mar 25 '08, 03:03 AM
.
Reason:
Changed CODE tag to CODE=vbnet, added closing tag.
Comment
Post
Cancel
kadghar
Recognized Expert
Top Contributor
Join Date:
Apr 2007
Posts:
1302
#4
Mar 24 '08, 07:10 PM
Originally posted by
jg007
depends what type of array you mean , I have used the code below to create and array of labels on runtime
Oh, that's true, you can make 'arrays' of controls during runtime. May be they can be more helpful for what you need, rekhamanoj!
Just have in mind that controls might be slower than variables. But for small amounts of data, it can be a nice solution.
Comment
Post
Cancel
rekhamanoj
New Member
Join Date:
Mar 2008
Posts:
3
#5
Mar 31 '08, 09:24 AM
thank you so much for your timely help
Comment
Post
Cancel
Previous
template
Next
Working...
Yes
No
OK
OK
Cancel
👍
👎
☕
Comment