By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,451 Members | 981 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,451 IT Pros & Developers. It's quick & easy.

dynamically dimension an object

P: n/a
TJS
how can I dynamically dimension objects in a loop ?

trying to do something like this -but it doesn't compile

for i = 1 to 5
Dim "submenu" & i As New objectName_here
next

Compiler Error Message: BC30203: Identifier expected.
Nov 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hi TJS

That one is absolutely impossible, but i can suggest you can alternate way of doing in the same way, that is identifying the objects with some name

look at the following code

Dim ht As New Hashtable(
Dim i As Intege
For i = 0 To
ht.Add("Obj" & i, "" & i
Nex
MsgBox(CType(ht("Obj1"), String)

But remember the key is case sensitive

I hope that this could help u a little

Sadha Sivam
Microsoft Community Star
Malleable Minds Software Pvt Ltd., India
as******@yahoo.co

Nov 20 '05 #2

P: n/a
You could probably do this using the CodeDOM but it would be non-trivial.
Have you thought about using an array (or a collection) like:

Dim a(4) As objectName
For i As Integer = 0 to 4
a(i) = New objectName(...)
Next

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
"TJS" <no****@here.com> wrote in message
news:O3**************@tk2msftngp13.phx.gbl...
how can I dynamically dimension objects in a loop ?

trying to do something like this -but it doesn't compile

for i = 1 to 5
Dim "submenu" & i As New objectName_here
next

Compiler Error Message: BC30203: Identifier expected.

Nov 20 '05 #3

P: n/a
Hi TJS,

Before you get confuse, although the one from Rob is simpler, I would try
the sample TJS did give you. When you only reference them by index you can
also use the arraylist as an alternative, however the sample from TJS is
better in my opinion.

Just to help you choose.

Cor
Nov 20 '05 #4

P: n/a
TJS
I tried your suggestion but it does not allow me to convert object to a
string

"Rob Windsor [MVP]" <rw******@NO.MORE.SPAM.bigfoot.com> wrote in message
news:ux**************@tk2msftngp13.phx.gbl...
You could probably do this using the CodeDOM but it would be non-trivial.
Have you thought about using an array (or a collection) like:

Dim a(4) As objectName
For i As Integer = 0 to 4
a(i) = New objectName(...)
Next

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
"TJS" <no****@here.com> wrote in message
news:O3**************@tk2msftngp13.phx.gbl...
how can I dynamically dimension objects in a loop ?

trying to do something like this -but it doesn't compile

for i = 1 to 5
Dim "submenu" & i As New objectName_here
next

Compiler Error Message: BC30203: Identifier expected.


Nov 20 '05 #5

P: n/a
TJS
how do I set this to an object ?
"Sadha Sivam S" <as******@yahoo.com> wrote in message
news:08**********************************@microsof t.com...
Hi TJS,

That one is absolutely impossible, but i can suggest you can alternate way of doing in the same way, that is identifying the objects with some name.
look at the following code.

Dim ht As New Hashtable()
Dim i As Integer
For i = 0 To 5
ht.Add("Obj" & i, "" & i)
Next
MsgBox(CType(ht("Obj1"), String))

But remember the key is case sensitive.

I hope that this could help u a little.

Sadha Sivam S
Microsoft Community Star,
Malleable Minds Software Pvt Ltd., India,
as******@yahoo.com

Nov 20 '05 #6

P: n/a
* "TJS" <no****@here.com> scripsit:
I tried your suggestion but it does not allow me to convert object to a
string


?!?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #7

P: n/a
I'm sorry, I don't know what you mean by this statement.

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
"TJS" <no****@here.com> wrote in message
news:OX**************@TK2MSFTNGP09.phx.gbl...
I tried your suggestion but it does not allow me to convert object to a
string

"Rob Windsor [MVP]" <rw******@NO.MORE.SPAM.bigfoot.com> wrote in message
news:ux**************@tk2msftngp13.phx.gbl...
You could probably do this using the CodeDOM but it would be non-trivial. Have you thought about using an array (or a collection) like:

Dim a(4) As objectName
For i As Integer = 0 to 4
a(i) = New objectName(...)
Next

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
"TJS" <no****@here.com> wrote in message
news:O3**************@tk2msftngp13.phx.gbl...
how can I dynamically dimension objects in a loop ?

trying to do something like this -but it doesn't compile

for i = 1 to 5
Dim "submenu" & i As New objectName_here
next

Compiler Error Message: BC30203: Identifier expected.



Nov 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.