Ok this is for VB6
Basically
I need to get my program to weed out the even numbers and separate into 1 list and the odd numbers go into another list.
Help.. i dont wanna have to type alot of code if theres a simpler way..
Weed them out of where?
My advice is to post in the Visual Basic Forum (http://forum.valhallalegends.com/phpbbs/index.php?board=31), not the Battle.net Bot Development forum
Well im getting the words from a text
Then...
Im using the Split method
to Split them if they contain "; "
Word() = Split(Words, "; ")
For Wd = 0 To UBound(Word)
This is the part where i want to separate the numbers even from odd...
Then do something like...
If Odd Then
listbox1.additem Word(Wd)
Else
listbox2.additem Word(Wd)
End If
Next Wd
This is a Java version of what you want:
if ((Wd%2) == 0)
// This is an even index
else
// This is an odd index
Is that what you were asking?
Except... vb6
If you know how to program in Visual Basic 6, I got it right this time, you should be able to convert that simple bit of code...
% is the modulus operator. It devides the two numbers and returns the remainder. Visual Basic might not have this so you might have to figure out another way to see if the index is divisible by two or not. It's fairly simple.
Edit: Typo
How would u do that?
Check here (http://forum.valhallalegends.com/phpbbs/index.php?board=31;action=display;threadid=3270), it might help you.
Ummm
That divides the number by 2... Anything greater than 2 will display bad results...
6 / 2 = 3 ...
For example...
No, Modulus does not divide the number at all, it's just the remainder.
Debug.Print "Printing 6 mod 2: " & 6 Mod 2
Debug.Print "Printing 6 / 2: " & 6 / 2
Results in:
QuotePrinting 6 mod 2: 0
Printing 6 / 2: 3
Edit: Silly Tuberload and Modulus spelling :P
Modulus is the correct spelling, sorry.
Explanation of modulus operator:
7 / 3 = 2 remainder 1
the division operator will return 2, and the modulus operator returns 1.
So: 6 / 2 = 2 remainder 0
This means the remainder of an even number when divided by two will always be 0, and an odd number 1.
Nvm UserLoser's code worked...
;D
+1 to all of you ;D
Quote from: Tuberload on October 26, 2003, 02:06 AMThis is a Java version of what you want:
if ((Wd%2) == 0)
// This is an even index
else
// This is an odd index
First, eww Java. Second, and more importantly, eww @ inefficient modulo. When taking something modulo a power of 2, you can get the same effect (& faster) by masking it with the modulo less 1. In your case, do
if ((wd & 1) == 0) /* even */As Adron pointed out recently in channel, most compilers are smart enough to do this optimization. However, given that the respective languages in this thread are Java and VB6, I wouldn't want to trust in that optimization. :)
Hmmm, thanks for the performance input Kp. My question, is the performance really that much faster? I know bitwise operators are faster, but for something this small what would the gains be? Besides I figured it would be much easier for trick to understand something a little simpler, based on his posts.
I am still sticking with Java. :) It does have some problems, but it is an excellent language in my opinion. Another side not, Java is a way better language than Visual Basic.
Well, division is about 100x slower than and, so if that code is running a lot it will make a big difference.
Wow. I didn't know the performance differences were that large. Once again thanks for the information, it should help the performance of some of my projects a lot.
Well, go back to logic gates. An and is 32 parallel AND gates, which is the same as a single AND gate.
On the other hand, a divide is .. *finds book*.. blast, I'll just link you to a picture:
http://books.elsevier.com/companions/1558604286/pictures/pdf/Chapter4/f0440.pdf
http://books.elsevier.com/companions/1558604286/pictures/pdf/Chapter4/f0441.pdf
Although I'm not totally sure which algorithm is implemented on 80x86 chips, they tend to be slow like that. And it runs in series, so it takes a hell of a lot longer.
So wouldn't thay make using the AND operator 32X faster than the division operator?
Quote from: iago on October 26, 2003, 05:37 PM
Well, division is about 100x slower than and, so if that code is running a lot it will make a big difference.
On a Pentium it seems to be 25x slower. 1 cycle vs 25. In a very tight loop it would probably be around 6 times slower, and in most loops it might make it 2 times slower.
Quote from: Tuberload on October 27, 2003, 02:54 AM
So wouldn't thay make using the AND operator 32X faster than the division operator?
No, because division doesn't just do one thing per cycle. If it was 32 and gates in sequence it would be different.
It really depends on the processor.
Think about what division actually is. It's like looped subtraction. so of course that's going to take longer than a simple anding.