-
August 11th, 2005, 08:36 AM
#1
better code
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.)
-
August 11th, 2005, 08:56 AM
#2
Re: better code
Originally Posted by Darbujan
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?
Code:
Dim o(2) As Object 'whatever datatype
Dim LoopCount As Integer
For LoopCount = 0 To UBound(o)
o(LoopCount).property = 100
Next LoopCount
-
August 11th, 2005, 09:33 AM
#3
Re: better code
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 bject variable or width blockvariable not set
-
August 11th, 2005, 10:47 AM
#4
Re: better code
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
-
August 11th, 2005, 12:55 PM
#5
Re: better code
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
-
August 11th, 2005, 03:25 PM
#6
Re: better code
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)
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|