473,473 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Wrong function bound?

Hello - I have a project in VB.NET (framework version 1.1), in which I use
the function InStr in the following form:
Public Function InStr(ByVal String1 As String, ByVal String2 As String,
Optional ByVal Compare As Microsoft.VisualBasic.CompareMethod = 0) As
Integer

(which is what Intellisense prompts), rather than the form:
Public Function InStr(ByVal Start As Integer, ByVal String1 As String, ByVal
String2 As String, Optional ByVal Compare As
Microsoft.VisualBasic.CompareMethod = 0) As Integer

Note that the form used omits the optional Start parameter. (Intellisense
does not prompt for inclusion of the Start param, even for a null followed
by a comma; and Microsoft.VisualBasic.dll documents both forms.) However, I
have a user (only one reported out of thousands), who get an exception
dialogue, with the error message including:
System.ArgumentException: Argument 'Start' must be greater or equal to zero.

at Microsoft.VisualBasic.Strings.InStr(Int32 Start, String String1,
String String2, CompareMethod Compare)

at Scenery_Align.mainForm.extractPath(String rawPath)

at Scenery_Align.mainForm.findOpenWithApp(String appName)

at Scenery_Align.mainForm.ButtonOpen_Click(Object sender, EventArgs e)

....the two red lines would seem to indicate that the wrong version of the
function is called. I have many installations where this is not the case,
they work just fine. He had a version of the .NET framework installed that
was earlier than mine, but I had him re-install the latest so his
Microsoft.VisualBasic.dll is version v7.10.6001.4, same as mine.

Anyone know why this would occur, and what I can do to make it work properly
in all cases?

Thanks -- Dick Bixler


Nov 21 '05 #1
10 1483
Richard,
Not sure what to suggest on your problem. I suspect you are passing in an
invalid starting position as the expression states. The user causing the
problem may be entering the value slightly differently then the others,
causing a problem.

| at Scenery_Align.mainForm.extractPath(String rawPath)
extractPath suggests to me that you are parsing a file path. I would
recommend rather then write your own routines to parse a file path, that you
use the methods of System.IO.Path to extract the various parts of a path.

Hope this helps
Jay

"Richard Bixler" <ne******@earthlink.net> wrote in message
news:Oh**************@TK2MSFTNGP11.phx.gbl...
| Hello - I have a project in VB.NET (framework version 1.1), in which I use
| the function InStr in the following form:
| Public Function InStr(ByVal String1 As String, ByVal String2 As String,
| Optional ByVal Compare As Microsoft.VisualBasic.CompareMethod = 0) As
| Integer
|
| (which is what Intellisense prompts), rather than the form:
| Public Function InStr(ByVal Start As Integer, ByVal String1 As String,
ByVal
| String2 As String, Optional ByVal Compare As
| Microsoft.VisualBasic.CompareMethod = 0) As Integer
|
| Note that the form used omits the optional Start parameter. (Intellisense
| does not prompt for inclusion of the Start param, even for a null followed
| by a comma; and Microsoft.VisualBasic.dll documents both forms.) However,
I
| have a user (only one reported out of thousands), who get an exception
| dialogue, with the error message including:
| System.ArgumentException: Argument 'Start' must be greater or equal to
zero.
|
| at Microsoft.VisualBasic.Strings.InStr(Int32 Start, String String1,
| String String2, CompareMethod Compare)
|
| at Scenery_Align.mainForm.extractPath(String rawPath)
|
| at Scenery_Align.mainForm.findOpenWithApp(String appName)
|
| at Scenery_Align.mainForm.ButtonOpen_Click(Object sender, EventArgs e)
|
| ...the two red lines would seem to indicate that the wrong version of the
| function is called. I have many installations where this is not the case,
| they work just fine. He had a version of the .NET framework installed that
| was earlier than mine, but I had him re-install the latest so his
| Microsoft.VisualBasic.dll is version v7.10.6001.4, same as mine.
|
| Anyone know why this would occur, and what I can do to make it work
properly
| in all cases?
|
| Thanks -- Dick Bixler
|
|
|
|
Nov 21 '05 #2
On 2005-09-04, Richard Bixler <ne******@earthlink.net> wrote:
Hello - I have a project in VB.NET (framework version 1.1), in which I use
the function InStr in the following form:
Public Function InStr(ByVal String1 As String, ByVal String2 As String,
Optional ByVal Compare As Microsoft.VisualBasic.CompareMethod = 0) As
Integer


Why don't you post the exact line of code that is getting the error?

Ditto what Jay said about IO.Path.

Also, if a single user really is getting the overloadeded function, that
probably means you have option strict off. With Option strict, the
overload is always chosen at compile time. Could that be so?
Nov 21 '05 #3
Hello, and thanks.

First, function header followed by line that barfs:

Private Function extractPath(ByVal rawPath As String) As String

.... (removes preceding chars including a leftmost quote mark)

Barfs--> If InStr(rawPath, Chr(37),
Microsoft.VisualBasic.CompareMethod.Text) > 0 Then _

rawPath = Trim(Microsoft.VisualBasic.Left(rawPath, InStr(rawPath, Chr(37),
Microsoft.VisualBasic.CompareMethod.Text) - 1))

The variable "rawPath" is returned from
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Applications\w ordpad.exe\shell\open\command,
and its value is "%ProgramFiles%\Windows NT\Accessories\WORDPAD.EXE" "%1"
including the quotes as part of the string. I'm converting this to a string
to pass to pass to Microsoft.VisualBasic.Shell, the form will ultimately be
C:\Program Files\Windows NT\Accessories\WORDPAD.EXE
D:\PROGRA~1\MICROS~1\FLIGHT~1\scenery.cfg

You're right about option strict. I'll have to fix up some implicit
conversions to turn it on... I should do that (and will), but in the
interest of responding quickly to the user, will that make a difference in
choosing the proper overload when executed on his specific installation?

Thanks again -- Dick Bixler

"dfoster" <df*****@woofix.local.dom> wrote in message
news:sl********************@localhost.localdomain. ..
On 2005-09-04, Richard Bixler <ne******@earthlink.net> wrote:
Hello - I have a project in VB.NET (framework version 1.1), in which I
use
the function InStr in the following form:
Public Function InStr(ByVal String1 As String, ByVal String2 As String,
Optional ByVal Compare As Microsoft.VisualBasic.CompareMethod = 0) As
Integer


Why don't you post the exact line of code that is getting the error?

Ditto what Jay said about IO.Path.

Also, if a single user really is getting the overloadeded function, that
probably means you have option strict off. With Option strict, the
overload is always chosen at compile time. Could that be so?

Nov 21 '05 #4
Thanks, Jay. Actually, I didn't specify a starting position since I used the
form of the function that didn't require one (assumes start of string). (You
have to show hidden functions in the .Net IDE object browser, I probably
used an old form in code I carried forward). The problem is that there are
two function signatures documented, one that does require a starting
position and one that doesn't, and that in the case of this user the wrong
one is called (and therefore mis-interprets parameters from the call). I
thought the compiler would determine the function signature, and cause the
correct function to be called at runtime. This does work for all but this
one user.

Thanks for the suggestion re System.IO.Path, I'll look into that. FYI, My
functions extractPath and findOpenWithApp take a path from a registry key
value "EXE Path", and the path string returned from the registry has quotes
and a call parameter that are not correct for my usage so I have to remove
or modify them - I'm finding a path to a registered app (WordPad is default
but user can specify another) and opening a file with it.

Thanks again. If the above prompts any further ideas, I'd still be
appreciative!

Dick Bixler

"Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> wrote in
message news:uD**************@TK2MSFTNGP10.phx.gbl...
Richard,
Not sure what to suggest on your problem. I suspect you are passing in an
invalid starting position as the expression states. The user causing the
problem may be entering the value slightly differently then the others,
causing a problem.

| at Scenery_Align.mainForm.extractPath(String rawPath)
extractPath suggests to me that you are parsing a file path. I would
recommend rather then write your own routines to parse a file path, that
you
use the methods of System.IO.Path to extract the various parts of a path.

Hope this helps
Jay

"Richard Bixler" <ne******@earthlink.net> wrote in message
news:Oh**************@TK2MSFTNGP11.phx.gbl...
| Hello - I have a project in VB.NET (framework version 1.1), in which I
use
| the function InStr in the following form:
| Public Function InStr(ByVal String1 As String, ByVal String2 As String,
| Optional ByVal Compare As Microsoft.VisualBasic.CompareMethod = 0) As
| Integer
|
| (which is what Intellisense prompts), rather than the form:
| Public Function InStr(ByVal Start As Integer, ByVal String1 As String,
ByVal
| String2 As String, Optional ByVal Compare As
| Microsoft.VisualBasic.CompareMethod = 0) As Integer
|
| Note that the form used omits the optional Start parameter.
(Intellisense
| does not prompt for inclusion of the Start param, even for a null
followed
| by a comma; and Microsoft.VisualBasic.dll documents both forms.)
However,
I
| have a user (only one reported out of thousands), who get an exception
| dialogue, with the error message including:
| System.ArgumentException: Argument 'Start' must be greater or equal to
zero.
|
| at Microsoft.VisualBasic.Strings.InStr(Int32 Start, String String1,
| String String2, CompareMethod Compare)
|
| at Scenery_Align.mainForm.extractPath(String rawPath)
|
| at Scenery_Align.mainForm.findOpenWithApp(String appName)
|
| at Scenery_Align.mainForm.ButtonOpen_Click(Object sender, EventArgs e)
|
| ...the two red lines would seem to indicate that the wrong version of
the
| function is called. I have many installations where this is not the
case,
| they work just fine. He had a version of the .NET framework installed
that
| was earlier than mine, but I had him re-install the latest so his
| Microsoft.VisualBasic.dll is version v7.10.6001.4, same as mine.
|
| Anyone know why this would occur, and what I can do to make it work
properly
| in all cases?
|
| Thanks -- Dick Bixler
|
|
|
|

Nov 21 '05 #5
On 2005-09-05, Richard Bixler <ne******@earthlink.net> wrote:
You're right about option strict. I'll have to fix up some implicit
conversions to turn it on... I should do that (and will), but in the
interest of responding quickly to the user, will that make a difference in
choosing the proper overload when executed on his specific installation?
Yep. With strict on, the overload is chosen when you compile the
project, so it's impossible for a different overload to be called at
runtime.

For the other, unfortunately VB with strict off is really a completely
different language than VB with strict on, and it's a language I just
don't know very well. From a glance, I don't see how you're getting the
wrong overload instead of an AmbiguousReferenceException. Hopefully
somebody else has some answers.


Thanks again -- Dick Bixler

"dfoster" <df*****@woofix.local.dom> wrote in message
news:sl********************@localhost.localdomain. ..
On 2005-09-04, Richard Bixler <ne******@earthlink.net> wrote:
Hello - I have a project in VB.NET (framework version 1.1), in which I
use
the function InStr in the following form:
Public Function InStr(ByVal String1 As String, ByVal String2 As String,
Optional ByVal Compare As Microsoft.VisualBasic.CompareMethod = 0) As
Integer


Why don't you post the exact line of code that is getting the error?

Ditto what Jay said about IO.Path.

Also, if a single user really is getting the overloadeded function, that
probably means you have option strict off. With Option strict, the
overload is always chosen at compile time. Could that be so?


Nov 21 '05 #6
Richard,
The following blog entry talks about how Option Strict Off (late-bound
behavior) can be different then Option Strict On (early-bound behavior).

http://www.panopticoncentral.net/arc.../02/10428.aspx

Can you use ILDASM.EXE to see what the IL code on the line that is failing
is? Can you post the 10 to 15 lines of IL for the code you posted below? As
far as I can tell it is calling the InStr you expect...

Can you add code to see explicitly what rawPath is when it blows up? Can you
include other pertinent variables?

For example, add a Try/Catch around the routine & include rawPath & other
pertinent info in a new exception that you throw?

| Private Function extractPath(ByVal rawPath As String) As String

Try

|
| ... (removes preceding chars including a leftmost quote mark)
|
| Barfs--> If InStr(rawPath, Chr(37),
| Microsoft.VisualBasic.CompareMethod.Text) > 0 Then _
|
| rawPath = Trim(Microsoft.VisualBasic.Left(rawPath, InStr(rawPath, Chr(37),
| Microsoft.VisualBasic.CompareMethod.Text) - 1))

Return ...
Catch ex As Exception
Throw New ExtractPathException("rawPath", rawPath)
End Try
End Function

Then let you global exception handlers log the exception & hopefully useful
information...

As dfoster suggests, I normally run with Option Strict On, except in cases
where Option Strict Off is beneficial, such as COM interop with COM object
that have variants as return values...

Hope this helps
Jay

"Richard Bixler" <ne******@earthlink.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
| Hello, and thanks.
|
| First, function header followed by line that barfs:
|
| Private Function extractPath(ByVal rawPath As String) As String
|
| ... (removes preceding chars including a leftmost quote mark)
|
| Barfs--> If InStr(rawPath, Chr(37),
| Microsoft.VisualBasic.CompareMethod.Text) > 0 Then _
|
| rawPath = Trim(Microsoft.VisualBasic.Left(rawPath, InStr(rawPath, Chr(37),
| Microsoft.VisualBasic.CompareMethod.Text) - 1))
|
| The variable "rawPath" is returned from
|
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Applications\w ordpad.exe\shell\open\command,
| and its value is "%ProgramFiles%\Windows NT\Accessories\WORDPAD.EXE" "%1"
| including the quotes as part of the string. I'm converting this to a
string
| to pass to pass to Microsoft.VisualBasic.Shell, the form will ultimately
be
| C:\Program Files\Windows NT\Accessories\WORDPAD.EXE
| D:\PROGRA~1\MICROS~1\FLIGHT~1\scenery.cfg
|
| You're right about option strict. I'll have to fix up some implicit
| conversions to turn it on... I should do that (and will), but in the
| interest of responding quickly to the user, will that make a difference in
| choosing the proper overload when executed on his specific installation?
|
| Thanks again -- Dick Bixler
|
| "dfoster" <df*****@woofix.local.dom> wrote in message
| news:sl********************@localhost.localdomain. ..
| > On 2005-09-04, Richard Bixler <ne******@earthlink.net> wrote:
| >> Hello - I have a project in VB.NET (framework version 1.1), in which I
| >> use
| >> the function InStr in the following form:
| >> Public Function InStr(ByVal String1 As String, ByVal String2 As
String,
| >> Optional ByVal Compare As Microsoft.VisualBasic.CompareMethod = 0) As
| >> Integer
| >
| > Why don't you post the exact line of code that is getting the error?
| >
| > Ditto what Jay said about IO.Path.
| >
| > Also, if a single user really is getting the overloadeded function, that
| > probably means you have option strict off. With Option strict, the
| > overload is always chosen at compile time. Could that be so?
| >
| >
|
|
Nov 21 '05 #7
Doh!

clicked send too soon...

Public Class ExtractPathException
Inherits ArgumentOutOfRangeException

Public Sub New(ByVal paramName As String, ByVal actualValue As
String)
MyBase.New(paramName, actualValue, "Extract Path Exception")
End Sub

End Class
Hope this helps
Jay

"Richard Bixler" <ne******@earthlink.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
| Hello, and thanks.
|
| First, function header followed by line that barfs:
|
| Private Function extractPath(ByVal rawPath As String) As String
|
| ... (removes preceding chars including a leftmost quote mark)
|
| Barfs--> If InStr(rawPath, Chr(37),
| Microsoft.VisualBasic.CompareMethod.Text) > 0 Then _
|
| rawPath = Trim(Microsoft.VisualBasic.Left(rawPath, InStr(rawPath, Chr(37),
| Microsoft.VisualBasic.CompareMethod.Text) - 1))
|
| The variable "rawPath" is returned from
|
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Applications\w ordpad.exe\shell\open\command,
| and its value is "%ProgramFiles%\Windows NT\Accessories\WORDPAD.EXE" "%1"
| including the quotes as part of the string. I'm converting this to a
string
| to pass to pass to Microsoft.VisualBasic.Shell, the form will ultimately
be
| C:\Program Files\Windows NT\Accessories\WORDPAD.EXE
| D:\PROGRA~1\MICROS~1\FLIGHT~1\scenery.cfg
|
| You're right about option strict. I'll have to fix up some implicit
| conversions to turn it on... I should do that (and will), but in the
| interest of responding quickly to the user, will that make a difference in
| choosing the proper overload when executed on his specific installation?
|
| Thanks again -- Dick Bixler
|
| "dfoster" <df*****@woofix.local.dom> wrote in message
| news:sl********************@localhost.localdomain. ..
| > On 2005-09-04, Richard Bixler <ne******@earthlink.net> wrote:
| >> Hello - I have a project in VB.NET (framework version 1.1), in which I
| >> use
| >> the function InStr in the following form:
| >> Public Function InStr(ByVal String1 As String, ByVal String2 As
String,
| >> Optional ByVal Compare As Microsoft.VisualBasic.CompareMethod = 0) As
| >> Integer
| >
| > Why don't you post the exact line of code that is getting the error?
| >
| > Ditto what Jay said about IO.Path.
| >
| > Also, if a single user really is getting the overloadeded function, that
| > probably means you have option strict off. With Option strict, the
| > overload is always chosen at compile time. Could that be so?
| >
| >
|
|
Nov 21 '05 #8
Richard,
Thanks again. If the above prompts any further ideas, I'd still be
appreciative!


Despite all that you call, can in my opinion using the Path class never be
result in someting so unreadable as you are creating now.

Cor
Nov 21 '05 #9
Hello Cor - Thanks. I only stated one line of code, really the program is
not unreadable if that's what you mean. And the newsreader inserts random
line breaks too. The other stuff I wrote was just to indicate the form of
strings I have to deal with, they're returned/required by system, not
designed by me... Is there a nice way of finding a path to an app whose name
is known, which is provisioned by simple calls?

Thanks -- Dick

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:uU**************@TK2MSFTNGP09.phx.gbl...
Richard,
Thanks again. If the above prompts any further ideas, I'd still be
appreciative!


Despite all that you call, can in my opinion using the Path class never be
result in someting so unreadable as you are creating now.

Cor

Nov 21 '05 #10
Richard,

I would go for recreating the path to a good readable path using the replace
method and than use the path command.

In my opinion gives that cleaner (more readable) code.

However feel free to do it in another way.

Cor
Nov 21 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: engrkhalid | last post by:
Hello everybody, When I send an email to any Hotmail account it goes directory to the Junk Email! My website is in a dedicated server using: Linux 2.4.21, Apa­che, PHP, MySQL I'm using the...
8
by: Uwe Mayer | last post by:
Is it possible to specify anonymous functions, something like: >>> f = {print "hello world"} >>> f() hello world in Pyton? Lambda expressions don't work here.
6
by: neo88 | last post by:
hi guys Can anyone please tell me what is wrong with this function: inline int strength(void) { int a; // tests to see what strength value the agent just attacked\defended with for (strength;...
5
by: Tony Johansson | last post by:
Hello experts! Why is not possible to have virtual static members Many thnakn //Tony
2
by: Aaron Ackerman | last post by:
I cannot a row to this bound DataGrid to SAVE MY LIFE! I have tried everything and I am at a loss. The using goes into add mode with the add button adds his data then updates with the update...
42
by: Holger | last post by:
Hi guys Tried searching for a solution to this, but the error message is so generic, that I could not get any meaningfull results. Anyways - errormessage:...
83
by: Anonymous | last post by:
Came across some code summarized as follows: char const* MyClass::errToText(int err) const { switch (err) { case 0: return "No error"; case 1: return "Not enough"; case 2: return "Too...
6
by: Max | last post by:
i have a event bind function like this(though it is not so robust): bind$=function(o,evt,fn,cb){ var aE='attachEvent'; var aEL='addEventListener'; if(!o&&o){ return o(evt,fn,!!cb); } return...
2
by: Maric Michaud | last post by:
Le Monday 25 August 2008 11:37:23 Steven Samuel Cole, vous avez écrit : i don't get your design, it seems over-complicated to mee at first glance. ... The free variable movementType in the...
0
marktang
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,...
0
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...
0
Oralloy
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
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,...
1
isladogs
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.