|
-
Sep 21st, 2003, 02:15 PM
#1
Thread Starter
Frenzied Member
for each i as (object here) or for each i in (form here)
i cant seem to get either of these two vb6 commands correctly
VB Code:
dim i as popbox
for each i in frmmain ' where frmmain is the form i am on
'do something with object here
next i
' and
dim i as object
for each i as popbox ' where popbox is a usercontroll in the current form
'do something with object here
next i
so what is the proper Vb.net way to loop through a certain kind of object and do something with it?
-
Sep 21st, 2003, 02:55 PM
#2
Hyperactive Member
You have to look at the controls collection of the object that you want to loop though...
VB Code:
Dim oO As Object
For Each oO In Me.Controls
msgBox(oO.id)
Next
HTH
Cheers
MarkusJ
-
Sep 21st, 2003, 02:58 PM
#3
Thread Starter
Frenzied Member
ok getting closer though i only want the controls that are "made" from the popbox control... there named popbox1 popbox2 etc etc :S
Dim i As Popbox
For Each i In Me.Controls
i.color_deselect()
Next i
doesnt seem to work though :S
An unhandled exception of type 'System.InvalidCastException' occurred in pop3 checker pro.net.exe
Additional information: Specified cast is not valid.
-
Sep 22nd, 2003, 03:36 AM
#4
Hyperactive Member
Hi, you have to test the type of control in the collection and depending on what it is (popup in your case) do something...
Two ways would be to test either then name of the control (All your controls that you want to check are called popup) or test the control type..
The following is off the top of my head so beware the bugs 
VB Code:
Dim i As object
For Each i In Me.Controls
' Check the name. If the name of the control is popup then it is one of your controls...
if i.id.toString.toLower.indexof("popup") then
i.color_deselect()
end if
Next i
' you could also check the type of the control. Syntax below is probably wrong but you get the idea
if i.getType = popup then
i.color_deselect()
end if
'Finally you could just do an error catch <shady crap programmer grin>
Dim i As object
For Each i In Me.Controls
try
ii.color_deselect()
catch
end try
Next i
hth
Cheers
MarkusJ
-
Sep 22nd, 2003, 07:27 AM
#5
Fanatic Member
dont know if this wil help
Over the weekend ive been messing with my old vb program i started ages ago and never got around to finishing it
there was loads of unsupported vb6 commands in my code which i really really needed to use so i just added this to import list
Imports vb = Microsoft.visualbasic
then if you need to access an old vb6 function then just use this
vb.Left(blah,1)
I guess this is not the correct way to do things but when your stressed out about finding how to do it and you know how vb6 done it, its a good alternative
Hope it helps
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
-
Sep 22nd, 2003, 08:29 AM
#6
Addicted Member
In VB.NET 2003, you can do this in a neater way:
VB Code:
For Each textBoxControl as TextBox in Me.Controls
Console.WriteLine textBoxControl.Name
Next
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
|