0

変数 Y に基づいて特定の配列 (シリーズで使用している) を作成する必要があります。これは私が使用している形式です - VBScript で実行しようとしています。

If Y=2 then

    S1 = [0,x]
    S2 = [x,0]

If Y=3 then

    S1 = [0,0,x]
    S2 = [0,x,0]
    S3 = [x,0,0]

If Y=4 then

    S1 = [0,0,0,x]<br/>
    S2 = [0,0,x,0]<br/>
    S3 = [0,x,0,0]<br/>
    S4 = [x,0,0,0]<br/>

If Y=5 then

    S1 = [0,0,0,0,x]
    S2 = [0,0,0,x,0]
    S3 = [0,0,x,0,0]
    S4 = [0,x,0,0,0]
    S5 = [x,0,0,0,0]

など for ループになることはわかっています -------------

for i = 1 to Y
    S[i] = "[.... this is where am drawing a brain freeze
next
4

1 に答える 1

0

arraylists を使用して配列を動的に作成し、それらを vbscript 配列に転送して、他の関数からアクセスできるようにすることができます。(または、私の意見では、通常の配列よりも優れている配列リストを使用し続けることもできます。)

Option Explicit

' Initialize
Dim x : x = "X"
Dim Y : Y = 5
Dim AL : Set AL = CreateObject("System.Collections.ArrayList")
Dim i, j, innerAL, S

' Make a loop to iterate over the amount of array entries we have to create
for i = 1 to Y

    ' This arraylist is used to set the inner array
    Set innerAL = CreateObject("System.Collections.ArrayList") 

    ' Fill the inner array
    for j = 0 to Y-1

        ' See if it has to be filled with X or 0
        If j = (Y-i) then
            innerAL.Add x
        else
            innerAL.Add 0
        end if
    next

    ' Convert the inner arraylist to a standard array and add it to the outer arraylist
    AL.Add innerAL.ToArray()

next

' We are done. Convert the arraylist to a standard array
S = AL.ToArray()

' Display the results
for i = 0 to Y-1
    wscript.echo "S(" & i & ") = [" & join(S(i), ",") & "]"
Next
于 2012-12-04T15:59:34.847 に答える