The third parameter of dim function sets the length of intercepted characters

Time:2022-5-25

The third parameter of the dim function is the length of the intercepted character. When I set this parameter, I had some problems: response Write mid (up_address, a (I), a (I + 1) – 1) & “< br / >” when I write as above, it will report an error and prompt invalid procedure calls or parameters,
response. Write mid (up_address, a (I), a (I + 1) + 1) & “< br / >” but when I change a (I + 1) – 1 to a (I + 1) + 1, it can be executed. The corresponding value of a (I + 1) is 11, but why can I only subtract but not add? All codes are as follows:
VB code:

Copy codeThe code is as follows:


dim a(),up_address
up_address = “aaa djaldk adflj adafadfasdfa afd ad”
redim a(len(up_address))
a(0) = instr(up_address,” “)
response.write a(0) & “<br />”
if a(0)<>0 then
for i=0 to len(up_address)-1
a(i+1) = instr(a(i)+1,up_address,” “)
response.write mid(up_address,a(i),a(i+1)-1) & “<br />”
if a(i+1)=0 then
exit for
end if
response.write a(i+1) & “<br />”
next


End if in the above code, I want to decompose the string by spaces, but there is something wrong with the third parameter of Mid. I originally wanted to intercept it like this:
VB code:

Copy codeThe code is as follows:


mid(up_address,a(i),a(i+1)-a(i)-1)
‘a (I) is the position of the space
‘a (I + 1) is the position of the next space
‘a (I + 1) – A (I) – 1 is the character length between two spaces


The problem now is that, after testing, the third parameter of mid cannot use subtraction, that is, I can write a (I + 1) +, but I can’t write a (I + 1) -. After thinking for a long time, I haven’t understood the problem? How should we solve it?
This problem occurs because the third parameter of the mid function above has a negative number. The following is the VBS code for testing found on the Internet. The principle is the same,The following code
VBScript code:

Copy codeThe code is as follows:


dim a(),up_address
up_address = “aaa djaldk adflj adafadfasdfa afd ad”
MsgBox len(up_address) ’36
redim a(len(up_address)) ‘a(36)
a(0) = instr(up_address,” “)
MsgBox a(0) ‘a(0)=4
MsgBox a(0) & “<br />”
if a(0)<>0 then
for i=0 to len(up_address)-1
a(i+1) = instr(a(i)+1,up_address,” “)
Msgbox a (I) & “” & (a (I + 1) – 1) ‘the result here is 34, – 1, which leads to an error
MsgBox mid(up_address,a(i),a(i+1)-1) & “<br />”
if a(i+1)=0 then
exit for
end if
MsgBox a(i+1) & “<br />”
next
end if

Recommended Today

Backtracking method — Taking the placement of queens as an example

Backtracking method(98 messages) (novice to) learning recursion and backtracking algorithm (I) — n-bit integer division_ TripleGold. Blog – CSDN blog Algorithm idea: (general problem solving method) the exhaustive search attempt process is mainly to find the solution of the problem in the search attempt process. When it is found that the solution conditions are not […]