Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
287 views
in Technique[技术] by (71.8m points)

vbscript - ASP - Changing variable name (numbering) or adding numbers to a variable in asc order to assign values

How to change the variable name numbering in ascending order to assign values to them. eg: car_1, car_2, car_3, car_4........ so on.. my coding is something like;

for i=1 to 20
var(i) = request.form("car_"i)
next

foreach ......so on........

response.write(var(12) & "<br/>")

I need a way to increase the number of 'car_' to assign each car value to the 'var' array. I have tried to add it like this:

var(i) = request.form("car_"&i)

AND

var(i) = request.form("car_"i"")

and none of these work. I would very much appreciate your help to solve this.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can concatenate values in VBScript with the & operator. Such as:

"car_" & i

To demonstrate, go ahead and run this code in something like this online code editor (IE only, I suspect):

<html>
    <head>
        <script type="text/vbscript">
            For i = 1 To 20
                document.write "car_" & i
                document.write "<br />"
            Next
        </script>
    </head>
    <body>
    </body>
</html>

Which produces the following output:

car_1
car_2
car_3
car_4
car_5
car_6
car_7
car_8
car_9
car_10
car_11
car_12
car_13
car_14
car_15
car_16
car_17
car_18
car_19
car_20

The same also works in server-side VBScript:

<body>
    <% For i = 1 To 20 %>
        Car_<%=i%><br />
    <% Next %>
</body>

Which produces the same output.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...