Swap variables without using a temporary to hold value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • clidezzzZ
    New Member
    • Aug 2007
    • 2

    Swap variables without using a temporary to hold value

    hi i want to know how to swap 2 variables in vb without using a temporary variable. thank you for the answer ^_^ god bless!!!!!
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by clidezzzZ
    hi i want to know how to swap 2 variables in vb without using a temporary variable.
    What version of VB?

    I don't know about later versions, but VB6 doesn't seem to have a built-in swap. You could always create your own Sub and make it a standard part of your toolkit. It's a pretty simple function. Something along the lines of...

    [CODE=vb]Public Sub SwapVariables(V ar1 As Variant, Var2 As Variant)
    Dim TempVar As Variant
    TempVar = Var1
    Va1 = Var2
    Var2 = TempVar
    End Sub[/CODE]To use it, you would just say SwapVariables A, B.

    Comment

    Working...