MSSCHED sharing violation with VB-RegExp
Moderators: JRL, Dorian (MJT support)
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
MSSCHED sharing violation with VB-RegExp
An earlier posting on another topic made reference to Regular Expressions in MultiEdit. I have always tried to come up with solutions within MacroSched vs. using other programs. So I decided to get more familiar with the VB function RegExp.
After a few modifications to eliminate some compile errors, I got the compiler portion to run every line without error. But when the End Function is finally reached, I get an error that forces me to restart MacroSched from Close Program window. SHIFT-ESC will not stop macro.
The VB code below is from the MSDN manual section on RegExp.
=========================================
VBSTART
VBEND
Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches ' Create variable.
regEx = New RegExp ' Create a regular expression. (Was with Set.)
regEx.Pattern = patrn ' Set pattern.
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True ' Set global applicability.
Matches = regEx.Execute(strng) ' Execute search. (Was with Set.)
For Each Match in Matches ' Iterate Matches collection.
RetStr = RetStr & "Match found at position "
RetStr = RetStr & Match.FirstIndex & ". Match Value is '"
RetStr = RetStr & Match.Value & "'." & vbCRLF
Next
RegExpTest = RetStr
End Function
VBEVAL>MsgBox(RegExpTest("is.", "IS1 is2 IS3 is4"))
===========================================
When the End Function statement is executed I get the following error message:
"Access violation at address 004CA2B8 in odule 'MSCHED.EXE'. Read of address FFFFFFFF.
===========================================
I am using Windows 98SE, MacroSched 7.1.13
Does anyone see what is wrong here? All suggestions to correct this are welcome.
After a few modifications to eliminate some compile errors, I got the compiler portion to run every line without error. But when the End Function is finally reached, I get an error that forces me to restart MacroSched from Close Program window. SHIFT-ESC will not stop macro.
The VB code below is from the MSDN manual section on RegExp.
=========================================
VBSTART
VBEND
Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches ' Create variable.
regEx = New RegExp ' Create a regular expression. (Was with Set.)
regEx.Pattern = patrn ' Set pattern.
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True ' Set global applicability.
Matches = regEx.Execute(strng) ' Execute search. (Was with Set.)
For Each Match in Matches ' Iterate Matches collection.
RetStr = RetStr & "Match found at position "
RetStr = RetStr & Match.FirstIndex & ". Match Value is '"
RetStr = RetStr & Match.Value & "'." & vbCRLF
Next
RegExpTest = RetStr
End Function
VBEVAL>MsgBox(RegExpTest("is.", "IS1 is2 IS3 is4"))
===========================================
When the End Function statement is executed I get the following error message:
"Access violation at address 004CA2B8 in odule 'MSCHED.EXE'. Read of address FFFFFFFF.
===========================================
I am using Windows 98SE, MacroSched 7.1.13
Does anyone see what is wrong here? All suggestions to correct this are welcome.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
Hi,
Your VBScript code isn't within the VBSTART and VBEND blocks so you will get syntax errors because Macro Scheduler will try to interpret it as MacroScript code.
Your VBScript code isn't within the VBSTART and VBEND blocks so you will get syntax errors because Macro Scheduler will try to interpret it as MacroScript code.
MJT Net Support
[email protected]
[email protected]
Hi,
The code also needed modification where the objects are created. I have modified and the following code works:
VBSTART
Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches ' Create variable.
Set regEx = New RegExp ' Create a regular expression. (Was with Set.)
regEx.Pattern = patrn ' Set pattern.
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True ' Set global applicability.
Set Matches = regEx.Execute(strng) ' Execute search. (Was with Set.)
For Each Match in Matches ' Iterate Matches collection.
RetStr = RetStr & "Match found at position "
RetStr = RetStr & Match.FirstIndex & ". Match Value is '"
RetStr = RetStr & Match.Value & "'." & vbCRLF
Next
RegExpTest = RetStr
End Function
VBEND
VBEval>RegExpTest("is.", "IS1 is2 IS3 is4"),result
MessageModal>result
The code also needed modification where the objects are created. I have modified and the following code works:
VBSTART
Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches ' Create variable.
Set regEx = New RegExp ' Create a regular expression. (Was with Set.)
regEx.Pattern = patrn ' Set pattern.
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True ' Set global applicability.
Set Matches = regEx.Execute(strng) ' Execute search. (Was with Set.)
For Each Match in Matches ' Iterate Matches collection.
RetStr = RetStr & "Match found at position "
RetStr = RetStr & Match.FirstIndex & ". Match Value is '"
RetStr = RetStr & Match.Value & "'." & vbCRLF
Next
RegExpTest = RetStr
End Function
VBEND
VBEval>RegExpTest("is.", "IS1 is2 IS3 is4"),result
MessageModal>result
MJT Net Support
[email protected]
[email protected]
Bob & Support,
I did evaluate the feasibility of applying RegExp objects in Macro Scheduler scripting. With Multi-Edit, you can search & replace the punctuation marks within several seconds regardless of the file size. On the other hand, with Macro Scheduler, it has to pass line by line to your VBScript function. It isn't practical for a very large text file. What if you change your search and replace patterns?
I did evaluate the feasibility of applying RegExp objects in Macro Scheduler scripting. With Multi-Edit, you can search & replace the punctuation marks within several seconds regardless of the file size. On the other hand, with Macro Scheduler, it has to pass line by line to your VBScript function. It isn't practical for a very large text file. What if you change your search and replace patterns?
Hi,
Actually you don't have to pass each line one by one, you could easily read the entire file into one string, modify it and write it back again. The following function reads an entire file into a single string:
Function ReadEntireFile(filename)
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(filename, 1,0)
ReadEntireFile = f.ReadAll
f.Close
End Function
Write it back to a new file (or delete the old and reopen for append) with the Write method.
So you could use FileSystemObject to read in the entire file, RegExp to search and replace and then write back with the FileSystemObject again. Set the pattern as a global variable at the top of the script.
Actually you don't have to pass each line one by one, you could easily read the entire file into one string, modify it and write it back again. The following function reads an entire file into a single string:
Function ReadEntireFile(filename)
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(filename, 1,0)
ReadEntireFile = f.ReadAll
f.Close
End Function
Write it back to a new file (or delete the old and reopen for append) with the Write method.
So you could use FileSystemObject to read in the entire file, RegExp to search and replace and then write back with the FileSystemObject again. Set the pattern as a global variable at the top of the script.
MJT Net Support
[email protected]
[email protected]
Support & Ernest,
I'm eager to try out your suggested VBScript code.
Support, does your VBScript code include the char/string replacement feature?
Ernest, WinXP comes with VBScript 5.6. For Win98/me/nt/2k, please download it from http://www.msdn.microsoft.com/downloads ... itedoc.xml. RegEXp is only available in VBScript 5.6. Please correct me if I'm wrong.
Thanks a lot.
I'm eager to try out your suggested VBScript code.
Support, does your VBScript code include the char/string replacement feature?
Ernest, WinXP comes with VBScript 5.6. For Win98/me/nt/2k, please download it from http://www.msdn.microsoft.com/downloads ... itedoc.xml. RegEXp is only available in VBScript 5.6. Please correct me if I'm wrong.
Thanks a lot.
Macro Scheduler ships with VBscript 5.6
Use the Replace function to do string replacements.
Use the Replace function to do string replacements.
MJT Net Support
[email protected]
[email protected]
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
WOW! Am I glad that I missed the VBEND error. Imagine, if I never made a mistake, we would have missed all of this. I am still embarassed to miss such an obvious error, but happy to oblige.
What a wealth of information this has generated. Thanks to everyone for their help.
1. Moving VBEND to the right location eliminated by first error.
2. I had removed the Set instruction because of errors I was getting, but moving VBEND solved those, and I did re enter Set as shown by Support.
3. Using Message>result allowed RegExp results to be displayed (VB MsgBox is generating a different error, I will look into that my self).
My initial problem is solved. Thanks again to Support, Ernest, Armstrong. The power of the forum strikes again.....
Nice to see the idea of reading an entire file in as a string for parsing, gonna use that one....thanks loads!
I had no specific need for RegExp at this time, just training myself on a function I was unfamiliar with. But it was originally generated from the Replace function that would not easily work with a " in the string to contain replacements.
I took a look at MultiEdit web page, looks like more than I could absorb right now. I did download the 30 day trial, but I will continue to use TextPad as alternate Editor.
Thank you all again...
What a wealth of information this has generated. Thanks to everyone for their help.
1. Moving VBEND to the right location eliminated by first error.
2. I had removed the Set instruction because of errors I was getting, but moving VBEND solved those, and I did re enter Set as shown by Support.
3. Using Message>result allowed RegExp results to be displayed (VB MsgBox is generating a different error, I will look into that my self).
My initial problem is solved. Thanks again to Support, Ernest, Armstrong. The power of the forum strikes again.....
Nice to see the idea of reading an entire file in as a string for parsing, gonna use that one....thanks loads!
I had no specific need for RegExp at this time, just training myself on a function I was unfamiliar with. But it was originally generated from the Replace function that would not easily work with a " in the string to contain replacements.
I took a look at MultiEdit web page, looks like more than I could absorb right now. I did download the 30 day trial, but I will continue to use TextPad as alternate Editor.
Thank you all again...
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
Although this may be ancient history for most of you now, I also found it very useful as a new user of Macro Scheduler. I have found an issue with it though that I don't know how to resolve and haven't been able to find any comments about it in the forum.
My question is how do you pass a string variable using VBEval when it has a quote in the string to be passed?
I am using essentially the same function as RegExpTest. I am grabbing a web page and passing it to the function line by line. When I encounter a line that has a quote in it, I get an error message from VBScript and the variables never get to the function. The error states "Microsoft VBScript compilation error :1006 Expected ')' Line 42, Column 78"
The Help file suggests that "To pass Macro Scheduler variables, embed them with the % symbol. If passing a Macro Scheduler variable as a string, remember that VBScript expects strings with quote marks around them." Unfortunately, it doesn't say what to do if the Macro scheduler variable has a quote in it.
To make an example from this, you could try to use..
body bgcolor="#ffffff" text="#000000" link="#000080" (as a variable value)
instead of IS1 is2 IS3 is4 in the following VBEval...
VBEval>RegExpTest("is.", "IS1 is2 IS3 is4"),result
I have been able to entirely bypass lines that contain quotes by using...
Position>",%line%,1,quotepos
If>quotepos>0,notfound
where line is my string with body tag and notfound is a label that bypasses the VBEval. While this works, it probably won't hold up as a good practice long term since HTML can have quotes through out the page.
Can anyone can point me in the right direction? Is there something I can use to get the quote marks passed to the VBScript?
Thanks,
Darren
My question is how do you pass a string variable using VBEval when it has a quote in the string to be passed?
I am using essentially the same function as RegExpTest. I am grabbing a web page and passing it to the function line by line. When I encounter a line that has a quote in it, I get an error message from VBScript and the variables never get to the function. The error states "Microsoft VBScript compilation error :1006 Expected ')' Line 42, Column 78"
The Help file suggests that "To pass Macro Scheduler variables, embed them with the % symbol. If passing a Macro Scheduler variable as a string, remember that VBScript expects strings with quote marks around them." Unfortunately, it doesn't say what to do if the Macro scheduler variable has a quote in it.
To make an example from this, you could try to use..
body bgcolor="#ffffff" text="#000000" link="#000080" (as a variable value)
instead of IS1 is2 IS3 is4 in the following VBEval...
VBEval>RegExpTest("is.", "IS1 is2 IS3 is4"),result
I have been able to entirely bypass lines that contain quotes by using...
Position>",%line%,1,quotepos
If>quotepos>0,notfound
where line is my string with body tag and notfound is a label that bypasses the VBEval. While this works, it probably won't hold up as a good practice long term since HTML can have quotes through out the page.
Can anyone can point me in the right direction? Is there something I can use to get the quote marks passed to the VBScript?
Thanks,
Darren
You've answered the question yourself - put quotes round it.dfritz wrote:how do you pass a string variable using VBEval when it has a quote in the string to be passed
VBEval>MyFunc("%somevariable%"),resultvar
MJT Net Support
[email protected]
[email protected]
Thanks but that hasn't helped unless I am still missing something. This is the line that has been generating the error...
VBEval>RegExpFind("(\d+\.\d+\.\d+\.\d+)]+>]+>([0-9][0-9]+)", "%line%"),resultRegEx
I did rename the function so this should be correct. This looks for an IP address followed by two html tags and then a digit larger than 9.
While watching it step by step in the "Show Watch List" window, it works for everything except the lines with quotes in them. If I cancel the error, it goes on through and does find the results that I am trying to get. I tried it with standard quotes, single quotes and no quotes with no luck.
I also added a MsgBox(strng) in the first line of the VB code and it never showed up which makes it appear like the VBscript never got the data. It appeared to skip the VB entirely when the function doesn't get the closing ).
Am I missing something obvious here or handling this different than others do? Perhaps it is just my installation?
Thanks,
Darren
VBEval>RegExpFind("(\d+\.\d+\.\d+\.\d+)]+>]+>([0-9][0-9]+)", "%line%"),resultRegEx
I did rename the function so this should be correct. This looks for an IP address followed by two html tags and then a digit larger than 9.
While watching it step by step in the "Show Watch List" window, it works for everything except the lines with quotes in them. If I cancel the error, it goes on through and does find the results that I am trying to get. I tried it with standard quotes, single quotes and no quotes with no luck.
I also added a MsgBox(strng) in the first line of the VB code and it never showed up which makes it appear like the VBscript never got the data. It appeared to skip the VB entirely when the function doesn't get the closing ).
Am I missing something obvious here or handling this different than others do? Perhaps it is just my installation?
Thanks,
Darren
Please post your VBScript code so that we can see the full picture.
MJT Net Support
[email protected]
[email protected]
Here is the whole thing. I thought the RegEx.replace effort might benefit others so I included my whole rough draft. It chokes on the HTML page's body tag that I mentioned in earlier post but works otherwise. It is the only line with quotes in the whole HTML file. I can send a sample HTML if it will help.
Thanks,
Darren
HTTPRequest>http://internal.FAKEnetworkmonitoringsy ... MLResponse
DeleteFile>%TEMP_DIR%\temp-blasterquery.txt
DeleteFile>%TEMP_DIR%\temp-blasterquery-parsed.txt
WriteLn>%TEMP_DIR%\temp-blasterquery.txt,result,HTMLResponse
Let>k=1
Let>j=0
Let>logspacer=
Let>msg=
Let>msglog=
Let>SENDMAIL_STATUS=0
Let>me=[email protected]
Let>myname=INMON SERVER
Let>recipients=[email protected],[email protected]
Label>STARTREGEXLOOP
ReadLn>%TEMP_DIR%\temp-blasterquery.txt,k,line
VBSTART
Function RegExpFind(patrn, strng)
Dim regEx, Match, Matches ' Create variable.
Set regEx = New RegExp ' Create a regular expression. (Was with Set.)
regEx.Pattern = patrn ' Set pattern.
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True ' Set global applicability.
Set Matches = regEx.Execute(strng) ' Execute search. (Was with Set.)
For Each Match in Matches ' Iterate Matches collection.
RetStr = RetStr & Match.Value
Next
RegExpFind = RetStr
End Function
VBEND
If>line=,skipposition
Position>",%line%,1,quotepos
Label>skipposition
If>quotepos>0,notfound
VBEval>RegExpFind("(\d+\.\d+\.\d+\.\d+)]+>]+>([0-9][0-9]+)", "%line%"),resultRegEx
If>resultRegEx=,notfound
Label>BeginFixResults
VBSTART
Function RegExpReplace(str1, patrn2, replStr)
Dim regEx2 ' Create variables.
Set regEx2 = New RegExp ' Create regular expression.
regEx2.Pattern = patrn2 ' Set pattern.
regEx2.IgnoreCase = True ' Make case insensitive.
RegExpReplace = regEx2.Replace(str1, replStr) ' Make replacement.
End Function
VBEND
VBEVAL>RegExpReplace("%resultRegEx%", "]+>", " "),resultRegEx
VBEval>RegExpFind("]+>", "%resultRegEx%"),resultRegEx2
If>resultRegEx2=,EndFixResults
Goto>BeginFixResults
Label>EndFixResults
Let>j=j+1
ConCat>msg,resultRegEx
ConCat>msg,%CRLF%
If>jmsglog,logspacer
Label>skiplogspace
Concat>msglog,resultRegEx
ConCat>msglog,%CRLF%
Label>notfound
If>line=##EOF##,ENDREGEXLOOP
Let>k=k+1
Goto>STARTREGEXLOOP
Label>ENDREGEXLOOP
If>msg=,LogAttempt
DateStamp>%SYS_DIR%\_INMON_BlasterAnalysis.log,********PROBLEM DETECTED********
DateStamp>%SYS_DIR%\_INMON_BlasterAnalysis.log,msglog
Let>subject=INMON ANALYSIS: Possible Blaster
SMTPSendMail>recipients,smtp2.internalserver.com,me,myname,subject,msg,
DateStamp>%SYS_DIR%\_INMON_BlasterAnalysis.log,Mail Result: %SMTP_RESULT%
SMTPSendMail>[email protected],smtp2.internalserver.com,me,myname,POSSIBLE BLASTER,Check Mail for details,
DateStamp>%SYS_DIR%\_INMON_BlasterAnalysis.log,Pager Result: %SMTP_RESULT%
Goto>END
Label>LogAttempt
DateStamp>%SYS_DIR%\_INMON_BlasterAnalysis.log,No problem detected
Label>END
FileSize>%SYS_DIR%\_INMON_BlasterAnalysis.log,LogFileSize
If>LogFileSizelogsizemsg=Please archive this file: %COMPUTER_NAME% - %SYS_DIR%\_INMON_BlasterAnalysis.log
SMTPSendMail>recipients,smtp2.internalserver.com,me,myname,_INMON_Blaster.log - Too Large,logsizemsg,
DateStamp>%SYS_DIR%\_INMON_BlasterAnalysis.log,********LOG FILE TOO LARGE********
DateStamp>%SYS_DIR%\_INMON_BlasterAnalysis.log,Log Size Mail Result: %SMTP_RESULT%
Label>EndLogSizeCheck
Thanks,
Darren
HTTPRequest>http://internal.FAKEnetworkmonitoringsy ... MLResponse
DeleteFile>%TEMP_DIR%\temp-blasterquery.txt
DeleteFile>%TEMP_DIR%\temp-blasterquery-parsed.txt
WriteLn>%TEMP_DIR%\temp-blasterquery.txt,result,HTMLResponse
Let>k=1
Let>j=0
Let>logspacer=
Let>msg=
Let>msglog=
Let>SENDMAIL_STATUS=0
Let>me=[email protected]
Let>myname=INMON SERVER
Let>recipients=[email protected],[email protected]
Label>STARTREGEXLOOP
ReadLn>%TEMP_DIR%\temp-blasterquery.txt,k,line
VBSTART
Function RegExpFind(patrn, strng)
Dim regEx, Match, Matches ' Create variable.
Set regEx = New RegExp ' Create a regular expression. (Was with Set.)
regEx.Pattern = patrn ' Set pattern.
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True ' Set global applicability.
Set Matches = regEx.Execute(strng) ' Execute search. (Was with Set.)
For Each Match in Matches ' Iterate Matches collection.
RetStr = RetStr & Match.Value
Next
RegExpFind = RetStr
End Function
VBEND
If>line=,skipposition
Position>",%line%,1,quotepos
Label>skipposition
If>quotepos>0,notfound
VBEval>RegExpFind("(\d+\.\d+\.\d+\.\d+)]+>]+>([0-9][0-9]+)", "%line%"),resultRegEx
If>resultRegEx=,notfound
Label>BeginFixResults
VBSTART
Function RegExpReplace(str1, patrn2, replStr)
Dim regEx2 ' Create variables.
Set regEx2 = New RegExp ' Create regular expression.
regEx2.Pattern = patrn2 ' Set pattern.
regEx2.IgnoreCase = True ' Make case insensitive.
RegExpReplace = regEx2.Replace(str1, replStr) ' Make replacement.
End Function
VBEND
VBEVAL>RegExpReplace("%resultRegEx%", "]+>", " "),resultRegEx
VBEval>RegExpFind("]+>", "%resultRegEx%"),resultRegEx2
If>resultRegEx2=,EndFixResults
Goto>BeginFixResults
Label>EndFixResults
Let>j=j+1
ConCat>msg,resultRegEx
ConCat>msg,%CRLF%
If>jmsglog,logspacer
Label>skiplogspace
Concat>msglog,resultRegEx
ConCat>msglog,%CRLF%
Label>notfound
If>line=##EOF##,ENDREGEXLOOP
Let>k=k+1
Goto>STARTREGEXLOOP
Label>ENDREGEXLOOP
If>msg=,LogAttempt
DateStamp>%SYS_DIR%\_INMON_BlasterAnalysis.log,********PROBLEM DETECTED********
DateStamp>%SYS_DIR%\_INMON_BlasterAnalysis.log,msglog
Let>subject=INMON ANALYSIS: Possible Blaster
SMTPSendMail>recipients,smtp2.internalserver.com,me,myname,subject,msg,
DateStamp>%SYS_DIR%\_INMON_BlasterAnalysis.log,Mail Result: %SMTP_RESULT%
SMTPSendMail>[email protected],smtp2.internalserver.com,me,myname,POSSIBLE BLASTER,Check Mail for details,
DateStamp>%SYS_DIR%\_INMON_BlasterAnalysis.log,Pager Result: %SMTP_RESULT%
Goto>END
Label>LogAttempt
DateStamp>%SYS_DIR%\_INMON_BlasterAnalysis.log,No problem detected
Label>END
FileSize>%SYS_DIR%\_INMON_BlasterAnalysis.log,LogFileSize
If>LogFileSizelogsizemsg=Please archive this file: %COMPUTER_NAME% - %SYS_DIR%\_INMON_BlasterAnalysis.log
SMTPSendMail>recipients,smtp2.internalserver.com,me,myname,_INMON_Blaster.log - Too Large,logsizemsg,
DateStamp>%SYS_DIR%\_INMON_BlasterAnalysis.log,********LOG FILE TOO LARGE********
DateStamp>%SYS_DIR%\_INMON_BlasterAnalysis.log,Log Size Mail Result: %SMTP_RESULT%
Label>EndLogSizeCheck