|
 |
asp_web_howto thread: Invalid procedure call or argument: 'Mid'
Message #1 by "Lance Woollett" <lancewlt@x...> on Wed, 1 Jan 2003 10:37:30
|
|
Having an issue with a user of a vbscript that I have written (hope i'm in
the right forum :).
The entire script is a fairly simple thing that gets some usage data off a
web page, and it works fine no worries for me. However others have bee
getting a Invalid procedure call or argument: 'Mid' error. After doing some
research I think I know the cause of the problem, however I am clueless of
how I am supposed to fix it (this is my first vbscript, and was amazed when
it actually works like it was supposed to!).
I believe the problem lies in the below function:
Function getValueFromText(startStr, endStr, text)
Dim regEx, matches, match, startStrPos, endStrPos, result
startStrPos = InStr(text, startStr)
If (startStrPos > 0) Then
startStrPos = startStrPos + Len(startStr)
endStrPos = InStr(startStrPos, text, endStr)
result = endStrPos
text = Mid(text, startStrPos, (endStrPos - startStrPos))
result = text
Set regEx = New RegExp
regEx.Pattern = "[\w]{0,}.[\w]{1,}"
Set Matches = regEx.Execute(Trim(text))
For Each Match in Matches ' Iterate Matches collection.
getURLFromTexttrimmed = Match.Value
Next
Else
getURLFromTexttrimmed = "N/A"
End If
End Function
Any pointers on what i'm doing wrong/how to fix it?
Thanks in advance :)
-Lance
Message #2 by "Lance Woollett" <lancewlt@x...> on Wed, 1 Jan 2003 10:49:09
|
|
arggh screwed up the posting of the code.
Its supposed to be:
Function getURLFromTexttrimmed(startStr, endStr, text)
Dim regEx, matches, match, startStrPos, endStrPos, result
startStrPos = InStr(text, startStr)
If (startStrPos > 0) Then
startStrPos = startStrPos + Len(startStr)
endStrPos = InStr(startStrPos, text, endStr)
result = endStrPos
text = Mid(text, startStrPos, (endStrPos - startStrPos))
result = text
Set regEx = New RegExp
regEx.Pattern = "[\w]{0,}.[\w]{1,}"
Set Matches = regEx.Execute(Trim(text))
For Each Match in Matches ' Iterate Matches collection.
getURLFromTexttrimmed = Match.Value
Next
Else
getURLFromTexttrimmed = "N/A" End If
End Function
Message #3 by "TomMallard" <mallard@s...> on Wed, 1 Jan 2003 08:11:33 -0800
|
|
What happens if "text" is empty or the start and end positions are bogus?
You don't have any code to handle these conditions and if someone enters the
positions wrong it'll give the error you get.
tom mallard
seattle
-----Original Message-----
From: Lance Woollett [mailto:lancewlt@x...]
Sent: Wednesday, January 01, 2003 10:38 AM
To: ASP Web HowTo
Subject: [asp_web_howto] Invalid procedure call or argument: 'Mid'
Having an issue with a user of a vbscript that I have written (hope i'm in
the right forum :).
The entire script is a fairly simple thing that gets some usage data off a
web page, and it works fine no worries for me. However others have bee
getting a Invalid procedure call or argument: 'Mid' error. After doing some
research I think I know the cause of the problem, however I am clueless of
how I am supposed to fix it (this is my first vbscript, and was amazed when
it actually works like it was supposed to!).
I believe the problem lies in the below function:
Function getValueFromText(startStr, endStr, text)
Dim regEx, matches, match, startStrPos, endStrPos, result
startStrPos = InStr(text, startStr)
If (startStrPos > 0) Then
startStrPos = startStrPos + Len(startStr)
endStrPos = InStr(startStrPos, text, endStr)
result = endStrPos
text = Mid(text, startStrPos, (endStrPos - startStrPos))
result = text
Set regEx = New RegExp
regEx.Pattern = "[\w]{0,}.[\w]{1,}"
Set Matches = regEx.Execute(Trim(text))
For Each Match in Matches ' Iterate Matches collection.
getURLFromTexttrimmed = Match.Value
Next
Else
getURLFromTexttrimmed = "N/A"
End If
End Function
Any pointers on what i'm doing wrong/how to fix it?
Thanks in advance :)
-Lance
|
|
 |