There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Software Development
Tag Cloud
audio blue screen boot bsod computer cpu crash dell desktop driver drivers error excel external hard drive firefox format freezes freezing hard drive hardware hijackthis install internet internet explorer itunes keyboard laptop malware motherboard mouse network networking outlook 2007 power printer problem ram router screen slow sound trojan usb virus vista vista 32-bit windows windows xp winxp wireless
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Write a program in Visual Basic.


Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
atish_aa's Avatar
Senior Member with 261 posts.
 
Join Date: Apr 2004
Location: INDIA
Experience: Advanced
01-Feb-2005, 02:35 AM #1
Thumbs up Write a program in Visual Basic.
Please write a program in VB to swap the values of 2 variables without using a third variable.
IMM's Avatar
IMM IMM is offline IMM is authorized to help remove malware.
Distinguished Member with 3,165 posts.
 
Join Date: Feb 2002
01-Feb-2005, 05:54 AM #2
I won't write any vb for you but this kind of algorithm works
a = a xor b
b = a xor b
a = a xor b

In c:
a ^= b ^= a ^= b;
-------------
There are 10 kinds of people -- those who read binary and those who don't

Last edited by IMM : 01-Feb-2005 06:04 AM.
Mosaic1's Avatar
Distinguished Member with 7,502 posts.
 
Join Date: Aug 2001
02-Feb-2005, 01:38 AM #3
Using IMM's example, it works great in VB.
Code:
Private Sub Command2_Click()
Dim a As Integer, b As Integer
a = 99
b = 33
a = a Xor b
b = a Xor b
a = a Xor b

MsgBox a & " " & b

End Sub
What the heck. This is easier than Posting in Security! LOL I hope this isn't your homework. Here's another simple logic.

Code:
Private Sub Command1_Click()
Dim a As Integer, b As Integer
a = 99
b = 14

b = a + b  'b =  99 + 14 = 113
a = b - a  'a   113 - 99 = 14
b = b - a  'b = 113 - 14 = 99

MsgBox "A = " & a
MsgBox "B = " & b

End Sub

Last edited by Mosaic1 : 02-Feb-2005 01:47 AM.
IMM's Avatar
IMM IMM is offline IMM is authorized to help remove malware.
Distinguished Member with 3,165 posts.
 
Join Date: Feb 2002
02-Feb-2005, 04:00 AM #4
That xor thing is probably as old as I am -- and I'm older than Fortran
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 10:45 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.