473,385 Members | 1,474 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,385 software developers and data experts.

What am I missing??

YYZ
Short version: I've got to a collection of objects based on a certain
property of those objects. Here is the code to know IF I need to swap
2 elements...

if cdbl(cCol(i).Balance) < cdbl(ccol(i + 1).Balance) then
SwapColItems(i, i+1, cCol)

The SwapColItems Sub looks like this (pared down)
Public Sub SwapColItems(ByVal i1 As Integer, ByVal i2 As Integer,
ByRef cCol As clsLiabilitiesCol)
Dim sTemp As String
sTemp = cCol(i1).Balance
cCol(i1).Balance = cCol(i2).Balance
cCol(i2).Balance = sTemp
End Sub

When I run this, and step through, I see the values being swapped. I
am using the Command Window to verify the collection(1).Balance =
"3000" and collection(2).Balance = "5000", then I step into the swap
routine, and at the end I see that cCol(i1).Balance = "5000" and
cCol(i2).Balance = "3000", which is good.

Then, right after it exits out of this sub, those values have been
reversed again!?!?! I know I'm doing something stupid, but I can't for
the life of my think of what it is!

Can anyone spot what I'm doing wrong? I know I'm forgetting something
stupid, but I've checked the obvious things I can think of (byval vs.
byref, which shouldn't matter in this case because the only values that
need to be preserved are in the cCol class variable, and as I
understand things it doesn't matter if you pass it byval or byref since
it points to an object pointer on the stack, and the data on the heap,
or whatever -- stacks and heaps make my ass twitch).

Any and all help is appreciated.

Matt

Jan 26 '06 #1
3 1034
Byref vs Byval is my first guess
Native Data types like Integer, String, Boolean and so on are by default
referenced by value
Classes are refrenced byref.
Byref means that VS passes a pointer to the original objekt when you call a
function.
when you use Byval a copy of the Data Type's value is passed to the
function.

If the two elements you are swapping are integers like in the example then
change from Byval to
Byref. If it still isnt working then try using the System.Integer class

you can read more on byref in VS help
byref vs byval: http://www.developerfusion.co.uk/show/1763/3/
"YYZ" <ma********@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Short version: I've got to a collection of objects based on a certain
property of those objects. Here is the code to know IF I need to swap
2 elements...

if cdbl(cCol(i).Balance) < cdbl(ccol(i + 1).Balance) then
SwapColItems(i, i+1, cCol)

The SwapColItems Sub looks like this (pared down)
Public Sub SwapColItems(ByVal i1 As Integer, ByVal i2 As Integer,
ByRef cCol As clsLiabilitiesCol)
Dim sTemp As String
sTemp = cCol(i1).Balance
cCol(i1).Balance = cCol(i2).Balance
cCol(i2).Balance = sTemp
End Sub

When I run this, and step through, I see the values being swapped. I
am using the Command Window to verify the collection(1).Balance =
"3000" and collection(2).Balance = "5000", then I step into the swap
routine, and at the end I see that cCol(i1).Balance = "5000" and
cCol(i2).Balance = "3000", which is good.

Then, right after it exits out of this sub, those values have been
reversed again!?!?! I know I'm doing something stupid, but I can't for
the life of my think of what it is!

Can anyone spot what I'm doing wrong? I know I'm forgetting something
stupid, but I've checked the obvious things I can think of (byval vs.
byref, which shouldn't matter in this case because the only values that
need to be preserved are in the cCol class variable, and as I
understand things it doesn't matter if you pass it byval or byref since
it points to an object pointer on the stack, and the data on the heap,
or whatever -- stacks and heaps make my ass twitch).

Any and all help is appreciated.

Matt

Jan 26 '06 #2
YYZ
> Byref vs Byval is my first guess

That was mine, too, but in this case, the integers that I'm passing
aren't the values I'm swapping. Think of it as an array (kinda) -- I'm
passing the indexes of the array, say items 1 and 2, and telling the
function to swap the values of array(1) and array(2) -- so the 1 and 2
aren't going to change...so byref/byval shouldn't matter. Assume the
array is made up of strings. arr(1) = "First" and arr(2) = "Second".
I want to make arr(1) = "Second" and arr(2) = "First".

Did that make more sense?

Matt

Jan 26 '06 #3
YYZ
My bad -- it wasn't anything obvious. The classes that I'm changing
are actually pass-throughs to an SDK that actually controls the data,
and while swapping all the values of the class, I was swapping the item
number, which means that my data was being moved, then moved back. In
actuality, the way to switch all the values is to just switch the item
number, which I didn't realize. Much easier than I was making it.

Sorry to post when the problem was with me and not a question of
programming.

Matt

Jan 26 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: David MacQuigg | last post by:
I'm concerned that with all the focus on obj$func binding, &closures, and other not-so-pretty details of Prothon, that we are missing what is really good - the simplification of classes. There are...
5
by: SimpSity | last post by:
I am a complete noob, what book would be the best for complete begginers, u know the ones that could teach a a retarted neborn monkey to program C++ thats the kind of thing im looking for alotr of...
112
by: Andy | last post by:
Hi All! We are doing new development for SQL Server 2000 and also moving from SQL 7.0 to SQL Server 2000. What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? Please,...
1
by: Sarah | last post by:
Hello. I am using Microsoft.Office.Interop.Excel in a C# .NET project. I want to open an Excel application with a specific file name. I am currently opening it with this code: ...
1
by: bradleyc | last post by:
Definately need my eyes checked... Error:asstester.cpp(300,1):Declaration missing ; Error:asstester.cpp(300,1):Compound statement missing } void doModify() { clrscr(); char inputv,...
0
by: kris | last post by:
hi can any one help me out, i have written a code for Word Indexing using Dll's i think this is an incomplete code for WORD INDEX. I had encountered this error "Error! No index entries found"...
17
by: Justin Emlay | last post by:
I'm hopping someone can help me out on a payroll project I need to implement. To start we are dealing with payroll periods. So we are dealing with an exact 10 days (Monday - Friday, 2 weeks). ...
10
by: Protoman | last post by:
Could you tell me what's wrong with this program, it doesn't compile: #include <iostream> #include <cstdlib> using namespace std; class Everything { public: static Everything* Instance()
5
by: le0 | last post by:
Hello guys, Im really having a hard time doing this, I have a record set with the ItemNo field with the data type as Text. In the record that I have, I want to find the missing number in the...
20
by: mc | last post by:
I may be opening a can of worms and don't want to start a religious war, but... What features of Java do Java programmers miss when working in C#? Other than, of course, great portability. C#...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.