Flexera Software Community  

Go Back   Flexera Software Community > Products > Legacy Installer Products > InstallShield > InstallShield Windows 11.5
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-14-2006, 12:17 PM
Rincewind's Avatar
Rincewind Rincewind is offline
User (5+ Posts)
 
Join Date: Jun 2003
Location: Austin, TX, USA
Posts: 26
Problems calling VBScript/COM objects from InstallScript

Can anyone tell whats wrong with this function?
It is supposed to create an VBscript Regexp object and then test a string against the expression and return the result of the test (TRUE/FALSE).
It always returns FALSE, even when it obviously should be TRUE - tested a simple expression. Am I missing something in how to call VBScript/COM objects and test return codes?

Code:
prototype BOOL ValidateString(STRING, STRING); 
function BOOL ValidateString(szString,szPattern)
OBJECT oRegEx, oMatch;  
BOOL MatchFound;
begin
	
	//try to create the RegEx object
	try
		set oRegEx = CreateObject("VBScript.RegExp");
	catch
		MessageBox("CreateObject Failed- "+ Err.Decription, SEVERE);
	endcatch;
	
	oRegEx.Pattern = szPattern;
	oRegEx.IgnoreCase = 0;
	oRegEx.Global = 1;  //set to 1 to find all matches in the string
			//set to 0 to find only the first match
	try
		set oMatch = oRegEx.Execute(szString);
	catch
		MessageBox("CreateObject Failed- "+ Err.Decription, SEVERE);
	endcatch;
	
	MatchFound = (oMatch.Count > 0);
	return MatchFound;
end;
Actually, that was a second attempt. The initial attempt was to call the Test method of REGEX directly, but that didn't work either.

Code:
prototype BOOL ValidateString(STRING, STRING); 
function BOOL ValidateString(szString,szPattern)
OBJECT oRegEx;  
BOOL MatchFound;
begin
	
	//try to create the RegEx object
	try
		set oRegEx = CreateObject("VBScript.RegExp");
	catch
		MessageBox("CreateObject Failed- "+ Err.Decription, SEVERE);
	endcatch;
	
	oRegEx.Pattern = szPattern;
	oRegEx.IgnoreCase = 0;
	oRegEx.Global = 1;  //set to 1 to find all matches in the string
			//set to 0 to find only the first match
	MatchFound = oRegEx.Test(szString);
	return MatchFound;
end;
This is being #included into a setup.rul in an InstallScriptMSI project.
Reply With Quote
  #2  
Old 07-14-2006, 02:09 PM
Rincewind's Avatar
Rincewind Rincewind is offline
User (5+ Posts)
 
Join Date: Jun 2003
Location: Austin, TX, USA
Posts: 26
Talking Solved it!!

Turns out I only needed to declare the Pattern variable as a "VARIANT".
Can be taken care of in the PROTOTYPE declaration:
Code:
prototype BOOL ValidateString(STRING, VARIANT);
The second set of code works great as a regular expression tester if anyone else is looking for one. Use the above prototype and this code:
Code:
function BOOL ValidateString(szString,szPattern)
OBJECT oRegEx;   
BOOL MatchFound;
begin
		            
	//try to create the RegEx object
	try
		set oRegEx = CoCreateObject("VBScript.RegExp");
	catch
		MessageBox("CoCreateObject Failed- "+ Err.Decription, SEVERE);
	endcatch;
	oRegEx.Pattern = szPattern;
	oRegEx.IgnoreCase = 0;
	MatchFound = oRegEx.Test(szString);  
	set oRegEx = NOTHING;
	return MatchFound;
end;
Reply With Quote
  #3  
Old 06-08-2007, 12:44 PM
bwknight's Avatar
bwknight bwknight is offline
Power User (30+ Posts)
 
Join Date: Dec 2004
Location: Durham, NC
Posts: 36
cant call the function!

I have tried your solution to validate a string

my regular expression is defined like so:
#define PATTERN "^[\w]*$"

That should match any string of alphanumeric characters, which is what I want.

I have tried calling the ValidateString method several different ways, in each instance it always returns FALSE.

How do you call the ValidateString method?
Reply With Quote
  #4  
Old 06-08-2007, 02:00 PM
Rincewind's Avatar
Rincewind Rincewind is offline
User (5+ Posts)
 
Join Date: Jun 2003
Location: Austin, TX, USA
Posts: 26
Must use a STRING variable

Quote:
Originally Posted by bwknight View Post
I have tried your solution to validate a string

my regular expression is defined like so:
#define PATTERN "^[\w]*$"

That should match any string of alphanumeric characters, which is what I want.

I have tried calling the ValidateString method several different ways, in each instance it always returns FALSE.

How do you call the ValidateString method?
I'm not using it anymore - the need went away.
But, a check in some older code showed the following:

Code:
	STRING	emailPattern;
	emailPattern="\w+@\w+\.\w+";
...
	elseif (!ValidateString(svMailAddr,emailPattern)) then
		MessageBox ("Invalid format for an email address.", WARNING);
		dlgCtrl = GetDlgItem (hwndDlg, RES_MAIL_ADDR);
		SetFocus (dlgCtrl);
		CtrlSelectText (szDialogName, RES_MAIL_ADDR);
...
Arguably not the best string for validating an email address, but it was working.
Make sure you are using the version from my corrected post and you've declared the PROTOTYPE correctly.

Last edited by Rincewind : 06-08-2007 at 02:02 PM. Reason: Adding a comment
Reply With Quote
  #5  
Old 02-05-2008, 04:12 PM
Rincewind's Avatar
Rincewind Rincewind is offline
User (5+ Posts)
 
Join Date: Jun 2003
Location: Austin, TX, USA
Posts: 26
Watch your quoting and slashes

When generating your regular expression string, remember that Installscript will impose some requirements on your string:
embeded quotes must be escaped with a backslash (\)
embedded backslashes must also be escaped with a backslash (i.e. \\, not \)
My string in the previous post wouldn't work because the backslashes were only singled, not doubled.
That is, it should have been:
Code:
emailPattern="\\w+@\\w+\\.\\w+";
Here's a better example (though it probably isn't 100% accurate):

Code:
// real pattern: ^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,})$
emailPattern='^(([^<>()[\\]\\\\.,;:\\s@\\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\\"]+)*)|(\\".+\\"))@(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,})$';
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -6. The time now is 05:16 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© 2010 Flexera Software Inc. All rights reserved.