Quail wrote:Hi Alan,
My apologies I should have been more specific - my first posting!
The TI actually creates 1 new asset but obviously I have not looped it appropriately and cannot create any more - here is the script
DimName = 'Asset';
vNum = CellGetS(‘Control', 'Current_Asset_Number', 'Assetcounter');
vQtr = CellGetS('Control', 'Current_Asset_Number', 'Timecode');
vNew = pNumber; (pNumber = the number of new assets to be created - entered by the user)
vNumIncrement = STR((NUMBR(vNum) + 1) , 4, 0);
iAssetNo = 1;
WHILE (iAssetNo <= vNew);
vAssetCode = vQtr|vNum;
DimensionElementInsert(DimName, '', vAssetCode,'N');
CellPutS(vNumIncrement, 'Control', 'Current_Asset_Number', 'Assetcounter');
iAssetNo = iAssetNo +1;
END;
thanks
Your problem is that you're only incrementing outside the loop. That means that no matter how many assets the user asks for, they get only one.
This looks OK:
Code: Select all
DimName = 'Asset';
vNum = CellGetS(‘Control', 'Current_Asset_Number', 'Assetcounter');
vQtr = CellGetS('Control', 'Current_Asset_Number', 'Timecode');
vNew = pNumber; (pNumber = the number of new assets to be created - entered by the user)
But this is wrong:
Code: Select all
vNumIncrement = STR((NUMBR(vNum) + 1) , 4, 0);
because it means that you only ever increment the original value by 1. (And looking at the code again, it never actually uses that increment to create a new element (since you're using the vNum value that you read from the control cube), but rather to update the control cube. Though it'll create the incremented element the second time you run the code.)
It would need to be (untested):
Code: Select all
iAssetNo = 1;
WHILE ( iAssetNo <= vNew);
vNumIncrement = STR( (NUMBR(vNum) + iAssetNo) , 4, 0);
vAssetCode = vQtr|vNumIncrement;
DimensionElementInsert(DimName, '', vAssetCode,'N');
CellPutS(vNumIncrement, 'Control', 'Current_Asset_Number', 'Assetcounter');
iAssetNo = iAssetNo +1;
END;
Actually there are a couple of efficiencies that you could introduce there too;
(a) You could convert vNum to a number as soon as you read it from the cube so that you don't have to do it each loop;
(b) You could do the CellPutS to the control cube after the end of the loop since you don't need to update that for every iteration of the loop either.
The only reason that I didn't do that is that wanted to change your code as little as possible to help you get a better idea of where the problem is.
I'd also suggest doing a test to make sure that the number input to pNumber is valid; not <=0 or higher than the number of projects that they're allowed to create.