Mombu the Microsoft Forum sponsored links

Go Back   Mombu the Microsoft Forum > Microsoft > SCRIPTNG (TECHNET) > Regular Expressions
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 14th April 20:33
zepp daddy
External User
 
Posts: 1
Default Regular Expressions



I have a problem I am hoping someone can help with.

My employer does contract machining work which employs generating a great
deal of CNC code.

We have recently discovered a problem with our lathe posts and need a way
to detect errors before they hit the production floor.

Here is an example of "bad" code:

....
N29 G0 Z0. S600
N30 X.8 Z0.
N31 G1 Z.1

Basically the N31 line should directly follow the N29 line:

N29 G0 Z0. S600
N30 G1 Z.1

I was thinking that there might be a way to utilize RegEx in VBScript to
search for these errors...

The only problem, I have no experience with regular expressions.

Can anyone help?

Any help is GREATLY appreciated!!

Thanks a million!!
  Reply With Quote


  sponsored links


2 14th April 20:33
michael harris \(mvp\)
External User
 
Posts: 1
Default Regular Expressions



Don't assume a RegExp is the solution to the problem, especially since you
haven't clearly defined the problem. Giving one example without stating
what it is about the example, in general terms, that makes it a problem is
too vague.

Define the criteria to be applied to 1) detect a problem exists and 2) what
actions need to be taken to correct the problem. It's easier for people to
help devise a solution, once you define the rules.

--
Michael Harris
Microsoft MVP Scripting
http://maps.google.com/maps?q=Sammamish%20WA%20US
  Reply With Quote
3 14th April 20:33
mighty zepp
External User
 
Posts: 1
Default Regular Expressions


Michael,

Thanks for the input...I aplogize for not clearly defining my problem.

Let's try again...

We are having an apparently random problem with our CNC posts when posting
out lather programs.

I am looking for errors in the "Facing Cycle" (G72)

A type facing cycle should include something very similar to:

N27 G72 W.05 R.05
N28 G72 P29 Q31 U0. W.01 F.014
N29 G0 Z0. S600
N30 G1 X.8

This can appear anywhere within the program.

The N## numbers are merely line numbers and may or may not be present.
Either way, it doesn't matter.

The G72 is the code for a facing cycle.

We should have two (2) consecutive lines including G72 instruction.

The next line following should be a G0 instruction (Rapid positioning).

The next line following should then be a G1 instruction (Linear feed).

The program then continues on as necessary.

The problem arises when there are arbitrary lines of code placed between my
G0 and G1 instruction lines (N29 and N30 in my example).

When this occurs, we may end up with something similar to:

N27 G72 W.05 R.05
N28 G72 P29 Q31 U0. W.01 F.014
N29 G0 Z0. S600
N30 X.8 Z0.
N31 G1 X.8

In the preceding example, the N30 line is out of place and causes an error
on the production floor.

I need to be able to detect such an error and send an alert to the
programmer.

As far as using a RegEx, I am not married to the idea. I just thought it
might serve our purpose. I am always open to suggestions.

Anyway, I hope I have not been to long-winded, but that I have explained my
problem fully.

Again, thanks a million for any help.

- Jeff
  Reply With Quote
4 14th April 20:33
torgeir bakken \(mvp\)
External User
 
Posts: 1
Default Regular Expressions


Hi

A non-RegExp solution:

'--------------------8<----------------------

Const ForReading = 1
Const OpenAsASCII = 0
Const FailIfNotExist = 0

sInFile = "C:\CNC.txt"

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set fInFile = oFSO.OpenTextFile(sInFile, _
ForReading, FailIfNotExist, OpenAsASCII)

bCheckForG1AtNextLoop = False ' init value
sErrLines = "" ' init value

Do Until fInFile.AtEndOfStream
' count line numbers
i = i + 1

sLine = fInFile.ReadLine
aLine = Split(sLine)
If UBound(aLine) > 0 Then

sCurrentValue = UCase(aLine(1))
If bCheckForG1AtNextLoop And sCurrentValue <> "G1" Then
' Wrong value found!
sErrLines = sErrLines & vbCrLf & i
WScript.Echo i
End If
bCheckForG1AtNextLoop = False

If sPrevValue = "G72" And sCurrentValue = "G0" Then
bCheckForG1AtNextLoop = True
End If

End If
sPrevValue = sCurrentValue Loop
If sErrLines <> "" Then
WScript.Echo "Error found at following line(s): " & sErrLines
Else
WScript.Echo "No errors found"
End If

'--------------------8<----------------------

--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666