This website uses cookies. By clicking Accept, you consent to the use of cookies. Click Here to learn more about how we use cookies.
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
- Revenera Community
- :
- InstallShield
- :
- InstallShield Forum
- :
- sprintf %c fails in for loop
Subscribe
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Oct 15, 2007
12:52 PM
sprintf %c fails in for loop
The following code snippet fails with an error stating wrong data type.
cDisk is a data type CHAR.
If I remove the for loop then the Sprintf works correctly.
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?
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?
(2) Replies
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Oct 15, 2007
05:46 PM
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;
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;
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Oct 16, 2007
07:46 AM
Thank you very much Alpesh. That does work.