dba123
asked on
Problem with for statement
for i=0 to UBound(array,2) ' Go Up to Down in array (column)
for j=0 to UBound(array,1) ' Go left to right in array (row)
If ((j <> 0) OR (j <> 3)) Then
objSpreadsheet.Cells(i + 2,j + 1).Value = array(j,i)
End If
next
Next
This doesn't work. The OR portion is what is not working. If I use one parameter, it works fine and skips that value in the array:
for i=0 to UBound(array,2) ' Go Up to Down in array (column)
for j=0 to UBound(array,1) ' Go left to right in array (row)
If j <> 3 Then
objSpreadsheet.Cells(i + 2,j + 1).Value = array(j,i)
End If
next
Next
for j=0 to UBound(array,1) ' Go left to right in array (row)
If ((j <> 0) OR (j <> 3)) Then
objSpreadsheet.Cells(i + 2,j + 1).Value = array(j,i)
End If
next
Next
This doesn't work. The OR portion is what is not working. If I use one parameter, it works fine and skips that value in the array:
for i=0 to UBound(array,2) ' Go Up to Down in array (column)
for j=0 to UBound(array,1) ' Go left to right in array (row)
If j <> 3 Then
objSpreadsheet.Cells(i + 2,j + 1).Value = array(j,i)
End If
next
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
what about this one
for ((i=0 to UBound(array,2)) AND (a=0 to Ubound(array,2))) ' Go Up to Down in array (column)
for ((j=0 to UBound(array,1)) AND ((b=0 to Ubound(array,2))) ' Go left to right in array (row)
If ((b <> 0) AND (b <> 3)) Then
objSpreadsheet.Cells(i + 2,j + 1).Value = array(b,a)
End If
next
Next
giving me error:
Expected identifier
for ((i=0 to UBound(array,2)) AND (a=0 to Ubound(array,2)))
for ((i=0 to UBound(array,2)) AND (a=0 to Ubound(array,2))) ' Go Up to Down in array (column)
for ((j=0 to UBound(array,1)) AND ((b=0 to Ubound(array,2))) ' Go left to right in array (row)
If ((b <> 0) AND (b <> 3)) Then
objSpreadsheet.Cells(i + 2,j + 1).Value = array(b,a)
End If
next
Next
giving me error:
Expected identifier
for ((i=0 to UBound(array,2)) AND (a=0 to Ubound(array,2)))
It's not possible to have condition like that...:(
What are you trying to do? Can't you use same i , j for a, b?
What are you trying to do? Can't you use same i , j for a, b?
ASKER
basically, I can't use j and i for both the spreadsheet cells and the array. Because the spreadsheet cell columns are off if I skip j when I used j in the array (shown at the very top in my initial post)
So I am only wanting to skip the array value if the array value is 0 or 3, not the spreadsheet cell so that is why I used another pair of variables for the array..so I can just check for 0 or 3 just for the array.....the spreadsheet should remain using the j and i as is.
So I am only wanting to skip the array value if the array value is 0 or 3, not the spreadsheet cell so that is why I used another pair of variables for the array..so I can just check for 0 or 3 just for the array.....the spreadsheet should remain using the j and i as is.
Try this..
for a=0 to Ubound(array,2) ' Go Up to Down in array (column)
for b=0 to Ubound(array,2) ' Go left to right in array (row)
If ((b <> 0) AND (b <> 3)) Then
objSpreadsheet.Cells(i + 2,j + 1).Value = array(b,a)
j=j+1
End If
next
i=i+1
Next
for a=0 to Ubound(array,2) ' Go Up to Down in array (column)
for b=0 to Ubound(array,2) ' Go left to right in array (row)
If ((b <> 0) AND (b <> 3)) Then
objSpreadsheet.Cells(i + 2,j + 1).Value = array(b,a)
j=j+1
End If
next
i=i+1
Next
you may need to change
for b=0 to Ubound(array,2)
to
for b=0 to Ubound(array,1) ...
for b=0 to Ubound(array,2)
to
for b=0 to Ubound(array,1) ...
ASKER
j=0
i=0
for a=0 to Ubound(array,2) ' Go Up to Down in array (column)
for b=0 to Ubound(array,2) ' Go left to right in array (row)
If ((b <> 0) AND (b <> 3)) Then
objSpreadsheet.Cells(i + 2,j + 1).Value = array(b,a)
j=j+1
End If
next
i=i+1
Next
End If
I get an error, I think because of where I set the initial value for the i and j variables
Microsoft Office Web Components 9.0 error 'e004002a'
i=0
for a=0 to Ubound(array,2) ' Go Up to Down in array (column)
for b=0 to Ubound(array,2) ' Go left to right in array (row)
If ((b <> 0) AND (b <> 3)) Then
objSpreadsheet.Cells(i + 2,j + 1).Value = array(b,a)
j=j+1
End If
next
i=i+1
Next
End If
I get an error, I think because of where I set the initial value for the i and j variables
Microsoft Office Web Components 9.0 error 'e004002a'
ASKER
I changed the Ubound from 2 to 1, just that you don't see it in my post above
Couple of bugfixes before you findout yourself!
for i=0 to UBound(array1,2) ' Go Up to Down in array (column)
for j=0 to UBound(array1,1) ' Go left to right in array (row)
If ((j <> 0) AND (j <> 3)) Then
objSpreadsheet.Cells(i + 2,j + 1).Value = array(b,a)
j=j+1
End If
next
j=0
i=+1
Next
for i=0 to UBound(array1,2) ' Go Up to Down in array (column)
for j=0 to UBound(array1,1) ' Go left to right in array (row)
If ((j <> 0) AND (j <> 3)) Then
objSpreadsheet.Cells(i + 2,j + 1).Value = array(b,a)
j=j+1
End If
next
j=0
i=+1
Next
ASKER
Here it is
for a=0 to Ubound(array,2) ' Go Up to Down in array (column)
j=0
for b=0 to Ubound(array,1) ' Go left to right in array (row)
i=0
If ((b <> 0) AND (b <> 3)) Then
objSpreadsheet.Cells(i + 2,j + 1).Value = array(b,a)
j=j+1
End If
next
i=i+1
Next
End If
for a=0 to Ubound(array,2) ' Go Up to Down in array (column)
j=0
for b=0 to Ubound(array,1) ' Go left to right in array (row)
i=0
If ((b <> 0) AND (b <> 3)) Then
objSpreadsheet.Cells(i + 2,j + 1).Value = array(b,a)
j=j+1
End If
next
i=i+1
Next
End If
ASKER
thanks much!!!
Looks ok... Are you still getting that error?
Ok I didn't see your post
ASKER