I have my ugly code:
dim o1, o2, o3,... as object
object1.property = 100
object2.property = 100
...
How I make it better,
for example by array object?
(I am beginner.)
Printable View
I have my ugly code:
dim o1, o2, o3,... as object
object1.property = 100
object2.property = 100
...
How I make it better,
for example by array object?
(I am beginner.)
What are you trying to do?Quote:
Originally Posted by Darbujan
Code:Dim o(2) As Object 'whatever datatype
Dim LoopCount As Integer
For LoopCount = 0 To UBound(o)
o(LoopCount).property = 100
Next LoopCount
I will be exatly. I do somewhere error.
...
Set ie1 = CreateObject("InternetExplorer.Application")
ie1.navigate address1
Set ie2 = CreateObject("InternetExplorer.Application")
ie2.navigate address2
...
ie1.visible= true
ie2.visible=true
...
if write this:
...
Dim ie(2) As Object 'whatever datatype
Dim i As Integer
For i = 0 To UBound(ie)
ie(i).Visible = True
Next i
...
=>runtime error 91 :object variable or width blockvariable not set
You are just decalring the Object but you are not Instantiating it. You also need to instantiate the object either using a New Keyword or the CreateObject function
Something like this
Code:Dim ie(2) As Object 'whatever datatype
Dim i As Integer
Set ie(0) = New WhatEverObject
Set ie(1) = New WhatEverObject
For i = 0 To UBound(ie)
ie(i).Visible = True
Next i
Code:Dim ie(2) As Object 'whatever datatype
Dim i As Integer
For i = 0 To UBound(ie)
Set ie(i) = CreateObject("InternetExplorer.Application")
ie(i).navigate address2
ie(i).Visible = True
Next i
One side note...
When declaring multiple variables of a specific type, you cannot declare the type only at the end of the line. The type of each variable must be specified, otherwise you'll end up with Variants.
In other words, do NOT do this:
Dim A, B, C As String
DO this:
Dim A As String, B As String, C As String
or
Dim A$, B$, C$
(The "$" is the type declaration character for a string)