Hi all
Printable View
Hi all
Can you post a snippet of the file, and the value of 'ln'?
text file
Give me a few :)
Hey is there any way better that would look at the "F" And the number to the right of it and if that number was greater than 1.3 it would change it to 1.3?
Sorry for all the new ideas.
Thanks
Reston
VB Code:
Option Explicit Private Sub Command1_Click() Dim intFF As Integer Dim lngCount As Long, lngIdx As Long Dim strArr() As String On Error GoTo Err_Handler intFF = FreeFile 'Load the TextFile into an Array Open App.Path & "\test.txt" For Input As #intFF strArr() = Split(Input(LOF(intFF), 1), vbCrLf) Close #intFF 'Now, pass tru each Array element and look for a match lngCount = UBound(strArr) - 1 For lngIdx = 0 To lngCount If InStr(1, strArr(lngIdx), "F", vbTextCompare) <> 0 And Left$(strArr(lngIdx), 1) <> "(" _ Then MsgBox Trim$(Right$(strArr(lngIdx), Len(strArr(lngIdx)) - InStrRev(strArr(lngIdx), "F", -1, vbTextCompare))) Next Exit Sub Err_Handler: MsgBox "Number: " & Err.Number & vbCrLf & _ "Description: " & Err.Description, vbOKOnly + vbInformation, "Error!" End Sub
Tested with the above snippet.
Hey Bruce Fox did you see my last post?
Yes I did!
Did you try it, if it is on track THEN we can tweek it :)
Will the header be always the same or there's a pattern to it? Same number of lines, etc? Will there be other instances of F such as in trailer info?
Cause if we can truncate the leading and trailing chars, leaving us with N* then we can Split on F.
Hi Bruce
That worked fine for the msgbox. And can we add the line number that is in the beginning of the "F" line. That is the N20G1Z0.F1.3 so the opperator knows where the line is that the "F" is on?
Just so everyone know these are cnc gcode files that i'm working on.The length of the files are all over the place. can be up to 100000 lines.
Thanks again for the help
Reston
So the format for the Line Num is for example:N20G1Z0?
Also, what do you want to do with the numbers after "F". Display as they are below the value of 1.3, and if above 1.3 only display as 1.3?
Bruce
The N20 is the line number. I think it would be nice to just display the whole line that has an "F" in it. Example: N20G1Z0.F1.3 That way it would be easier to find later if we find a line that the feed rate is set to high.
I had done this earlier for you pending a response. Adjust as required.
VB Code:
Option Explicit Private Sub Command1_Click() Dim intFF As Integer Dim lngCount As Long, lngIdx As Long Dim strArr() As String On Error GoTo Err_Handler intFF = FreeFile 'Load the TextFile into an Array Open App.Path & "\test.txt" For Input As #intFF strArr() = Split(Input(LOF(intFF), 1), vbCrLf) Close #intFF 'Now, pass tru each Array element and look for a match lngCount = UBound(strArr) - 1 For lngIdx = 0 To lngCount If InStr(1, strArr(lngIdx), "F", vbTextCompare) <> 0 And Left$(strArr(lngIdx), 1) <> "(" Then If IsNumeric(Trim$(Right$(strArr(lngIdx), Len(strArr(lngIdx)) - InStrRev(strArr(lngIdx), "F", -1, vbTextCompare)))) Then 'Line Number data MsgBox Trim$(Left$(strArr(lngIdx), InStrRev(strArr(lngIdx), "F", -1, vbTextCompare) - 1)) 'Value MsgBox Trim$(Right$(strArr(lngIdx), Len(strArr(lngIdx)) - InStrRev(strArr(lngIdx), "F", -1, vbTextCompare))) End If End If Next Exit Sub Err_Handler: MsgBox "Number: " & Err.Number & vbCrLf & _ "Description: " & Err.Description, vbOKOnly + vbInformation, "Error!" End Sub
Yeilds, Line Number, Value, Line Number, Value:
N20G1Z0.
1.3
N46X-.1567Y2.2957
200.250
Do you still want only a COMPLETE line that has the F and followed by Numerics?
Just tested this, and it works. To add what line it's on as you've stated earlier, just add an extra variable that counts the number of loops gone by, by adding +1 at the end of each loop(i.e. each time a line is loaded):
VB Code:
Dim ln As String, keyword As String: keyword = "F" Dim ff As Integer, lnNum As String: ff = FreeFile 'Open App.Path & "\nifchwc.t" For Input As #ff Open "C:\Nif2\nif2chwc\nifchwc.t" For Input As #ff Do Until EOF(ff) Line Input #ff, ln If InStr(1, ln, keyword) Then lnNum = Mid(ln, InStr(ln, keyword) + 1) If Val(lnNum) > 1.3 Then ln = Replace$(ln, lnNum, "1.3") Debug.Print ln 'Printer.Print ln End If ace = 77 'Just a note, this is not declared in your code! Loop Close #ff
This will, however, replace both numbers after "F" to "1.3" like you said. To adjust it to make the second number NOT change to "1.3" and change to something else, just add an extra check to see if it is higher than whatever number you expect to be there, ya dig?
Sorry
I've had alot going on and have not had a chance to try some of these.
Give me a few
Hey Thanks everyone for helping. Lots to learn!
This is what I'm going with
VB Code:
Private Sub Command4_Click() 'Option Explicit Dim intFF As Integer Dim lngCount As Long, lngIdx As Long Dim strArr() As String On Error GoTo Err_Handler intFF = FreeFile 'Load the TextFile into an Array Open App.Path & "\" & Text1.Text For Input As #intFF strArr() = Split(Input(LOF(intFF), 1), vbCrLf) Close #intFF 'Now, pass tru each Array element and look for a match lngCount = UBound(strArr) - 1 For lngIdx = 0 To lngCount If InStr(1, strArr(lngIdx), "F", vbTextCompare) <> 0 And Left$(strArr(lngIdx), 1) <> "(" Then If IsNumeric(Trim$(Right$(strArr(lngIdx), Len(strArr(lngIdx)) - InStrRev(strArr(lngIdx), "F", -1, vbTextCompare)))) Then MsgBox Trim$(Right$(strArr(lngIdx), Len(strArr(lngIdx)) - InStrRev(strArr(lngIdx), "F", 1, vbTextCompare))) End If End If Next Exit Sub Err_Handler: MsgBox "Number: " & Err.Number & vbCrLf & _ "Description: " & Err.Description, vbOKOnly + vbInformation, "Error!" End Sub