Split Variable? - Updated

Post Reply
Tabor
Super User
Super User
Posts: 175
Joined: Thu Dec 20, 2012 3:43 pm

Split Variable? - Updated

Post by Tabor » Tue Sep 30, 2014 6:31 pm

I am writing a script to automatically offset a fixture reference frame that was created on a different CMM. Both are 7.7.7 C3s but the Machine Ref Frame is different on each.

I've created a text file that has 5 lines. This goes into a local folder on the CMM computer. The first line is the file path to a network drive, the second is the CMM machine number (1 or 2), the 3rd, 4th, and 5th numbers are the X, Y, and Z offsets.

I also have a CSV file on the network (hence the file path in the text file) that has the part number and machine the reference frame was created on each line for all the parts we have programs for.

I would like to run the script right after recalling the Fixture Reference Frame, create a point with the variables, and set origin to that point. I'm stumbling through this but feel I'm close. It doesn't seem to like the Split variable code. Is this something the native VB version doesn't recognize or am I doing it wrong?

Sorry for the rambling explanation but it's been a long day and I'm exhausted.

Code: Select all

'FIXTURE REFERENCE FRAME OFFSETS

Dim CMMInfo(10)
Dim FilePath As String
Dim PN As String
Dim FileName As String
Dim filerow As Interger
Dim PartLine(10) As String
Dim CMM As Interger
Dim XOffset As Double
Dim YOffset As Double
Dim ZOffset As Double
Dim XREF As Double
Dim YREF As Double
Dim ZREF As Double

'Enter Part Number below where there are Xs
PN = xxxxxx

'Get local CMM info
Open "c:\CMMData\CMM.txt" For Input As #1
filerow = 0
		Do Until EOF(1)
			filerow = filerow + 1
			Line Input #1, fileline
			CMMInfo(i) = fileline
		Loop
Close #1
FilePath = CMMInfo(1)
CMM = CMMInfo(2)
XOffset = CMMInfo(3)
YOffset = CMMInfo(4)
ZOffset = CMMInfo(5)

'Determine which CMM FRF was created
FileName = FilePath & "FRF.crv"
Open Filename For Input As #2
filerow = 0
		Do Until partline(0) = PN
			filerow = filerow + 1
			Line Input #2, fileline
			PartLine = Split (fileline, ",")
		Loop
Close #2

'Determine if offset is needed

If PartLine(1) = CMM Then
	XREF = 0
	YREF = 0
	ZREF = 0
Else
	XREF = XOffset
	YREF = YOffset
	ZREF = ZOffset
End If
Tabor

User avatar
Ryan Christopher
Nikon
Nikon
Posts: 248
Joined: Mon Jun 06, 2011 3:00 pm
Location: Sumner Washington
Contact:

Re: Split Variable?

Post by Ryan Christopher » Thu Oct 30, 2014 2:48 pm

Don't forget to check your "INTERGER" 's
Ryan Tackes
Applications Manager, VMS Inc.
http://www.vantagemeasure.com/

User avatar
US_Helpdesk
Moderator
Moderator
Posts: 1087
Joined: Wed Feb 23, 2011 7:26 pm

Re: Split Variable?

Post by US_Helpdesk » Fri Dec 12, 2014 3:34 pm

I figured this one out... Finally.

Code: Select all

Dim namexyz As String
Dim nomxyz(1 to 3) As Double
Open "c:\CMM-Manager\Design\Points.csv" For Input As #1	' Open file.
    Do While Not EOF(1)		' Loop until end of file.
	Input #1, namexyz, nomxyz(1), nomxyz(2), nomxyz(3)	' Read line into variable.
  x=nomxyz(1)
  y=nomxyz(2)
  z=nomxyz(3)

Loop
    Close #1	' Close file.
This will read a .CSV file with contents as such:
nm,0,0,0
next,1,2,3
more,3,2,1
another,1,2,4
last,4,8,16



Update - Split() VBS command will now be supported starting in CMM-Manager 3.8. However the Open "c:\myfile.txt" For Input As #1 VBA File Open Method is deprecated in 3.8. See updated example below, I will post example CMM-M file once 3.8 releases:

Code: Select all

Dim objFSO, objWShell, objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWShell = CreateObject("WScript.Shell")
Set objFile = objFSO.OpenTextFile("c:\files\myfile.txt", 1)
i = 1
          Do While objFile.AtEndOfStream = False
               TextLine = objFile.ReadLine
               nomxyz = split(TextLine, ",") 
               x=nomxyz(1)
               y=nomxyz(2)
               z=nomxyz(3)         	
                i = i + 1
          Loop
 objFile.Close
You do not have the required permissions to view the files attached to this post.
I've migrated to a new user account, see my other posts here

Post Reply