• Welcome to Valhalla Legends Archive.
 

Another Bit Of Help Please....

Started by TriCk, October 26, 2003, 01:43 AM

Previous topic - Next topic

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..

warz


UserLoser

My advice is to post in the Visual Basic Forum, not the Battle.net Bot Development forum

TriCk

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

Tuberload

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?
Quote"Pray not for lighter burdens, but for stronger backs." -- Teddy Roosevelt
"Your forefathers have given you freedom, so good luck, see you around, hope you make it" -- Unknown


Tuberload

#6
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
Quote"Pray not for lighter burdens, but for stronger backs." -- Teddy Roosevelt
"Your forefathers have given you freedom, so good luck, see you around, hope you make it" -- Unknown

TriCk

#7
How would u do that?

UserLoser

#8
Check here, it might help you.

TriCk

Ummm

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


6 / 2 = 3 ...


For example...

UserLoser

#10
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

Tuberload

#11
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.
Quote"Pray not for lighter burdens, but for stronger backs." -- Teddy Roosevelt
"Your forefathers have given you freedom, so good luck, see you around, hope you make it" -- Unknown

TriCk

#12
Nvm UserLoser's code worked...
;D


+1 to all of you ;D

Kp

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. :)
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

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.
Quote"Pray not for lighter burdens, but for stronger backs." -- Teddy Roosevelt
"Your forefathers have given you freedom, so good luck, see you around, hope you make it" -- Unknown