In VB 6, the loop iterator v in the following code must be a variant.
dim v as variant
dim c as new collection
for each v in collection
...
next v
What is the general translation in VB 7.1 and VB 8 Beta 1? Also, is there
an easy way to force "v" to be an early bound variable. In VB 6 this can be
done by going through the rather convoluted creation of a collection class
that implements the _IEnum interface.
Thanks,
Mike Ober 6 4834
* "Michael D. Ober" <mdo.@.wakeasso c..com> scripsit: In VB 6, the loop iterator v in the following code must be a variant.
dim v as variant dim c as new collection for each v in collection ... next v
What is the general translation in VB 7.1 and VB 8 Beta 1?
You can use the items' type directly in VB.NET.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
"Michael D. Ober" <mdo.@.wakeasso c..com> wrote in message
news:%2******** *********@TK2MS FTNGP09.phx.gbl ... In VB 6, the loop iterator v in the following code must be a variant.
dim v as variant dim c as new collection for each v in collection ... next v
Collection is by default non-typed (using type Object). If you were to use
a different type of collection, such as a Specialized.Str ingCollection, then
yes. For example:
'// .NET 1.1: Using a weak-typed Collection:
Dim C as New Collection
Dim strItem as String
....
For each V as Object In C
Debug.WriteLine DirectCast(V, String)
Next
'// .NET 1.1: Using a specialized collection:
Dim C as New Collections.Spe cialized.String Collection
....
For each ThisString as String In C
Debug.WriteLine ThisString
Next
'// .NET 2: Use generics
Dim C as New Generics.Collec tion(Of String)
For Each ThisString as String in C
Debug.WriteLine ThisString
Next
HTH,
Jeremy
Thanks Jeremy. That's exactly the information I needed.
Mike Ober.
"Jeremy" <th***********@ hotmail.com> wrote in message
news:JO******** **********@twis ter.tampabay.rr .com... "Michael D. Ober" <mdo.@.wakeasso c..com> wrote in message news:%2******** *********@TK2MS FTNGP09.phx.gbl ... In VB 6, the loop iterator v in the following code must be a variant.
dim v as variant dim c as new collection for each v in collection ... next v
Collection is by default non-typed (using type Object). If you were to
use a different type of collection, such as a Specialized.Str ingCollection,
then yes. For example:
'// .NET 1.1: Using a weak-typed Collection: Dim C as New Collection Dim strItem as String ... For each V as Object In C Debug.WriteLine DirectCast(V, String) Next '// .NET 1.1: Using a specialized collection: Dim C as New Collections.Spe cialized.String Collection ... For each ThisString as String In C Debug.WriteLine ThisString Next '// .NET 2: Use generics Dim C as New Generics.Collec tion(Of String)
For Each ThisString as String in C Debug.WriteLine ThisString Next
HTH, Jeremy
Jeremy (& Michael),
You do realize that if your weak-typed collection only contains strings you
can do: '// .NET 1.1: Using a weak-typed Collection: Dim C as New Collection For each strItem as String In C Debug.WriteLine strItem Next
The For Each will do the DirectCast for you!
Which also means that if C contains something other then a String, you will
get an InvalidCastExce ption!
Hope this helps
Jay
"Jeremy" <th***********@ hotmail.com> wrote in message
news:JO******** **********@twis ter.tampabay.rr .com... "Michael D. Ober" <mdo.@.wakeasso c..com> wrote in message news:%2******** *********@TK2MS FTNGP09.phx.gbl ... In VB 6, the loop iterator v in the following code must be a variant.
dim v as variant dim c as new collection for each v in collection ... next v
Collection is by default non-typed (using type Object). If you were to
use a different type of collection, such as a Specialized.Str ingCollection,
then yes. For example:
'// .NET 1.1: Using a weak-typed Collection: Dim C as New Collection Dim strItem as String ... For each V as Object In C Debug.WriteLine DirectCast(V, String) Next '// .NET 1.1: Using a specialized collection: Dim C as New Collections.Spe cialized.String Collection ... For each ThisString as String In C Debug.WriteLine ThisString Next '// .NET 2: Use generics Dim C as New Generics.Collec tion(Of String)
For Each ThisString as String in C Debug.WriteLine ThisString Next
HTH, Jeremy
Frequently they are simply strings, but there are a signficant number of
cases where I use
for each v in c
set obj = v
...
next v
It appears that this will become
for each obj as objclass in c
...
next obj
This is probably the one area that I absolutely hate about VB 6 - collection
iterators always require variants.
Mike Ober.
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:OJ******** ******@tk2msftn gp13.phx.gbl... Jeremy (& Michael), You do realize that if your weak-typed collection only contains strings
you can do:
'// .NET 1.1: Using a weak-typed Collection: Dim C as New Collection For each strItem as String In C Debug.WriteLine strItem Next The For Each will do the DirectCast for you!
Which also means that if C contains something other then a String, you
will get an InvalidCastExce ption!
Hope this helps Jay
"Jeremy" <th***********@ hotmail.com> wrote in message news:JO******** **********@twis ter.tampabay.rr .com... "Michael D. Ober" <mdo.@.wakeasso c..com> wrote in message news:%2******** *********@TK2MS FTNGP09.phx.gbl ... In VB 6, the loop iterator v in the following code must be a variant.
dim v as variant dim c as new collection for each v in collection ... next v
Collection is by default non-typed (using type Object). If you were to use a different type of collection, such as a Specialized.Str ingCollection, then yes. For example:
'// .NET 1.1: Using a weak-typed Collection: Dim C as New Collection Dim strItem as String ... For each V as Object In C Debug.WriteLine DirectCast(V, String) Next '// .NET 1.1: Using a specialized collection: Dim C as New Collections.Spe cialized.String Collection ... For each ThisString as String In C Debug.WriteLine ThisString Next '// .NET 2: Use generics Dim C as New Generics.Collec tion(Of String)
For Each ThisString as String in C Debug.WriteLine ThisString Next
HTH, Jeremy
Michael, It appears that this will become
for each obj as objclass in c
Correct the 'variable' that you are using with the For Each can be strongly
typed to the actual type in the collection! Even when you have a collection
of objects, such as VB.Collection & ArrayList.
VB.NET will do a DirectCast to the type of the variable for you.
This is probably the one area that I absolutely hate about VB 6 -
collection iterators always require variants.
I "hate" the fact that VB6 doesn't have constructors more, but yes, now that
you reminded me, this one is way up there also.
Hope this helps
Jay
"Michael D. Ober" <mdo.@.wakeasso c..com> wrote in message
news:Og******** ******@TK2MSFTN GP10.phx.gbl... Frequently they are simply strings, but there are a signficant number of cases where I use
for each v in c set obj = v ... next v
It appears that this will become
for each obj as objclass in c ... next obj
This is probably the one area that I absolutely hate about VB 6 -
collection iterators always require variants.
Mike Ober.
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message news:OJ******** ******@tk2msftn gp13.phx.gbl... Jeremy (& Michael), You do realize that if your weak-typed collection only contains strings you can do:
'// .NET 1.1: Using a weak-typed Collection: Dim C as New Collection For each strItem as String In C Debug.WriteLine strItem Next
The For Each will do the DirectCast for you!
Which also means that if C contains something other then a String, you will get an InvalidCastExce ption!
Hope this helps Jay
"Jeremy" <th***********@ hotmail.com> wrote in message news:JO******** **********@twis ter.tampabay.rr .com... "Michael D. Ober" <mdo.@.wakeasso c..com> wrote in message news:%2******** *********@TK2MS FTNGP09.phx.gbl ... > In VB 6, the loop iterator v in the following code must be a
variant. > > dim v as variant > dim c as new collection > for each v in collection > ... > next v
Collection is by default non-typed (using type Object). If you were
to use a different type of collection, such as a
Specialized.Str ingCollection, then yes. For example:
'// .NET 1.1: Using a weak-typed Collection: Dim C as New Collection Dim strItem as String ... For each V as Object In C Debug.WriteLine DirectCast(V, String) Next '// .NET 1.1: Using a specialized collection: Dim C as New Collections.Spe cialized.String Collection ... For each ThisString as String In C Debug.WriteLine ThisString Next '// .NET 2: Use generics Dim C as New Generics.Collec tion(Of String)
For Each ThisString as String in C Debug.WriteLine ThisString Next
HTH, Jeremy
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Generic Usenet Account |
last post by:
To settle the dispute regarding what happens when an "erase" method is
invoked on an STL container (i.e. whether the element is merely
removed from the container or whether it also gets deleted in the
process), I looked up the STL code. Erase certainly does not delete
the memory associated with the element. However, it appears that the
destructor on the element is invoked. I wonder why it has to be this
way. In my opinion, this renders...
|
by: Kurt Bauer |
last post by:
I have an ASP group calendar application which pulls calendar data from
Exchange via webdav into an XML string. I then loop the XML nodes to
populate a collection of appointments. Finally I use the appointment
collection to populate the calendar control. The performance getting the
XML data is fine, but loading the data into the collection is slow. My
question/problem is should I be using the collection, a dataset, or
something else to...
|
by: Scott |
last post by:
I have a collection where the items in the collection are dates. I want to
iterate over the collection and build a value list string for the rowsource
of a listbox. The dates in the collection are not in chronological order. Is
there a way to first sort the collection and put the dates in chronological
order before creating the value list string? Or, how would I iterate over
the collection pulling out the dates in chronological order?
...
|
by: Pavils Jurjans |
last post by:
Hello,
There's some confusion about the purpose and difference between these handy
classes...
First, both of them are holding number of key - value pairs, right? Then, I
see that there may be some difference in terms of data types allowed for
keys and values, perhaps?
I read the following in MSDN about "CollectionBase" class and
|
by: Brian |
last post by:
NOTE ALSO POSTED IN
microsoft.public.dotnet.framework.aspnet.buildingcontrols
I have solved most of my Server Control Collection property issues.
I wrote an HTML page that describes all of the problems that I have
encountered to date and the solutions (if any) that I found.
http://users.adelphia.net/~brianpclab/ServerControlCollectionIssues.htm
This page also has all of the source code in a compressed file that you are
free to download...
| |
by: Matt Michael |
last post by:
I have a listview control and a collection object right now that I'm trying
to pass information to and from. Whenever I click on the checkbox, I want
it to remove certain listview items and add them to the collection.
Whenever I uncheck the checkbox, I want to add the items back into the
listview from the collection, and remove them from the collection so I can
do the process multiple times. The listview tag is being used as a key, so
I...
|
by: Chet Cromer |
last post by:
I am creating a set of base classes and sub classes to use throughout a
program I'm developing. The base class represents a generic "lookup
table" from my database that contains lists of things like
manufacturers, makes, modes, etc. of cars. I have created a generic
"datacollection" class and a generic "dataobject" class to represent the
table and the rows within that table as a collection of objects with
generic properties for...
|
by: Scott M. Lyon |
last post by:
As I mentioned in my other post, I'm attempting to, using COM Interop so I
can update existing VB6 code to (for several specific functions) return a
Hashtable from a .NET library.
I've had very little luck processing the Hashtable itself in VB6 (I can add
a reference to the project so it knows what a Hashtable is, but I'm not
having much luck looping through all objects in the Hashtable), so I decided
to try a different idea.
|
by: Arthur Dent |
last post by:
How do you sort a generic collection derived from
System.Collections.ObjectModel.Collection?
Thanks in advance,
- Arthur Dent
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |