[RESOLVED] [02/03] What's wrong with these for loops!?!
I have 3 loops, the outer loop goes from 0 to 4, the middle from 0 to 15 and the inner is 0 to 15. The problem is that only the outer loop actually goes to its max, the middle and inner loops exit before the counter reaches the max value of 15. The same exact loop works perfectly in VB6, what is going on here? What am I missing?
Code:
For ha = 0 To stb.sS.scan.numHa - 1 Step ha + 1
stbd.VBSCSIResetHBA(Convert.ToInt32(ha))
For lun = 0 To stb.MAX_LUN - 1 Step lun + 1
For scsiId = 0 To 15 Step scsiId + 1
devType = stbd.VBSCSIGetDeviceType(ha, scsiId, lun)
If devType > 0 Then
If devType > &HES Then
devType = 16
End If
stb.sS.scan.numDev(devType) = stb.sS.scan.numDev(devType) + 1
Select Case devType
Case stb.TYPE_TAPE
stb.sS.scan.tapeNexus(stb.sS.scan.numDev(devType)).ha = ha
stb.sS.scan.tapeNexus(stb.sS.scan.numDev(devType)).target = scsiId
stb.sS.scan.tapeNexus(stb.sS.scan.numDev(devType)).lun = lun
device = "TAPE DRIVE"
collection.UUT(scsiId).ha = ha
collection.UUT(scsiId).target = scsiId
collection.UUT(scsiId).lun = lun
Case stb.TYPE_LIBRARY
stb.sS.scan.libNexus(stb.sS.scan.numDev(devType)).ha = ha
stb.sS.scan.libNexus(stb.sS.scan.numDev(devType)).target = scsiId
stb.sS.scan.libNexus(stb.sS.scan.numDev(devType)).lun = lun
device = "LIBRARY/LOADER"
Case stb.TYPE_SNC
stb.sS.scan.sncNexus(stb.sS.scan.numDev(devType)).ha = ha
stb.sS.scan.sncNexus(stb.sS.scan.numDev(devType)).target = scsiId
stb.sS.scan.sncNexus(stb.sS.scan.numDev(devType)).lun = lun
device = "SNC"
End Select
End If
Next scsiId
Next lun
Next ha
Re: [02/03] What's wrong with these for loops!?!
For lun = 0 To stb.MAX_LUN - 1 Step lun + 1
first time lun = 0
second lun =1
third lun =3
fourth = 7
if you want 0 to 15 why aren't you saying
for lun = 0 to 15
Re: [02/03] What's wrong with these for loops!?!
Thanks
stb.MAX_LUN is a constant at 16, I could very well say for lun = 0 to 15, however, is there something wrong with using a constant in VB.NET loop? Like I said the exact same VB6 code runs perfectly each loop to their max, I still don't understand why this behaves differently.
Re: [02/03] What's wrong with these for loops!?!
For lun = 0 To stb.MAX_LUN - 1 Step lun + 1
could be
For lun = 0 To stb.MAX_LUN - 1
it was the step lun + 1 that was the problem.
Re: [02/03] What's wrong with these for loops!?!
Quote:
Originally Posted by dbasnett
For lun = 0 To stb.MAX_LUN - 1 Step lun + 1
could be
For lun = 0 To stb.MAX_LUN - 1
it was the step lun + 1 that was the problem.
Thank you but why? according to the MSDN if it is omitted (Step lun+1) then it automatically increments the counter by 1. And I believe C# also requires that
for int x = 0; i=15; x++
Re: [02/03] What's wrong with these for loops!?!
If you want to use step then
For lun = 0 To stb.MAX_LUN - 1 step 1
Re: [RESOLVED] [02/03] What's wrong with these for loops!?!
Damn, I just noticed that, it's step 1 not step lun +1, thanks I'm an ID10T