HELP, Newbie Question "not declared"

  • Thread starter Thread starter Robert Martinez
  • Start date Start date
R

Robert Martinez

I am getting the following error:

Compiler Error Message: BC30451: Name 'InStr' is not declared.

with the following code:

Dim startpos, endpos As Integer
startpos = InStr(strSource, StartString)

endpos = (InStr(strSource, EndString) - InStr(strSource, StartString))

I don't know if this might be the problem, but I am basically trying to get
some vb.net code to work in a c# project. I've done this before, where I
just exclude the vb code from the project, and change all the "Codebehind="
to "Src=" and add the <% @Assembly Name="" %> directive to each vb file.

Any help would be appreciated.

REM
 
Excellent. That worked. Got it, InStr is dead.

What about "Mid"? Same error "not declared" for the following line of
code (I went through 200 lines of code to clean it up and make it work,
and now I am in the last 3 lines -- thanks!)

strSource = Mid(strSource, startpos, endpos)
 
Hello,

Robert Martinez said:
Compiler Error Message: BC30451: Name 'InStr' is not declared.

InStr requires a reference to Microsoft.VisualBasic.dll. You can import the
namespace Microsoft.VisualBasic and access it by typing
"Strings.InStr(...)".

Regards,
Herfried K. Wagner
 
I was minding my own business when Herfried K. Wagner [MVP] blurted out:
InStr is _not_ dead.

InStr IS dead. Just because it's accessible doesn't mean it should be used.
It is provided to ease the transition from vb 6 to vb.net. String.IndexOf
should be used wherever InStr was used previously.
 
Dear Herfried, Chris,

I tend to agree but I see it as deprecated rather than dead.

This was what I meant in my earlier post about not wanting to use
AppActivate. I see these things as legacy functions which, like Chris says,
ease the transition. But they get in the way of portability, as Robert
found.

Just my thoughts.

Regards,
Fergus

==========================================
Deprecated:
Said of a program or feature that is considered obsolescent
and in the process of being phased out, usually in favour of a
specified replacement. Deprecated features can,
unfortunately, linger on for many years. This term appears
with distressing frequency in standards documents when the
committees writing the documents realise that large amounts of
extant (and presumably happily working) code depend on the
feature(s) that have passed out of favour.
 
Robert,
For me in a normal VB.net project form "instr" works.

For the discussion to all, Instr and IndexOf give different results.

Dim strsource As String = "abcdefg"
Dim startposInstr As Integer = InStr(strsource, "a")
'startpos = 1
Dim startposIndexOf As Integer = strsource.IndexOf("a")
'startpos = 0

Then my thoughts about Instr is dead.
After a long discussion with someone active in this newsgroup I did change
my mind.
I myself alway use IndexOf, just because it is too in other languages.
(and it easier to handle with a for loop in a string, but when you use the
for each char loop, that is not necessary too now)

But back to "is dead" a (natural) language is rich by the way you can
describe things by using only one word.
In my native language we had formely 4 words for pasta.
Vermicelli
Mie
Macronie
Spagetti

Now we use all Italian words for it, some chinese (mihoen, bihoen, etc) and
the old ones.
By the time we are not eating pasta anymore, maybe some of those words
disapear again.

But now it has our language made more rich.
Cor
 
Hello,

-=Chris=- said:
InStr IS dead. Just because it's accessible doesn't mean it should be used.
It is provided to ease the transition from vb 6 to vb.net. String.IndexOf
should be used wherever InStr was used previously.

No. InStr is part of the Visual Basic .NET programming language. It's a
"shortcut". Nobody is forced to use it, but in a VB .NET application it's
legitime to use VB .NET's commands.

Regards,
Herfried K. Wagner
 
Back
Top