Macros and Programming


CardboxForumsMacros and Programming > "Problem processing array calling subroutines"

Problem processing array calling subroutines

Macro only processing first item in an array when subroutines are called

Current user: [none]
Register / Log In · Help

Posted By Post

Mary Doyle (DAF)

8-Oct-2010 17:25

I have a macro that starts in my MonthlyTrade database
I am selecting a series of records (trade codes) - a much longer list than
illustrated here
The selected records in the master file are then read to a temporary database (SR), where
they are edited by calling subroutines

When I run the macro and don't edit the records by calling the subroutines
the macro works through each code in the array in turn and the line

MsgBox TimberCode2(i) will list each code in turn.

However as soon as I include any of the subroutines the macro runs correctly for the
first code in the list (i.e. runs all the subroutines and returns to the MonthlyTrade
database) but it doesn't process the next code.

I hope this is clear and I would appreciate any suggestions as to what I am doing wrong.

Yes, I know it's Friday evening......

TimberCodes2 = "44071000:44071099,44072500:44072599"
TimberCode2 = Split(TimberCodes2,",")

' In MonthlyTrade at this point
For i = 0 to Ubound(TimberCode2)
MsgBox "About to run next code"
SelectionLevel = 0
ActiveWindow.Select "cn",TimberCode2(i)
n = Records.Count
If n = 0 Then
MsgBox "There are no records for " & TimberCode2(i)
ElseIf n <> 0 Then
MsgBox TimberCode2(i)
Activate "sr"
ReadFromCardbox 0,Windows("MonthlyTrade").Records
Call EditCode
Call CountryName
Call CalculateTotalAndValue
MsgBox "About to activate MonthlyTrade"
Activate "MonthlyTrade"
End If


8-Oct-2010 18:50

Hi Mary,

Add just after
For i = 0 to Ubound(TimberCode2)
msgbox i
You can find out if i is right value.

Perhaps the "call" commands does erase the value of i?

I think you can avoid losing the value for i by adding in your macro in first line dim i

Check also if there is in the subroutines not another i....

Then your line
   ElseIf n <> 0 Then

You can change to simple
(if n = 0 then else everrything is of course <> 0)


Mary Doyle

8-Oct-2010 19:43

Hi Bert,

I think you have hit the nail on the head, the subroutines are probably changing the value of i. Can't check now until Monday as the databases are in work, but knowing what is in the subroutines I think you are probably right and will let you know. The "ElseIf n <> 0" is a hangover from an earlier stage of developing the macro and I can, of course, remove it.

Many thanks and have a good weekend.


Mary Doyle (DAF)

11-Oct-2010 11:14

Hi Bert,
As expected you did indeed hit the nail on the head. All now working. Thank you for saving me a lot of head scratching.


Quick Reply

Please log in or register before trying to post a reply.

© 2010 Cardbox Software Limited   Home