cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Nikhil7302
Level 3

How to get ASCII value for character?

Jump to solution

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?

Labels (1)
0 Kudos
(1) Solution

Okay, just a screenshot from my InstallScript debugger:

IS-SampleCharUse.pngIn 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

View solution in original post

0 Kudos
(5) Replies
ch_eng2
Level 6

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

0 Kudos
MarkusLatz
Level 8

In which project type do you work (MSI or InstallScript or ...) ?

regards

Markus

0 Kudos

We are working on an installShield project which creates an exe and uses some script written in InstallScript.

0 Kudos

Okay, just a screenshot from my InstallScript debugger:

IS-SampleCharUse.pngIn 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

0 Kudos
Nikhil7302
Level 3

Thank you @MarkusLatz  & @ch_eng2 for the replies. I was able to perform the validation based on the on the suggestion of @MarkusLatz . 

0 Kudos