Inconsistency in indexof

  • Thread starter Thread starter Art Krumsee
  • Start date Start date
A

Art Krumsee

I have a console app that reads and parses the command line. The code
originally read something like this:

dim CmdLine as String = Command()
if CmdLine.indexof("-trace") then
'tracing is enabled...
end if

In Visual Studio on my development workstation this was working fine. But
on my production server the condition failed regardless of the contents of
the command line. I then went back to the old VB6 syntax

dim CmdLine as String = Command()
if instr(CmdLine,"-trace") then
'tracing is enabled...
end if

This works both on my dev workstation and on the production server. Has
anyone seen this inconsistency?
 
Hi Art,

No, but I always use

if CmdLine.indexof("-trace") <> -1 then
or something


Hit your head and say: "Hello I am still here".
(This kind of things happens me also often)

:-))

Cor
 
The String.IndexOf method returns an integer, but you're treating it
as a boolean. Maybe there is a difference in debug and release builds
that causes this to break. Try comparing it to -1 like this:

if CmdLine.IndexOf("-trace") <> -1 then
'tracing enabled
end if

/claes
 
Art Krumsee said:
I have a console app that reads and parses the command line. The
code originally read something like this:

dim CmdLine as String = Command()
if CmdLine.indexof("-trace") then
'tracing is enabled...
end if

Option Strict On?
 
Back
Top