0

If today is 3rd, I want to make three obejects.

Dim Obj1 As Object

Dim Obj2 As Object

Dim Obj3 As Object

If today is 5th, I want to make three obejects.

Dim Obj1 As Object

Dim Obj2 As Object

Dim Obj3 As Object

Dim Obj4 As Object

Dim Obj5 As Object

Then how do I declare objects dynamically like this? Thank you for reading.

1
  • 1
    if you want an uncertain number of objects you'll want to hold them in an array or list. Commented Aug 10, 2017 at 8:21

3 Answers 3

2

YOu'll have to keep them in an array or list or some other kind of collection. Here's how you can achieve it:

Dim objects = New List(Of Object)

For i = 1 To Date.Today.Day
    objects.Add(New Object())
Next
Sign up to request clarification or add additional context in comments.

Comments

0

Creating a list of objects may work for what you what:

Dim objs As List(Of Object) = New List(Of [Object])()
Dim day As Integer = DateTime.Today.Day

For i As Integer = 1 To day
    Dim o As Object = New Object()
    objs.Add(o)
Next

Comments

0

Another possibility

Dim Objects As New List(Of Object)(Enumerable.Repeat(New Object, Date.Now.Day))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.