Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set the length of intercepted characters in the third argument of dim function

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you how to set the third parameter of the dim function to intercept the length of characters, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

The third parameter of the dim function, that is, the length of the intercepted character, I had some problems when I set this: response.write mid (up_address,a (I), a (item1)-1) & "" when I write like this, it will report an error, indicating an invalid procedure call or argument.

Response.write mid (up_address,a (I), a (iTune1) + 1) & "but when I change a (iTune1)-1 to a (iTune1) + 1, I can execute it, and the corresponding value for a (iTune1) is 11, but why should I subtract but not add? The full code is as follows:

VB code:

The copy 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) & ""

If a (0) 0 then

For iTunes 0 to len (up_address)-1

A (iTunes 1) = instr (a (I) + 1 jade updated address, "")

Response.write mid (up_address,a (I), a (item1)-1) & ""

If a (iTun1) = 0 then

Exit for

End if

Response.write a (iTunes 1) & ""

Next

End if as in the above code, I want to decompose the string into spaces, but there is something wrong with the third parameter of mid. I originally intended to intercept it like this:

VB code:

The copy code is as follows:

Mid (up_address,a (I), a (item1)-a (I)-1)

'a (I) is the position of the space

'a (iDiver1) is the position of the next space

'a (iTun1)-a (I)-1 is the length of a character between two spaces

The problem now is that, after testing, the third parameter of mid cannot use subtraction, that is to say, I can write a (item1) +, but I can't write a (item1) -. After thinking about it for a long time, I still don't understand what the problem is. How should we solve the problem?

This problem occurs because there is a negative number in the third parameter of the above MID function. Here is the VBS code for the test found on the Internet. The principle is the same as the following code:

VBScript code:

The copy 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) & ""

If a (0) 0 then

For iTunes 0 to len (up_address)-1

A (iTunes 1) = instr (a (I) + 1 jade updated address, "")

MsgBox a (I) & "& (a (iTun1)-1) 'the result here is 34, which leads to an error.

MsgBox mid (up_address,a (I), a (item1)-1) & ""

If a (iTun1) = 0 then

Exit for

End if

MsgBox a (iTunes 1) & ""

Next

End if

These are all the contents of the article "how to set the length of intercepted characters in the third parameter of the dim function". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report