Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Instr() in ASP.NET? 2

Status
Not open for further replies.

Ovatvvon

Programmer
Feb 1, 2001
1,514
US
Hello,

I tried to use the instr() function in an aspx page, however I received an error on a pop-up dialog box that reads:



An exception 'system.stackoverflowexception' has occurred in /LM/W3SVC/8/Root-1-126747-864778437500.



and it gives a list of possible debuggers (MS CLR debugger or MS Development Environment).


This is what's causing it:


<script language=&quot;VB&quot; runat=&quot;server&quot;>
...

Function lastFolder(folder)
Dim i As Integer
lastFolder = Split(lastFolder, &quot;/&quot;)
If instr(1, lastFolder(UBound(lastFolder)), &quot;.asp&quot;) > 0 Then
i = (UBound(lastFolder) - 1)
Else
i = UBound(lastFolder)
End If
Return lastFolder(i)
End Function

...
</script>



Does anyone know what this means or how I can appropriately use this function without generating an error?

-Ovatvvon :-Q
 
You ended up calling Lastfolder recursively instead of accessing the array.

If instr(1, lastFolder(UBound(lastFolder)),

Use a work array. Also use UBound(arylastFolder) once.
You can get subscript out of range if there is only one entry and it has &quot;.asp&quot; because j will be 0 so J - 1 = -1.
What happens if &quot;.ASP&quot; because Instr will not see it unless vbTextCompare is used.

Function lastFolder(folder)
Dim i As Integer
Dim j as Integer
Dim aryLastFolder() as string
arylastFolder = Split(Folder, &quot;/&quot;)
J = UBound(arylastFolder) ' = 0 if not &quot;/&quot;
If instr(1, arylastFolder(j)), &quot;.asp&quot;) > 0 Then
i = j - 1
Else
i = j
End If
Return arylastFolder(i) 'i= -1 if no &quot;/&quot; and is .asp
Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
John,
What I used would have worked in ASP. What causes it to not work with .NET? -Ovatvvon :-Q
 
I do not know. But as a side note. In VBscript, all variables were Variants. In .Net, specifying no type defaults to Object. Put types on your code to speed it up.
Function lastFolder(folder as string) as string
Dim i As Integer
Dim j as Integer
Dim aryLastFolder() as string
arylastFolder = Split(Folder, &quot;/&quot;)
J = UBound(arylastFolder) ' = 0 if not &quot;/&quot;
If instr(1, arylastFolder(j)), &quot;.asp&quot;) > 0 Then
i = j - 1
Else
i = j
End If
Return arylastFolder(i) 'i= -1 if no &quot;/&quot; and is .asp
Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
That's right. I forgot about all that. Thanks for the reminder. :) -Ovatvvon :-Q
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top