I am doing some work that involves automating MS MapPoint 2002. The
object model is documented in the context of Visual Basic 6.0. A
typical example follows.
'Output first result of find search
Set objFindResults = objApp.ActiveMa p.FindAddressRe sults("One Microsoft
Way", "Redmond", , "WA", , geoCountryUnite dStates)
MsgBox "The first item in the find list is: " _
+ objFindResults. Item(1).Name
FindResults is a collection. In C# I find that the VB6 syntax .Item (1)
is not acceptable nor is [1]. I don't know if it is acceptable in
VB.NET or not.
When MapPoint attempts to locate an input address it returns an
assessment of how well the results in the specified FindResult
collection match the input criteria, (e.g. geoFirstResultG ood,
geoAmbiguousRes ults, geoNoGoodResult ). Therefore if a complete and
unambiguous address is input the ResultsQuality property will be
geoFirstResultG ood, and I can …
IEnumerator frEnumerator = oFindResults.Ge tEnumerator();
frEnumerator.Mo veNext();
locX = (MapPoint.Locat ion) frEnumerator.Cu rrent;
listBox1.Items. Add( locX.Name );
listBox1.SetSel ected(0, true );
If one of the other ResultsQuality values is returned I can…
foreach (MapPoint.Locat ion locX in oFindResults)
{
listBox1.Items. Add( locX.Name );
}
If such an address is simply missing a North/South qualifier there will
only be two or three entries in the listBox. On the other hand, If the
address is 100 N Main St, Willburg, MA, 010907 where someone has
misspelled the city name and the Post Office has changed the zip code,
there can be several hundred items listed in listBox1 showing every 100
Main, City and Zip in Massachusetts. I have no problem with the time
required to LOAD the listBox. At this point I want to manually select
from listBox1 the location on which to perform further MapPoint
operations.
The only way I have been able to do this in C# has been to find the
index of the selected item in the listBox and then walk through the
collection AGAIN to reach the location object on which to perform the
further operations…
if ( listBox1.Select edIndex != -1 )
{
IEnumerator frEnumerator = oFindResults.Ge tEnumerator();
for ( int stepper = 0; stepper <= listBox1.Select edIndex; stepper++ )
frEnumerator.Mo veNext();
thisLocation = (MapPoint.Locat ion) frEnumerator.Cu rrent;
}
For the list containing several hundred items, walking the collection
again takes a perceptible amount of time on a fast CPU. It seems that
when I know the index of the item in the listBox I should be able to go
directly to the item in the collection rather than walking the
collection again. Is there a better way in C# that I have not found?
Gerald 9 8014
Gerald,
Very long question indeed. I'm assuming that your listBox1 is
System.Windows. Forms.ListBox, then you can access the selected item from C#
like this listBox1.Items[listBox1.Select edIndex]
Ron
"Gerald Lightsey" <gl********@cox .net> wrote in message
news:MP******** *************** *@msnews.micros oft.com... I am doing some work that involves automating MS MapPoint 2002. The object model is documented in the context of Visual Basic 6.0. A typical example follows.
'Output first result of find search Set objFindResults = objApp.ActiveMa p.FindAddressRe sults("One Microsoft Way", "Redmond", , "WA", , geoCountryUnite dStates) MsgBox "The first item in the find list is: " _ + objFindResults. Item(1).Name
FindResults is a collection. In C# I find that the VB6 syntax .Item (1) is not acceptable nor is [1]. I don't know if it is acceptable in VB.NET or not.
When MapPoint attempts to locate an input address it returns an assessment of how well the results in the specified FindResult collection match the input criteria, (e.g. geoFirstResultG ood, geoAmbiguousRes ults, geoNoGoodResult ). Therefore if a complete and unambiguous address is input the ResultsQuality property will be geoFirstResultG ood, and I can .
IEnumerator frEnumerator = oFindResults.Ge tEnumerator(); frEnumerator.Mo veNext(); locX = (MapPoint.Locat ion) frEnumerator.Cu rrent; listBox1.Items. Add( locX.Name ); listBox1.SetSel ected(0, true );
If one of the other ResultsQuality values is returned I can.
foreach (MapPoint.Locat ion locX in oFindResults) { listBox1.Items. Add( locX.Name ); }
If such an address is simply missing a North/South qualifier there will only be two or three entries in the listBox. On the other hand, If the address is 100 N Main St, Willburg, MA, 010907 where someone has misspelled the city name and the Post Office has changed the zip code, there can be several hundred items listed in listBox1 showing every 100 Main, City and Zip in Massachusetts. I have no problem with the time required to LOAD the listBox. At this point I want to manually select from listBox1 the location on which to perform further MapPoint operations.
The only way I have been able to do this in C# has been to find the index of the selected item in the listBox and then walk through the collection AGAIN to reach the location object on which to perform the further operations.
if ( listBox1.Select edIndex != -1 ) { IEnumerator frEnumerator = oFindResults.Ge tEnumerator(); for ( int stepper = 0; stepper <= listBox1.Select edIndex; stepper++ ) frEnumerator.Mo veNext(); thisLocation = (MapPoint.Locat ion) frEnumerator.Cu rrent; }
For the list containing several hundred items, walking the collection again takes a perceptible amount of time on a fast CPU. It seems that when I know the index of the item in the listBox I should be able to go directly to the item in the collection rather than walking the collection again. Is there a better way in C# that I have not found?
Gerald
On Sat, 26 Jul 2003 22:18:02 +0800, in the
microsoft.publi c.dotnet.langua ges.csharp group, Ron Bullman said... If I put[listBox1.Select edIndex] as a substitute for <your help needed here> or even [0] I get a compiler error that says, "Property, indexer, or event 'this' is not supported by the language; try directly calling accessor method 'MapPoint.FindR esults.get_item (ref object)' " I <snip>
Have you tried what the error message 'MapPoint.FindR esults.get_item (ref object)' suggest?
I must confess, I don't know or understand how to do that.
A MapPoint FindResults collection has five properties.
Application
Count
Item* (Default Property)
Parent
ResultsQuality
There is no get_item method in MapPoint that I can find nor is there one
listed in the .NET Framework Class Library that I have found.
Again, MapPoint help gives this example using VB6 syntax...
'Output first result of find search
Set objFindResults = objApp.ActiveMa p.FindAddressRe sults("One
Microsoft Way", "Redmond", , "WA", , geoCountryUnite dStates)
MsgBox "The first item in the find list is: " _
+ objFindResults. Item(1).Name
This all seems straight-forward initially. I program in dBASE and the
following dBASE command works beautifully to access a location item
directly out of a FindResults collection.
locX = oFindResults.It em(listbox1.ite mSelected)
It is only when I try to translate the command from VB6 or dBASE to C#
am I unable to get anything that will compile. Trying to handle it like
an array index, (i.e. [1] ), definitely will not work. Using Item(1)
like VB6 and dBASE tells the compiler I am trying to call a method which
it will not accept. Getting an enumerator or foreach both work but it
means I walk the collection once to lay it into a listBox and again
after dereferencing the listBox selected item.
There is supposed to be a new version of MapPoint out next month and I
hope that its documentation will use .NET syntax. Perhaps then it will
be clear how to do what I think I should be able to do in C#. In the
meantime, I just thought that it probably was a common occurrence for C#
programmers to translate VB6 syntax that uses an integer indexer into an
application's collection object such as objFindResults. Item(1). I was
hoping to learn the trick here.
Gerald
Gerald,
Are you using VS.NET? If so, could you check from the object browser if the
get_item is visible. If so, then use it.
Ron
"Gerald Lightsey" <gl********@cox .net> wrote in message
news:MP******** *************** *@msnews.micros oft.com... On Sat, 26 Jul 2003 22:18:02 +0800, in the microsoft.publi c.dotnet.langua ges.csharp group, Ron Bullman said...
If I put[listBox1.Select edIndex] as a substitute for <your help
needed here> or even [0] I get a compiler error that says, "Property,
indexer, or event 'this' is not supported by the language; try directly calling accessor method 'MapPoint.FindR esults.get_item (ref object)' " I <snip>
Have you tried what the error message 'MapPoint.FindR esults.get_item (ref object)' suggest?
I must confess, I don't know or understand how to do that.
A MapPoint FindResults collection has five properties. Application Count Item* (Default Property) Parent ResultsQuality
There is no get_item method in MapPoint that I can find nor is there one listed in the .NET Framework Class Library that I have found.
Again, MapPoint help gives this example using VB6 syntax...
'Output first result of find search Set objFindResults = objApp.ActiveMa p.FindAddressRe sults("One Microsoft Way", "Redmond", , "WA", , geoCountryUnite dStates) MsgBox "The first item in the find list is: " _ + objFindResults. Item(1).Name
This all seems straight-forward initially. I program in dBASE and the following dBASE command works beautifully to access a location item directly out of a FindResults collection.
locX = oFindResults.It em(listbox1.ite mSelected)
It is only when I try to translate the command from VB6 or dBASE to C# am I unable to get anything that will compile. Trying to handle it like an array index, (i.e. [1] ), definitely will not work. Using Item(1) like VB6 and dBASE tells the compiler I am trying to call a method which it will not accept. Getting an enumerator or foreach both work but it means I walk the collection once to lay it into a listBox and again after dereferencing the listBox selected item.
There is supposed to be a new version of MapPoint out next month and I hope that its documentation will use .NET syntax. Perhaps then it will be clear how to do what I think I should be able to do in C#. In the meantime, I just thought that it probably was a common occurrence for C# programmers to translate VB6 syntax that uses an integer indexer into an application's collection object such as objFindResults. Item(1). I was hoping to learn the trick here.
Gerald
On Sat, 26 Jul 2003 22:18:02 +0800, in the
microsoft.publi c.dotnet.langua ges.csharp group, Ron Bullman said... Gerald,
<sinp> If I put[listBox1.Select edIndex] as a substitute for <your help needed here> or even [0] I get a compiler error that says, "Property, indexer, or event 'this' is not supported by the language; try directly calling accessor method 'MapPoint.FindR esults.get_item (ref object)' " I <snip>
Have you tried what the error message 'MapPoint.FindR esults.get_item (ref object)' suggest?
I can't find anywhere get_Item() is actually surfaced and I didn't
understand the implications of the error message. But I found a
previous article dated 7/16/03 from Nicholas Paldino to a similar
question that helped.
He said,
quote
The reason this is happening is that the signature of your methods on
the COM server are taking variants by reference, which translates to
object by reference. Because of this, you have to pass in the exact
type when passing ref parameters. To do this, you will want to use:"
// Create a dummy object for the index.
object pobjIndex = 0;
// Reference the item.
iDrs.Item( ref pobjIndex).Item ( ref pobjIndex);
endquote
For my particular problem this translated to...
// listBox.Selecte dIndex zero based vs Colletions ones based
object lbIndex = listBox1.Select edIndex +1;
XLocation = (MapPoint.Locat ion) oFindResults.ge t_Item( ref lbIndex );
This compiles and in operation picks an item out of a large collection
instantly rather than iterating through it.
Thanks for your input.
Gerald
On Sat, 26 Jul 2003 22:18:02 +0800, in the
microsoft.publi c.dotnet.langua ges.csharp group, Ron Bullman said... Gerald,
<sinp> If I put[listBox1.Select edIndex] as a substitute for <your help needed here> or even [0] I get a compiler error that says, "Property, indexer, or event 'this' is not supported by the language; try directly calling accessor method 'MapPoint.FindR esults.get_item (ref object)' " I <snip>
Have you tried what the error message 'MapPoint.FindR esults.get_item (ref object)' suggest?
I can't find anywhere get_Item() is actually surfaced and I didn't
understand the implications of the error message. But I found a
previous article dated 7/16/03 from Nicholas Paldino to a similar
question that helped.
He said,
quote
The reason this is happening is that the signature of your methods on
the COM server are taking variants by reference, which translates to
object by reference. Because of this, you have to pass in the exact
type when passing ref parameters. To do this, you will want to use:"
// Create a dummy object for the index.
object pobjIndex = 0;
// Reference the item.
iDrs.Item( ref pobjIndex).Item ( ref pobjIndex);
endquote
For my particular problem this translated to...
// listBox.Selecte dIndex zero based vs Colletions ones based
object lbIndex = listBox1.Select edIndex +1;
XLocation = (MapPoint.Locat ion) oFindResults.ge t_Item( ref lbIndex );
This compiles and in operation picks an item out of a large collection
instantly rather than iterating through it.
Thanks for your input.
Gerald
Gerald,
It's good that you managed to solve your problem.
<snip> I can't find anywhere get_Item() is actually surfaced and I didn't
With surfaced you mean that it won't show in the object browser? But the
compiler will recognize it! Perhaps the Interop NG could provide more
details if needed.
Ron
Gerald,
It's good that you managed to solve your problem.
<snip> I can't find anywhere get_Item() is actually surfaced and I didn't
With surfaced you mean that it won't show in the object browser? But the
compiler will recognize it! Perhaps the Interop NG could provide more
details if needed.
Ron
On Fri, 1 Aug 2003 23:53:30 +0800, in the
microsoft.publi c.dotnet.langua ges.csharp group, Ron Bullman said... I can't find anywhere get_Item() is actually surfaced and I didn't With surfaced you mean that it won't show in the object browser? But the compiler will recognize it! Perhaps the Interop NG could provide more details if needed.
No, get_Item() does not show up in the object browser. I have done a
bit more searching around the documentation and find that property
access method names starting with get_ and put_ are commonly used in
older applications set up for automation.
A MapPoint FindResults collection has a default property named Item
which some languages, (e.g. dBASE which I have used successfully and
VB6), can address directly. Trying to directly address the Item
property in C# results in nothing but compiler failures but get_Item
pops up in a compiler error message as an alternative if one has a clue
what to do with it. I'm happy to have found out how to do specifically
what I wanted and feel I have learned quite a lot in the process.
Again thanks for your input.
Gerald
On Fri, 1 Aug 2003 23:53:30 +0800, in the
microsoft.publi c.dotnet.langua ges.csharp group, Ron Bullman said... I can't find anywhere get_Item() is actually surfaced and I didn't With surfaced you mean that it won't show in the object browser? But the compiler will recognize it! Perhaps the Interop NG could provide more details if needed.
No, get_Item() does not show up in the object browser. I have done a
bit more searching around the documentation and find that property
access method names starting with get_ and put_ are commonly used in
older applications set up for automation.
A MapPoint FindResults collection has a default property named Item
which some languages, (e.g. dBASE which I have used successfully and
VB6), can address directly. Trying to directly address the Item
property in C# results in nothing but compiler failures but get_Item
pops up in a compiler error message as an alternative if one has a clue
what to do with it. I'm happy to have found out how to do specifically
what I wanted and feel I have learned quite a lot in the process.
Again thanks for your input.
Gerald This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Marc L'Ecuyer |
last post by:
Hi,
I have a collection class derived from CollectionBase. This collection can
add items of my class MyItem. In my class MyItem, I have a Selected
property. When this property is set to true, I have to set this property to
false for all other items in the collection (only 1 item can be selected).
How can I do that?
Thanks
|
by: ck |
last post by:
Sorry for the cross post.
What is wrong with this code?--ado recordset to populate a collection--see
reason below
Dim myCol2 As New Collection
On Error Resume Next
Do While Not rs.EOF
myCol2.Add rs!Email, rs!Email
rs.MoveNext
Loop
|
by: juli |
last post by:
I have strings variables in a collection list and I want to create new
collection but to add to it only strings that are distinct (no common
strings).
For example I have an object sentense which is the base for a
collection and there are words in it and I want to create a new
collection of sentenses where there is no similar secound word in
those sentenses.
How do I do this distinct selection from a collection of object?
Thanks!
|
by: Josema |
last post by:
Hi,
My problem is the next one (in a windows application):
- I have a class derived from collectionbase to fill with persons object
(id, name) from database.
- I have a ListBox wich datasource its the collectionbase above.
I want to do:
- I would like that when i click in a item of the listbox, deletes from
database the values of this item, and from collection too. Then refresh the
listbox with the collection modified.
|
by: jason |
last post by:
Hello. I've got this simple collection populate code I downloaded from
the net (sorry can't find source now) I'm trying to test, but I can't
seem to get it to work. Any help would be greatly appreciated.
I've compiled the following VB.NET into a DLL:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections
| |
by: Michael K. Walter |
last post by:
I'd like to create a strongly-typed collection of objects that are indexed
by a string value (key is a string). I'd also like to allow users to iterate
over the collection using a For-each loop where an object of the contained
type is returned (instead of just the standard DictionaryEntry object).
- only allow objects of type MyObj to be added to the collection
- return a MyObj type in the For-each loop
What's the best way to do this?
|
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: Rich |
last post by:
Yes, I need to store some values in an array type collection object that can
hold 3 or more parameters per index. I have looked at the collection object,
hashtable object and would prefer not to hassel with a multi-dimensional
array. Is there such an object in VB.Net?
Dim obj As someCollectionObj
obj.Add("parmA1", "parmA2", "parmA3")
obj.Add("parmB1", "parmB2", "parmB3")
....
|
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |