将数字中的负数转换为正数

时间:2015-08-26 18:05:46

标签: arrays vbscript qtp

我编写了一个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)。当我执行注释代码时,我只得到第二个数字&#34; 8&#34;。我必须一起显示所有数字(正数和转换数字)。怎么办呢?

0 个答案:

没有答案
相关问题