cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
DLee65
Level 13

sprintf %c fails in for loop

The following code snippet fails with an error stating wrong data type.
cDisk is a data type CHAR.


...

for cDisk = 'a' to 'z'
Sprintf(strDrive, "%c", cDisk);
endfor;



If I remove the for loop then the Sprintf works correctly.

...
cDisk = 'a';
Sprintf(strDrive, "%c", cDisk);


When I inspect the value of cDisk in the for loop, it has the correct value of 97.

So what is happening with the for loop to cause this to fail?
Labels (1)
0 Kudos
(2) Replies
Alpesh
Flexera Alumni

Hi Dan,

I did some testing with Installscript and found that the counter begin and end values in the for statement need to be number only. Even though it does not give any error at compile-time, if you use char values.

The following code should solve your purpose -

function ShowVal (hMSI)
string strDrive;
number nA, nZ, nDrive;
begin

nA = 'a';
nZ = 'z';
for nDrive = nA to nZ
Sprintf(strDrive, "%c", nDrive);
endfor;

end;
0 Kudos
DLee65
Level 13

Thank you very much Alpesh. That does work.
0 Kudos