tags:

views:

908

answers:

3

Example

G76 I0.4779 J270 K7 C90

X20 Y30

If a number begins with I J K C X Y and it doesn't have a decimal then add decimal. Above example should look like:

G76 I0.4779 J270 K7. C90.

X20. Y30.

Purpose of this code is to convert CNC code for an older Fanuc OPC controller

+2  A: 
tloach
Oops, updated now that I've had a coffee :)
tloach
A: 
function convert(str)
    Set RegEx = New RegExp
    RegEx.Global = True
    RegEx.Pattern = "([IJKCXY]\d*\.?\d*)"
    Set Matches = regEx.Execute(str)

    For Each Match in Matches
     if instr(Match.value, ".") = 0 then
      str = Replace(str, Match.value, Match.value & ".")
     end if
    Next
    convert = str
end function
Wayne
A: 

tloach still answer doesn't work

Waynes works but also puts a . after every occurrence of IJKCXY

I changed if instr(Match.value, ".") = 0 then

To be like if instr(Match.value, ".") = 0 and len(Match.value) > 1 then

I've updated mine, should work now
tloach