Micro Focus QTP (UFT) Forums
display any 10 numbers in ascending order using arrays in vb scripting - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: display any 10 numbers in ascending order using arrays in vb scripting (/Thread-display-any-10-numbers-in-ascending-order-using-arrays-in-vb-scripting)



display any 10 numbers in ascending order using arrays in vb scripting - haritha - 11-15-2011

hi,

can any one give me the simple code to display the below numbers in ascending order using arrays in vb scripting. 6,20,30,5,80,56,22,12,34,54




RE: display any 10 numbers in ascending order using arrays in vb scripting - v.swaminathan - 11-15-2011

Hi.. Please let me know if the below code works for you...

You would be required to pass/specify the numbers to the variable "InputNumbers"

'Code Starts Here

Code:
Option Explicit
Dim InputNumbers, SplitInputNumbers, ArrayCount, ReSort, iterInputNum, Num1, Num2
InputNumbers = "6,20,30,5,80,56,22,12,34,54"
SplitInputNumbers = Split(InputNumbers, ",")
ArrayCount = UBound(SplitInputNumbers)
ReSort = "YES"
While ReSort = "YES"
    ReSort = "NO"
    For iterInputNum = 0 to ArrayCount        
        If iterInputNum < ArrayCount Then
            If Cint(SplitInputNumbers(iterInputNum)) > Cint(SplitInputNumbers(iterInputNum+1)) Then
                Num1 = SplitInputNumbers(iterInputNum)
                Num2 = SplitInputNumbers(iterInputNum+1)
                SplitInputNumbers(iterInputNum+1) = Num1
                SplitInputNumbers(iterInputNum) = Num2
                ReSort = "YES"
            End If
        End If
    Next
Wend

'Code Ends Here


Thanks and Regards,
Swami


RE: display any 10 numbers in ascending order using arrays in vb scripting - haritha - 11-16-2011

hi swamy,

its not displaying any results after executiong np print or msgbox specified.


RE: display any 10 numbers in ascending order using arrays in vb scripting - v.swaminathan - 11-16-2011

Hi.. Please append the below script to retrieve the output data..

(From the earlier one also you would be able to see the output from the array (variable) "SplitInputNumbers". But this one will get you the output as a comma separated string)

'Code Starts here
Code:
Dim iterSortedNum, SortedNumericArray
For iterSortedNum = 0 to ArrayCount
    If iterSortedNum = 0 Then
        SortedNumericArray = SplitInputNumbers(iterSortedNum)    
    Else
        SortedNumericArray = SortedNumericArray & "," & SplitInputNumbers(iterSortedNum)    
    End If
Next
msgbox SortedNumericArray
'Code Ends Here


RE: display any 10 numbers in ascending order using arrays in vb scripting - shivu.hanu - 01-03-2012

Code:
dim arr(10),x
'TO READ THE INPUT FROM USERS
for i=0 t0 9
arr(i)=cint(inputbox("enter 10 numbers"))
next
'SORT THE INPUT
for i=0 to ubound(arr)
if arr(i)>arr(i+1) then
x=arr(i)
arr(i)=arr(i+1)
arr(i+1)=x
end if
next
'to display the array vALUES
for i=0 to 9
str=str&arr(i)&vblf
next