# Thread: [RESOLVED] Random Numbers math

1. ## [RESOLVED] Random Numbers math

Jjjir  Reply With Quote

2. ## Re: Random Numbers math

If someone were to ask you what the following line of code is doing and accomplishing, what would your response be?

Code:
`If CBool((CInt(ListBox1.Items(i)) + sum)) Then`  Reply With Quote

3. ## Re: Random Numbers math

I was just showing the concept of my code. But that line right there you posted is what I'm having trouble with.  Reply With Quote

4. ## Re: Random Numbers math

ANY time you are doing a programming problem, you should be working out the logic first and then writing the code to implement that logic. It is very clear that you haven't done that here:
Code:
```            If CBool((CInt(ListBox1.Items(i)) + sum)) Then
sum = CInt(ListBox1.Items(1))
End If```
because that code is complete nonsense. What exactly is that If statement supposed to be doing? If I gave you a list of numbers to add, what would be the logic you would follow to do it? Would you be doing something for a number in the list only if some condition was true? I would think not, so why would you write code that does that? Pick up a pen and paper and write down the logic first. Do the process manually, following the steps you wrote down. When it works, you know what the code has to do and you can write code to do it. If you just pluck code out of thin air with no real idea of what that code has to do - the steps, not just the result - then why would it work?  Reply With Quote

5. ## Re: Random Numbers math

Yeah, and I think OB1 had a good point: What were you expecting that to do? If you can't explain it, then you need to step back and think about it a bit more. A sum is just adding all the numbers, so what is the condition supposed to be doing there? When you sum something, do you only add it if some condition is met? If so, then a condition is needed, but you made it sound like you add it in for all cases.

EDIT: I was too slow.  Reply With Quote

6. ## Re: Random Numbers math

Also, you really ought to be using a For Each loop here. Unless you've been specifically instructed to do otherwise, do that.  Reply With Quote

7. ## Re: [RESOLVED] Random Numbers math

Instead of deleting the question, how about you post your solution and maybe help someone else with a similar problem?  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•