VB icon

Swap Fang (A comprehensive swap)

Email
Submitted on: 10/18/2017 8:47:29 PM
By: Nicholas Forystek  
Level: Intermediate
User Rating: Unrated
Compatibility: VB 6.0
Views: 387
author picture
 
     This is a Swa-tooth, or SwapFang! It really fits in the joke category a little bit to me, but not at first! (If anything in programming did, this is it, I don't use it.........) This is a comprehensive swap function it swaps up to five variables, or objects. Handles duel swap, sending two pairs of different times, else it sues right to left, unless it is specified to perform a fang which is like a tooth in a triangle elliptical when among three in a swap (order difference by two separate single swaps verses a shift like swap on two or more items, a fang is only for three, an argument shift is two to four when swapping). I think this Swap Fang illuminated something that I get myself into a lot in my developing, that is covering cases that maybe not become catches, a.k.a. extra code that never gets executed, sometimes like this function I design my interface with anomalies that really don't appear to occur or is just over code wasting memory.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Swap Fang(A comprehensive swap)
' Description:This is a Swa-tooth, or SwapFang! It really fits in the joke category a little bit to me, but not at first! (If anything in programming did, this is it, I don't use it.........) This is a comprehensive swap function it swaps up to five variables, or objects. Handles duel swap, sending two pairs of different times, else it sues right to left, unless it is specified to perform a fang which is like a tooth in a triangle elliptical when among three in a swap (order difference by two separate single swaps verses a shift like swap on two or more items, a fang is only for three, an argument shift is two to four when swapping). I think this Swap Fang illuminated something that I get myself into a lot in my developing, that is covering cases that maybe not become catches, a.k.a. extra code that never gets executed, sometimes like this function I design my interface with anomalies that really don't appear to occur or is just over code wasting memory.
' By: Nicholas Forystek
'**************************************

Public Sub SwapFang(ByRef var1, ByRef var2, Optional ByRef var3 = Empty, Optional ByRef var4 = Empty, Optional ByRef fang = Empty)
 Dim var5 'the variant variable to use for the swapping
 Dim var6 'for objects cause we might swap two pairs, var1 & var2 variant, then var3 and 4 objects
 
 If ((Not (TypeName(fang) = "Empty")) And (TypeName(fang) = "Boolean") And (Not (TypeName(var1) = "Boolean"))) Then
 If fang Then
 If (Not (TypeName(var4) = "Empty")) Then
 If IsObject(var1) Then
 Set var6 = var2
 Set var2 = var1
 Set var1 = var6
 
 Set var6 = var3
 Set var3 = var1
 Set var1 = var6
 
 Set var6 = var4
 Set var4 = var1
 Set var1 = var6
 Else
 var5 = var2
 var2 = var1
 var1 = var5
 
 var5 = var3
 var3 = var1
 var1 = var5
 
 var5 = var4
 var4 = var1
 var1 = var5
 End If
 Else
 If IsObject(var1) Then
 Set var6 = var2
 Set var2 = var1
 Set var1 = var6
 
 Set var6 = var3
 Set var3 = var1
 Set var1 = var6
 
 Set var6 = var4
 Set var4 = var1
 Set var1 = var6
 Else
 var5 = var2
 var2 = var1
 var1 = var5
 
 var5 = var3
 var3 = var1
 var1 = var5
 
 var5 = var4
 var4 = var1
 var1 = var5
 End If
 End If
 Else
 If ((Not (TypeName(var4) = "Empty")) And ((TypeName(fang) = "Boolean") And _
 ((Not (TypeName(var3) = "Boolean") And (TypeName(var3) = TypeName(var4)))))) Or _
 ((Not (TypeName(var4) <> TypeName(var3))) And ((TypeName(fang) = "Boolean") And _
 ((Not (TypeName(var3) = "Boolean") And (TypeName(var3) = TypeName(var4)))))) Then
 If fang Then
 If IsObject(var1) Then
 Set var6 = var1
 Set var1 = var2
 Set var2 = var6
 
 Set var6 = var3
 Set var3 = var1
 Set var1 = var6
 Else
 var5 = var1
 var1 = var2
 var2 = var5
 
 var5 = var3
 var3 = var1
 var1 = var5
 End If
 Else
 If IsObject(var1) Then
 Set var6 = var1
 Set var1 = var2
 Set var2 = var3
 Set var3 = var6
 Else
 var5 = var1
 var1 = var2
 var2 = var3
 var3 = var5
 End If
 End If
 ElseIf (Not (TypeName(var4) <> TypeName(var3))) And ((TypeName(fang) = "Boolean") And _
 ((Not (TypeName(var3) = "Boolean") And (TypeName(var3) = TypeName(var4))))) Then
 If IsObject(var1) Then
 Set var6 = var1
 Set var1 = var2
 Set var2 = var3
 Set var3 = var6
 Else
 var5 = var1
 var1 = var2
 var2 = var3
 var3 = var5
 End If
 ElseIf ((TypeName(var3) = TypeName(var4)) And _
 (Not (TypeName(var2) = TypeName(var3)))) And _
 ((TypeName(var1) = TypeName(var2))) Then
 If IsObject(var1) Then
 Set var6 = var1
 Set var1 = var2
 Set var2 = var6
 
 Set var6 = var3
 Set var3 = var4
 Set var4 = var6
 Else
 var5 = var1
 var1 = var2
 var2 = var5
 
 var5 = var3
 var3 = var4
 var4 = var5
 End If
 End If
 End If
 ElseIf (TypeName(var1) = TypeName(var2)) And (TypeName(fang) = "Empty") Then
 If (TypeName(var3) = TypeName(var4)) And (Not (TypeName(var2) = TypeName(var3))) Then
 'duce swap
 If IsObject(var1) Then
 Set var6 = var1
 Set var1 = var2
 Set var2 = var6
 
 Set var6 = var3
 Set var3 = var4
 Set var4 = var6
 Else
 var5 = var1
 var1 = var2
 var2 = var5
 
 var5 = var3
 var3 = var4
 var4 = var5
 End If
 Else
 If (Not (TypeName(var4) = "Empty")) And (TypeName(fang) = "Boolean") And (Not (TypeName(var1) = "Boolean")) Then
 If fang Then
 If IsObject(var1) Then
 Set var6 = var2
 Set var2 = var1
 Set var1 = var6
 
 Set var6 = var3
 Set var3 = var1
 Set var1 = var6
 
 Set var6 = var4
 Set var4 = var1
 Set var1 = var6
 Else
 var5 = var2
 var2 = var1
 var1 = var5
 
 var5 = var3
 var3 = var1
 var1 = var5
 
 var5 = var4
 var4 = var1
 var1 = var5
 End If
 Else
 If (Not (TypeName(var4) = "Empty")) Then
 If IsObject(var1) Then
 Set var6 = var1
 Set var1 = var2
 Set var2 = var3
 Set var3 = var4
 Set var4 = var6
 Else
 var5 = var1
 var1 = var2
 var2 = var3
 var3 = var4
 var4 = var5
 End If
 Else
 If IsObject(var1) Then
 Set var6 = var1
 Set var1 = var2
 Set var2 = var3
 Set var3 = var6
 Else
 var5 = var1
 var1 = var2
 var2 = var3
 var3 = var5
 End If
 End If
 End If
 ElseIf (TypeName(var1) = TypeName(var3)) And (TypeName(var4) = "Empty") Then
 If IsObject(var1) Then
 Set var6 = var1
 Set var1 = var2
 Set var2 = var3
 Set var3 = var6
 Else
 var5 = var1
 var1 = var2
 var2 = var3
 var3 = var5
 End If
 Else
 If IsObject(var1) Then
 Set var6 = var1
 Set var1 = var2
 Set var2 = var3
 Set var3 = var4
 Set var4 = var6
 Else
 var5 = var1
 var1 = var2
 var2 = var3
 var3 = var4
 var4 = var5
 End If
 End If
 End If
 ElseIf TypeName(var2) = TypeName(var3) And (Not (TypeName(var4) = "Empty")) And (TypeName(fang) = "Empty") Then
 'four swap
 If IsObject(var1) Then
 Set var6 = var1
 Set var1 = var2
 Set var2 = var3
 Set var3 = var6
 Else
 var5 = var1
 var1 = var2
 var2 = var3
 var3 = var5
 End If
 ElseIf (Not (TypeName(var3) = "Empty")) And (TypeName(var4) = "Empty") And (TypeName(fang) = "Empty") Then
 'three swap
 If IsObject(var1) Then
 Set var6 = var1
 Set var1 = var2
 Set var2 = var3
 Set var3 = var6
 Else
 var5 = var1
 var1 = var2
 var2 = var3
 var3 = var5
 End If
 ElseIf (TypeName(var3) = "Empty") And (TypeName(var4) = "Empty") And (TypeName(fang) = "Empty") Then
 If IsObject(var1) Then
 Set var6 = var1
 Set var1 = var2
 Set var2 = var6
 Else
 var5 = var1
 var1 = var2
 var2 = var5
 End If
 End If
End Sub


Other 11 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.