- Revenera Community
- :
- InstallShield
- :
- InstallShield Forum
- :
- How to get ASCII value for character?
- 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
I am trying to check if a string contains an uppercase and a lowercase character. So need to get the ASCII value for a character. I tried using 'Asc' function but didn't work. How can we can get the ASCII value for a character?
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Okay, just a screenshot from my InstallScript debugger:
In InstallScript you do not need the "Asc"-function, just assign one character from a string to the "CHAR" data type. Internal it is an int with the ASCII value. You can also assign a CHAR directly to a NUMBER data type.
regards
Markus
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
You will not be able to check for the case of characters using just InstallScript. As far as I can tell, all InstallScript string comparison functions are case insensitive. An example is
StrCompare( "A", "a")
which will return 0 (indicates that the two strings are equal). By implication, this means you will not be able to get the correct ASCII value of a character using just InstallScript.
Using VBScript and regex, you can create a function that will work. Note that VBScript is going away eventually so I wouldn't recommend relying on that and instead write a custom DLL to do the work if you need it. Here is the regex example:
prototype BOOL HasUpperAndLowerCase( byval STRING, byref STRING );
//---------------------------------------------------------------------------
function BOOL HasUpperAndLowerCase( szInput, svError )
OBJECT objRegEx;
BOOL bHasUpperAndLowerCase;
begin
bHasUpperAndLowerCase = FALSE;
svError = "";
if (szInput = "") then
svError = "input string is empty";
else
try
// use VBScript & Regex. NOTE: VBScript support is going away:
// https://community.flexera.com/t5/InstallShield-Knowledge-Base/VBScript-Deprecation-Impact-on-InstallShield/ta-p/311788/
set objRegEx = CoCreateObject( "VBScript.RegExp" );
if IsObject( objRegEx ) then
// determine if the input string has upper and lower characters by using a regular expression
objRegEx.Pattern = "(?=.*[a-z])(?=.*[A-Z])";
objRegEx.IgnoreCase = FALSE;
bHasUpperAndLowerCase = objRegEx.Test( szInput );
else
// RegExp is not an object
svError = "RegExp is not an object";
endif;
catch
svError = "Error checking case: " + Err.Description;
endcatch;
if !bHasUpperAndLowerCase then
svError = "Does not have upper and lowercase";
endif;
endif;
return bHasUpperAndLowerCase;
end;
usage:
bHasUpperAndLowerCase = HasUpperAndLowerCase( szInput, svError );
if (bHasUpperAndLowerCase) then
MessageBox( "string has Upper and Lowercase characters.", INFORMATION );
else
MessageBox( svError, SEVERE );
endif;
HTH
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
In which project type do you work (MSI or InstallScript or ...) ?
regards
Markus
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
We are working on an installShield project which creates an exe and uses some script written in InstallScript.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Okay, just a screenshot from my InstallScript debugger:
In InstallScript you do not need the "Asc"-function, just assign one character from a string to the "CHAR" data type. Internal it is an int with the ASCII value. You can also assign a CHAR directly to a NUMBER data type.
regards
Markus
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
Thank you @MarkusLatz & @ch_eng2 for the replies. I was able to perform the validation based on the on the suggestion of @MarkusLatz .