473,382 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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!!!!!
Aug 22 '07 #1
1 8816
Killer42
8,435 Expert 8TB
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...

Expand|Select|Wrap|Line Numbers
  1. Public Sub SwapVariables(Var1 As Variant, Var2 As Variant)
  2.   Dim TempVar As Variant
  3.   TempVar = Var1
  4.   Va1 = Var2
  5.   Var2 = TempVar
  6. End Sub
To use it, you would just say SwapVariables A, B.
Aug 23 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

50
by: Steve | last post by:
How do you rewrite the swap function without using a tmp variable in the swap function???? int main() { int x = 3; int y = 5; // Passing by reference
28
by: OSHIMA | last post by:
Hi, I found the swap() function without a temporary variable. void swap(int *x, int *y){ *x ^= *y; *y ^= *x; *x ^= *y; } So, I wrote the next code that exchange the double.
21
by: Abhishek Jha | last post by:
hello all, this has been an interesting topic since long. you can swap two numbers (say a and b) using temp(as third variable). you can also swap without using third variable.likeThis was also...
14
by: pras.vaidya | last post by:
hi, please help me with this problem : - how to swap two addresses .For eg variable i is located at 2000 and j at 3000 . Now i call swap function . Result should be that i should be now having...
6
by: Jack White | last post by:
Does anyone know if an analogue to the "swap()" function found in C++ exists in C#. For those not familiar, let's say you have a function that loads some collection passed in by reference. If an...
25
by: indrawati.yahya | last post by:
OK, before you all stab me with your OT pitchfork, I just want to mention that this question is indeed related to c.l.c++. My question is, does the well-known method to swap two integers produce...
9
by: sksriharsha | last post by:
In a C++ quiz, we were asked to write a program to swap two integer variables without using a third temporary variable. Any suggestions??
10
by: Chad | last post by:
I hope this question doesn't appear twice. I tried posting it once, however, I got a stupid 505 internal error on google. When this happens, the post will either post 30 minutes later or won't post...
21
by: raylopez99 | last post by:
In the otherwise excellent book C# 3.0 in a Nutshell by Albahari et al. (3rd edition) (highly recommended--it's packed with information, and is a desktop reference book) the following statement is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.