Results 1 to 7 of 7

Thread: [RESOLVED] [02/03] What's wrong with these for loops!?!

  1. #1

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    51

    Resolved [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

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    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
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    51

    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.

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    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.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    51

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

  6. #6
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    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
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  7. #7

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    51

    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

Posting Permissions

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



Click Here to Expand Forum to Full Width