Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


VBSCript For Begineers(Array)

 
Logged in as: Guest
arrSession:exec spGetSession 2,16,46609
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> VBSCript For Begineers(Array)
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 VBSCript For Begineers(Array) - 5/3/2007 4:54:56 PM   
  amitkumar.s

 

Posts: 2
Score: 0
Joined: 5/3/2007
Status: offline
Public Function CompareArrays(ExpArray, ActArray, Test_step)

iResult=True
If (UBound(ExpArray)<>UBound(ActArray)) Then
call Logger(Test_step,"Array comparision failed as the Sizes of Arrays are not equal","Fail")
Else
array_size=UBound(ExpArray)
End If
For i=0 to array_size
 
 If (LCase(Trim(ExpArray(i)))<>LCase(Trim(ActArray(i))))Then
  iResult=False
 Else
  iResult=True
 End If
 Next
 
End Function

Public Function CompareinArray(ExpArray, ActArray, Test_step)

array_size=UBound(ExpArray)

For i=0 to array_size
 iResult=False
 For j=0 to UBound(ActArray)
  If (LCase(Trim(ExpArray(i)))=LCase(Trim(ActArray(j))))Then
  iResult=True
  Exit For
 End If
 Next
 
 If NOT iResult Then
  iResult=False
 End If
Next

End Function



Public Function CompareValueinArray(StringVal, ExpArray, Test_step)

iResult=False

array_size=UBound(ExpArray)

For i=0 to array_size
  If (LCase(Trim(ExpArray(i)))=LCase(Trim(StringVal)))Then
   iResult=True
  End If
Next
 If  iResult Then
  CompareValueinArray=True
 Else
  CompareValueinArray=False
 End If
End Function



Public Function Join_Arrays(Array1, Array2, Joined_Array)
 ReDim Joined_Array(Ubound(Array1)+Ubound(Array2)+1)
 
 For ind=0 to Ubound(Array1)
  Joined_Array(ind)=Array1(ind)
 Next
 
 For ind=0 to Ubound(Array2)
  Joined_Array(Ubound(Array1)+1+ind)=Array2(ind)
 Next

End Function



Public Function ArraySort_desc(arrShort)
   For i = UBound(arrShort) - 1 To 0 Step -1
   For j= 0 to i
   If arrShort(j) < arrShort(j+1) then
   temp=arrShort(j+1)
   arrShort(j+1)=arrShort(j)
   arrShort(j)=temp
   end if
   next
   Next
End Function



Public Function ArraySort_asc(arrShort)
   For i = UBound(arrShort) - 1 To 0 Step -1
   for j= 0 to i
   if arrShort(j) > arrShort(j+1) then
   temp=arrShort(j+1)
   arrShort(j+1)=arrShort(j)
   arrShort(j)=temp
   end if
   next
   Next
End Function

 
 
Post #: 1
 
 RE: VBSCript For Begineers(Array) - 5/4/2007 1:55:05 AM   
  ebgreen


Posts: 5250
Score: 31
Joined: 7/12/2005
Status: offline
Thanks for sharing your code. Some comments:

Public Function CompareArrays(ExpArray, ActArray, Test_step)
iResult=True
If (UBound(ExpArray)<>UBound(ActArray)) Then
   call Logger(Test_step,"Array comparision failed as the Sizes of Arrays are not equal","Fail")
Else
   array_size=UBound(ExpArray)
End If
For i=0 to array_size

    If (LCase(Trim(ExpArray(i)))<>LCase(Trim(ActArray(i))))Then
       iResult=False
    Else
       iResult=True
    End If
  Next

End Function

iResult=True is misleading. You name the variable with a name that indiocates that it will be an integer yet you use it like a boolean.
call Logger(Test_step,"Array comparision failed as the Sizes of Arrays are not equal","Fail") - There is no Logger function provided
The logic of the function is faulty. The way it is written, it will return true anytime that the last elements of the array are equal and the arrays are the same size regardless of whether all the rest of the elements are equal.
The Test_Step parameter is never used so there really isn't any point to passing it into the function.
The function never returns a result.



Public Function CompareinArray(ExpArray, ActArray, Test_step)
array_size=UBound(ExpArray)
For i=0 to array_size
iResult=False
For j=0 to UBound(ActArray)
If (LCase(Trim(ExpArray(i)))=LCase(Trim(ActArray(j))))Then
iResult=True
Exit For
End If
Next

If Not iResult Then
iResult=False
End If
Next
End Function


If you move iResult=False out of the For loop at the beginning then there is no need for the If Not iResult Then logic block any more.
The Test_Step parameter is never used so there really isn't any point to passing it into the function.
This function doesn't actually return any result.


Public Function CompareValueinArray(StringVal, ExpArray, Test_step)
iResult=False
array_size=UBound(ExpArray)
For i=0 to array_size
If (LCase(Trim(ExpArray(i)))=LCase(Trim(StringVal)))Then
  iResult=True
End If
Next
If  iResult Then
CompareValueinArray=True
Else
CompareValueinArray=False
End If
End Function

The Test_Step parameter is never used so there isn't really any point to passing it into the function.
The If iResult Then block is pointless. All you need to do is CompareValueInArray = iResult.
 
Neither of the sort functions actually sort the array.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to amitkumar.s)
 
 
Post #: 2
 
 RE: VBSCript For Begineers(Array) - 5/21/2007 11:03:53 PM   
  anrmurthy

 

Posts: 2
Score: 0
Joined: 5/1/2007
Status: offline
Hi Amit

This is Murthy, i am new to this VB Script could you help me in writting the VB code  for sorting as i have tried a lot but i haven't got if you could please try for me and post it to my mail id: PLEASE DO NOT FEED THE SPAMMERS
Regards
Murthy.

EDIT (EBGREEN): Removed email address. Use the Private Messaging system to contact a person.

< Message edited by ebgreen -- 5/22/2007 12:49:19 AM >

(in reply to amitkumar.s)
 
 
Revisions: 1 | Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> VBSCript For Begineers(Array) Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts