Advertisement
AyrA

Exchange Values without a 3rd Var

Aug 3rd, 2011
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'Exchange Numbers and Strings without using a third Variable
  2. 'https://ayra.ch
  3.  
  4. OPTION EXPLICIT
  5.  
  6. DIM iA
  7. DIM iB
  8. DIM sA
  9. DIM sB
  10.  
  11. iA=1
  12. iB=10
  13.  
  14. sA="<Word 1>"
  15. sB="<Word 2>"
  16.  
  17. 'Before
  18. CALL MsgBox("A: " & CSTR(iA) & vbCrLf & "B: " & CSTR(iB),vbInformation,"Before: Number")
  19. CALL MsgBox("A: " & CSTR(sA) & vbCrLf & "B: " & CSTR(sB),vbInformation,"Before: String")
  20.  
  21. 'Exchange Number
  22. iA=iA+iB
  23. iB=iA-iB
  24. iA=iA-iB
  25.  
  26. 'Exchange String
  27. sA=sA & sB
  28. sB=Left(sA,Len(sA)-Len(sB))
  29. sA=Right(sA,Len(sA)-Len(sB))
  30.  
  31. 'After
  32. CALL MsgBox("A: " & CSTR(iA) & vbCrLf & "B: " & CSTR(iB),vbInformation,"After: Number")
  33. CALL MsgBox("A: " & CSTR(sA) & vbCrLf & "B: " & CSTR(sB),vbInformation,"After: String")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement