【发布时间】:2015-08-26 18:05:46
【问题描述】:
我编写了一个 VBscript 来找出数组中的正数和负数。我已经设法将这些数字分开并打印出来。我现在想将正数转换为负数。
这是我写的vbscript:
Option explicit
Dim arr(), i, str, number,j,k,str1,p
number=inputbox("The number of elements the array should have")
ReDim arr(number-1)
arr(0)=1
arr(1)=2
arr(2)=-4
arr(3)=6
arr(4)=-8
For i=0 to number-1
If arr(i)>0 Then
j=i
str=str&vbnewline&arr(j)&vbnewline
msgbox ("The positive numbers from the array are " &str)
end if
next
For i=0 to number-1
If arr(i)<0 Then
k=i
str1=str1&vbnewline&arr(k)&vbnewline
msgbox ("The negative numbers from the array are " &str1)
End If
Next
'ReDim preserve arr(6)
'For i= 5 to 7
'p=arr(k)*(-1)
'Next
'msgbox p
脚本成功执行,直到第二个 for 循环。我正在尝试将数组中的负数转换为正数(在本例中为 -4、-8)。当我执行注释代码时,我只得到第二个数字“8”。我必须一起显示所有数字(正数和转换后的数字)。怎么办?
【问题讨论】: