Help: Can use InStr Code Behind Forms (simple example included)
I just attempted to move my code out of an aspx page to find that I couldn't
use certain standard VB functions. for example 'InStr' at first I thought
it was due to a namespace exclusion but InStr is a standard VB function not
a class. I created an extremely short code example below to demonstrate the
issue: (the code will complie if you comment out the line containing InStr
and uncomment the line containing 'foo=25')
'<-- TEST.VB -->
Option Strict Off
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Public Class testCBF : Inherits Page
Function foo() As Integer
'foo = 25
foo = InStr("Hello World","o") '<-- This will not compile
End Function
End Class
<!--TEST.ASPX-->
<%@ Page Inherits="testCBF" Src="test.vb" %>
<HTML>
<BODY>
<P><%=foo()%></P>
</BODY>
</HTML>
# 1 Re: Help: Can use InStr Code Behind Forms (simple example included)
Try one of the following:
1) Imports Microsoft.VisualBasic
2) Use IndexOf method:
Dim s As String = "Hello World"
Foo = s.IndexOf("o")
Mingyong Yang, MCP
----------
http://www.foxinternet.net/web2/myang
"Tom Ashworth" <tomash@bellsouth.net> wrote:
>I just attempted to move my code out of an aspx page to find that I couldn't
>use certain standard VB functions. for example 'InStr' at first I thought
>it was due to a namespace exclusion but InStr is a standard VB function
not
>a class. I created an extremely short code example below to demonstrate
the
>issue: (the code will complie if you comment out the line containing InStr
>and uncomment the line containing 'foo=25')
>
>
>
>
>
>
>'<-- TEST.VB -->
>Option Strict Off
>
>Imports System
>Imports System.Web.UI
>Imports System.Web.UI.WebControls
>Imports System.Web.UI.HtmlControls
>
>Public Class testCBF : Inherits Page
>
> Function foo() As Integer
>
> 'foo = 25
> foo = InStr("Hello World","o") '<-- This will not compile
>
> End Function
>
>End Class
>
>
><!--TEST.ASPX-->
><%@ Page Inherits="testCBF" Src="test.vb" %>
><HTML>
><BODY>
>
><P><%=foo()%></P>
>
></BODY>
></HTML>
>
>
>