If you don't define a specific file path, the default location that PC-DMIS searches for the file to open is "C:\Users\Public\Documents\Hexagon\PC-DMIS\<version>".
This code sample provides various examples of several methods or functions. It contains these subroutines:
Main - This routine starts the code sample. It assumes you have a file named TESTFILE in your default directory with some content in it. This example reads each line of the file and displays it in a message box. The subroutine then calls the Test subroutine.
Test - This subroutine also reads a file. It assumes you have a file named MYFILE in your default directory with some content in it. The subroutine then calls the FileIO_Example subroutine.
FileIO_Example - This subroutine calls the Make3Files subroutine. After the Make3Files subroutine runs, the program flow returns here and deletes the sample files created.
Make3Files - This subroutine loops three times and creates files TEST1, TEST2, and TEST3 in your default directory with a couple of lines of code in each.
Sub Main() Open "TESTFILE" For Input As #1 ' Open file. Do While Not EOF(1) ' Loop until end of file. Line Input #1, TextLine ' Read line into variable. MsgBox TextLine ' Print to Debug window. Loop Close #1 ' Close file. Call Test ' Call The test subroutine. End Sub Sub Test() Open "MYFILE" For Input As #1 ' Open file for input. Do While Not EOF(1) ' Check for end of file. Line Input #1, InputData ' Read line of data. MsgBox InputData Loop Close #1 ' Close file. Call FileIO_Example End Sub Sub FileIO_Example() Dim Msg ' Declare variable. Call Make3Files ' Create data files. Msg = "Three test files, TEST1, TEST2, and TEST3, have been created on your disk. " Msg = Msg & "Click OK to remove these three test files." MsgBox Msg For I = 1 To 3 Kill "TEST" & I ' Remove data files from disk. Next I End Sub Sub Make3Files() Dim I, FNum, FName ' Declare variables. For I = 1 To 3 FNum = FreeFile ' Determine next file number. FName = "TEST" & FNum Open FName For Output As FNum ' Open file. Print #I, "This is test #" & I ' Write string to file. Print #I, "Here is another "; "line"; I Next I Close ' Close all files. End Sub