# Thread: Variable not getting a value

1. ## Variable not getting a value

*Sorry if my first post didn't follow the forum rules, while waiting for answers i read the faq's, forum rules and realized what I did.

Now to my question, I have 2 loops where the counters are set to similar variable(e.g ctr=var1, ctr2=var1) but the inner loops doesn't seem to get the value I want it to get. Here is the code of the 2 loops:
Code:
```For ctr = root To 0 Step -1
For ctr2 = root To 0 Step -1
lchild = (2 * ctr2) + 1
rchild = (2 * ctr2) + 2
If lchild <= upbound And rchild <= upbound Then
If arr(rchild) >= arr(lchild) Then
mchild = rchild
Else
mchild = lchild
End If
Else
If rchild > upbound Then
mchild = lchild
Else
mchild = rchild
End If
End If

If arr(ctr2) < arr(mchild) Then
temp = arr(ctr2)
arr(ctr2) = arr(mchild)
arr(mchild) = temp
End If
Next ctr2
Next ctr```
Thanks in advance.

2. ## Re: Variable not getting a value

Originally Posted by znerol
...but the inner loops doesn't seem to get the value I want it to get...
What did you get and what were you expecting? Could you be a bit more explicit?

3. ## Re: Variable not getting a value

What is the value of root?
Make the first line of the inner loop a breakpoint. What values do ctr and ctr2 get?

#### Posting Permissions

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

Featured

Click Here to Expand Forum to Full Width