Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: TriCk on October 26, 2003, 01:43 AM

Title: Another Bit Of Help Please....
Post by: TriCk on October 26, 2003, 01:43 AM
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..
Title: Re:Another Bit Of Help Please....
Post by: warz on October 26, 2003, 01:45 AM
Weed them out of where?
Title: Re:Another Bit Of Help Please....
Post by: UserLoser on October 26, 2003, 01:47 AM
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
Title: Re:Another Bit Of Help Please....
Post by: TriCk on October 26, 2003, 01:49 AM
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
Title: Re:Another Bit Of Help Please....
Post by: Tuberload on October 26, 2003, 02:06 AM
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?
Title: Re:Another Bit Of Help Please....
Post by: TriCk on October 26, 2003, 02:07 AM
Except... vb6
Title: Re:Another Bit Of Help Please....
Post by: Tuberload on October 26, 2003, 02:10 AM
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
Title: Re:Another Bit Of Help Please....
Post by: TriCk on October 26, 2003, 02:17 AM
How would u do that?
Title: Re:Another Bit Of Help Please....
Post by: UserLoser on October 26, 2003, 02:19 AM
Check here (http://forum.valhallalegends.com/phpbbs/index.php?board=31;action=display;threadid=3270), it might help you.
Title: Re:Another Bit Of Help Please....
Post by: TriCk on October 26, 2003, 02:22 AM
Ummm

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


6 / 2 = 3 ...


For example...
Title: Re:Another Bit Of Help Please....
Post by: UserLoser on October 26, 2003, 02:25 AM
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
Title: Re:Another Bit Of Help Please....
Post by: Tuberload on October 26, 2003, 02:26 AM
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.
Title: Re:Another Bit Of Help Please....
Post by: TriCk on October 26, 2003, 02:29 AM
Nvm UserLoser's code worked...
;D


+1 to all of you ;D
Title: ewww, inefficiency
Post by: Kp on October 26, 2003, 07:49 AM
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. :)
Title: Re:Another Bit Of Help Please....
Post by: Tuberload on October 26, 2003, 05:00 PM
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.
Title: Re:Another Bit Of Help Please....
Post by: 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.
Title: Re:Another Bit Of Help Please....
Post by: Tuberload on October 26, 2003, 11:10 PM
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.
Title: Re:Another Bit Of Help Please....
Post by: iago on October 27, 2003, 02:24 AM
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.
Title: Re:Another Bit Of Help Please....
Post by: Tuberload on October 27, 2003, 02:54 AM
So wouldn't thay make using the AND operator 32X faster than the division operator?
Title: Re:Another Bit Of Help Please....
Post by: Adron on October 27, 2003, 03:11 AM
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.
Title: Re:Another Bit Of Help Please....
Post by: iago on October 27, 2003, 03:22 AM
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.
Title: Re:Another Bit Of Help Please....
Post by: Etheran on October 27, 2003, 09:11 PM
Think about what division actually is.  It's like looped subtraction.  so of course that's going to take longer than a simple anding.