Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating Array Loop Problem

Status
Not open for further replies.

Chance1234

IS-IT--Management
Jul 25, 2001
7,871
US
Code:
'1. Create Army-----------------
'
intC = 4
IntR = 2

'1.1 Find out size of army

Do Until IntR = 22
  If IntR <= 11 Then
    lngA = lngA + RngArm.Cells(IntR, 4)
  Else
    LngB = LngB + RngArm.Cells(IntR, 4)
  End If
  IntR = IntR + 1
Loop


'1.2 Set up arrays

ReDim arrA(lngA, 10)
ReDim arrB(LngB, 10)


Do Until IntR = 22
    lngA = lngX + lngA
    LngB = lngZ + LngB
    lngX = 1
    lngZ = 1
   
    
    If RngArm.Cells(IntR, 1) = "A" Then 'ROMANS
        Do Until lngX = RngArm.Cells(IntR, 4)
            arrA(lngX + lngA, 1) = RngArm.Cells(IntR, 2)
            arrA(lngX + lngA, 2) = RngArm.Cells(IntR, 3)
                Do Until lngZ = 41
                    If RngScores(lngZ, 1) = RngArm.Cells(IntR, 3) Then
                       arrA(lngX + lngA, 3) = RngScores.Cells(lngZ, 3)
                       arrA(lngX + lngA, 4) = RngScores.Cells(lngZ + 1, 3)
                       arrA(lngX + lngA, 5) = RngScores.Cells(lngZ + 2, 3)
                       arrA(lngX + lngA, 6) = RngScores.Cells(lngZ + 3, 3)
                       arrA(lngX + lngA, 7) = RngScores.Cells(lngZ + 4, 3)
                       arrA(lngX + lngA, 8) = RngScores.Cells(lngZ + 5, 3)
                       arrA(lngX + lngA, 9) = RngScores.Cells(lngZ + 6, 3)
                       Exit Do
                    End If
                    lngZ = lngZ + 1
                Loop
                lngZ = 1
                lngX = lngX + 1
        Loop
    ElseIf RngArm.Cells(IntR, 1) = "B" Then 'Britains
        Do Until lngX = RngArm.Cells(IntR, 4)
            arrB(lngX + LngB, 1) = RngArm.Cells(IntR, 2)
            Debug.Print RngArm.Cells(IntR, 2)
            
            arrB(lngX + LngB, 2) = RngArm.Cells(IntR, 3)
                Do Until lngZ = 41
                    If RngScores(lngZ, 1) = RngArm.Cells(IntR, 3) Then
                       arrB(lngX + lngA, 3) = RngScores.Cells(lngZ, 4)
                       arrB(lngX + lngA, 4) = RngScores.Cells(lngZ + 1, 4)
                       arrB(lngX + lngA, 5) = RngScores.Cells(lngZ + 2, 4)
                       arrB(lngX + lngA, 6) = RngScores.Cells(lngZ + 3, 4)
                       arrB(lngX + lngA, 7) = RngScores.Cells(lngZ + 4, 4)
                       arrB(lngX + lngA, 8) = RngScores.Cells(lngZ + 5, 4)
                       arrB(lngX + lngA, 9) = RngScores.Cells(lngZ + 6, 4)
                       Exit Do
                    End If
                    lngZ = lngZ + 1
                Loop
                lngZ = 1
                lngX = lngX + 1
        Loop
    End If
    IntR = IntR + 1
Loop



RngArmy looks like the following

Code:
Side	He	Type	Total
A	 XI	Sk	1000
A	 XI	Inf	3840
A	 XI	Ainf	1000
A	 XI	Calv	300
A	 XI	Acalv	200

etc etc

RngScores Looks like

Code:
Type	Traits	A	B
Acalv	Attack	42	0
Acalv	Damage	32	0
Acalv	Defence	12	0
Acalv	Discipline	75	0
Acalv	Loyalty 	60	0
Acalv	Stamina	30	0
Acalv	Strength	68	0

I keep getting out of range errors, when populating the britains! but cant see what is causing that.


Chance,

Filmmaker, taken gentleman and He tan e epi tas
 
just to explain that a bit better.

THe error is on this line here

arrB(lngX + LngB, 1) = RngArm.Cells(IntR, 2)

I cant se what is making LngX + lngB > than
ReDim arrB(LngB, 10)



Chance,

Filmmaker, taken gentleman and He tan e epi tas
 
Maybe you need to move the Romans closer until the Britains are in range. j/k

But seriously, in the Romans loop the value lngX is being incremented. Maybe you need to reset its value before proceeding with the Britain loop?

Here is the part of the code I'm talking about:
Code:
.
.
.
                lngX = lngX + 1
        Loop
    ElseIf RngArm.Cells(IntR, 1) = "B" Then 'Britains
.
.
.

Might need to be:
Code:
.
.
.
                lngX = lngX + 1
        Loop
    ElseIf RngArm.Cells(IntR, 1) = "B" Then 'Britains
        lngX=1
.
.
.
or something similar.
 
Huh?
Chance1234 said:
I cant se what is making LngX + lngB > than
ReDim arrB(LngB, 10)
Unless LngX is always zero then LngX+LngB will always be greater than LngB. Am I missing something?

Regards,
Mike
 
Finally got it to work , by moving the LngB = lngZ + LngB

from the top of the loop.

Chance,

Filmmaker, taken gentleman and He tan e epi tas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top