Valhalla Legends Forums Archive | Battle.net Bot Development | Another Bit Of Help Please....

AuthorMessageTime
TriCk
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..
October 26, 2003, 7:43 AM
warz
Weed them out of where?
October 26, 2003, 7:45 AM
UserLoser
My advice is to post in the Visual Basic Forum, not the Battle.net Bot Development forum
October 26, 2003, 7:47 AM
TriCk
Well im getting the words from a text
Then...
Im using the Split method
to Split them if they contain "; "
[code]
Word() = Split(Words, "; ")
For Wd = 0 To UBound(Word)
[/code]
This is the part where i want to separate the numbers even from odd...
Then do something like...
[code]
If Odd Then
listbox1.additem Word(Wd)
Else
listbox2.additem Word(Wd)
End If
Next Wd
[/code]
October 26, 2003, 7:49 AM
Tuberload
This is a Java version of what you want:

[code]
if ((Wd%2) == 0)
// This is an even index
else
// This is an odd index
[/code]

Is that what you were asking?
October 26, 2003, 8:06 AM
TriCk
Except... vb6
October 26, 2003, 8:07 AM
Tuberload
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
October 26, 2003, 8:10 AM
TriCk
How would u do that?
October 26, 2003, 8:17 AM
UserLoser
Check here, it might help you.
October 26, 2003, 8:19 AM
TriCk
Ummm

That divides the number by 2... Anything greater than 2 will display bad results...


6 / 2 = 3 ...


For example...
October 26, 2003, 8:22 AM
UserLoser
No, Modulus does not divide the number at all, it's just the remainder.

[code]Debug.Print "Printing 6 mod 2: " & 6 Mod 2
Debug.Print "Printing 6 / 2: " & 6 / 2
[/code]

Results in:

[quote]Printing 6 mod 2: 0
Printing 6 / 2: 3
[/quote]


Edit: Silly Tuberload and Modulus spelling :P
October 26, 2003, 8:25 AM
Tuberload
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.
October 26, 2003, 8:26 AM
TriCk
Nvm UserLoser's code worked...
;D


+1 to all of you ;D
October 26, 2003, 8:29 AM
Kp
[quote author=Tuberload link=board=17;threadid=3269;start=0#msg25787 date=1067155596]This is a Java version of what you want:
[code]
if ((Wd%2) == 0)
// This is an even index
else
// This is an odd index
[/code][/quote]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 [code]if ((wd & 1) == 0) /* even */[/code]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. :)
October 26, 2003, 1:49 PM
Tuberload
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.
October 26, 2003, 11:00 PM
iago
Well, division is about 100x slower than and, so if that code is running a lot it will make a big difference.
October 26, 2003, 11:37 PM
Tuberload
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.
October 27, 2003, 5:10 AM
iago
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.
October 27, 2003, 8:24 AM
Tuberload
So wouldn't thay make using the AND operator 32X faster than the division operator?
October 27, 2003, 8:54 AM
Adron
[quote author=iago link=board=17;threadid=3269;start=15#msg25980 date=1067211469]
Well, division is about 100x slower than and, so if that code is running a lot it will make a big difference.
[/quote]

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.
October 27, 2003, 9:11 AM
iago
[quote author=Tuberload link=board=17;threadid=3269;start=15#msg26045 date=1067244882]
So wouldn't thay make using the AND operator 32X faster than the division operator?
[/quote]

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.
October 27, 2003, 9:22 AM
Etheran
Think about what division actually is. It's like looped subtraction. so of course that's going to take longer than a simple anding.
October 28, 2003, 3:11 AM

Search