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
- :
- Re: Cannot execute VBScript function inside InstallScript
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
‎Feb 24, 2010
01:42 PM
Cannot execute VBScript function inside InstallScript
Hi,
I've used the following function through several versions of Installshield, but it doesn't seem to be working in InstallShield 2010.
It is called with the following code snippets to validate a proper email address format:
[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,})$';
if (!ValidateString(svMailAddr,emailPattern)) then
[/CODE]
It always takes the "then" clause in IS2010. It has worked, unchanged, in all previous versions of IS back to IS7.
Anyone have any idea what changed in IS2010 to make this no longer work?
I've used the following function through several versions of Installshield, but it doesn't seem to be working in InstallShield 2010.
prototype BOOL ValidateString(STRING, VARIANT);
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;
It is called with the following code snippets to validate a proper email address format:
[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,})$';
if (!ValidateString(svMailAddr,emailPattern)) then
[/CODE]
It always takes the "then" clause in IS2010. It has worked, unchanged, in all previous versions of IS back to IS7.
Anyone have any idea what changed in IS2010 to make this no longer work?
(5) Replies
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Feb 25, 2010
05:17 PM
Turns out both parameters need to be declared "VARIANT" in the prototype definition. Wonder what changed between releases.
prototype BOOL ValidateString(VARIANT, VARIANT);
prototype BOOL ValidateString(VARIANT, VARIANT);
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Feb 26, 2010
04:17 PM
I'm not sure what the issue could have been here. With your original code (assuming I am understanding the intention of this code correctly), I can get true or false results from ValidateString with the original function prototype. I am passing two string variables (for szString and szPattern) to ValidateString, one with the pattern posted, and the other containing some text or an email address.
There haven't been any changes to the core script engine for a while (with the exception of a change made for calling DLL functions) that could explain the behavior you are seeing.
There haven't been any changes to the core script engine for a while (with the exception of a change made for calling DLL functions) that could explain the behavior you are seeing.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Apr 22, 2010
10:27 AM
I still can't get this to work. I tried having szString and szPattern both set as STRING, then as VARIANT, and still doesn't work. I added a line to display the boolean value in the function
I'm still only getting the else clause in my if-else condition. I switched the if check from MatchFound = TRUE to MatchFound = FALSE, and it still always takes the else. This makes me think something is wrong and MatchFound is not getting a true or false result.
if(MatchFound = TRUE) then
MessageBox("match found", INFORMATION);
else
MessageBox("match not found", INFORMATION);
endif;
I'm still only getting the else clause in my if-else condition. I switched the if check from MatchFound = TRUE to MatchFound = FALSE, and it still always takes the else. This makes me think something is wrong and MatchFound is not getting a true or false result.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Apr 22, 2010
10:51 AM
okay, it seems my MatchFound boolean has an error value. I'm not sure why my function isn't working. Does VBScript have to be setup to work correctly? No catch message is thrown when creating oRegEx object in the try block.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Apr 22, 2010
12:53 PM
I don't do anything special to enable VBScript, but it does need to exist on the system you are running the installer on. All the code is as you see it. There is one thing I didn't mention in the earlier posts: In the calling routine, I have the emailPattern declared as a WSTRING. In IS2009 and before, I just defined it as a STRING. I'm pretty sure I made that change before changing the protoype declaration, so it may be that the combination is what was needed.
One thing I know for sure, do not try to pass the pattern as a literal. That will cause all sorts of issues.
Here are the currently working code snippets for IS2010:
The calling routine (actually a custom dialog):
[CODE]
WSTRING emailPattern;
// 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,})$';
if (!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);
endif;
[/CODE]
The function itself:
If you are getting an error code, you will need to see what that code means to VBScript. Otherwise, I would expect a problem with your regular expression. I would set it up in a separate VBscript for testing, using the regular VBscript error mechanism to see what it is telling you. One you get it working there, then transfer the pattern to your InstallScript. When you make the transfer, you will need to convert every "\" to "\\" or Installscript will eat them.
One thing I know for sure, do not try to pass the pattern as a literal. That will cause all sorts of issues.
Here are the currently working code snippets for IS2010:
The calling routine (actually a custom dialog):
[CODE]
WSTRING emailPattern;
// 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,})$';
if (!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);
endif;
[/CODE]
The function itself:
// function prototype declaration
prototype BOOL ValidateString(VARIANT, VARIANT);
///////////////////////////////////////////////////////////////////////////////////////////////
//
// ValidateString
//
// This function uses the VBScript regular expression object
// found in Windows Scripting Host v5 and above to validate
// strings in IS Script.
//
// Refer to- http://msdn.microsoft.com/scripting for more information
// about the RegExp object and VBScript
//
////////////////////////////////////////////////////////////////////////////////////////////////
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;
If you are getting an error code, you will need to see what that code means to VBScript. Otherwise, I would expect a problem with your regular expression. I would set it up in a separate VBscript for testing, using the regular VBscript error mechanism to see what it is telling you. One you get it working there, then transfer the pattern to your InstallScript. When you make the transfer, you will need to convert every "\" to "\\" or Installscript will eat them.
![](/skins/images/D60DF682EA37BF37032955CE10F3F0BB/responsive_peak/images/icon_anonymous_message.png)