CODE:
strPartNum = "test part"
CODE:
'Dimension variables and Arrays
Dim objFSO
Dim SerialArr(3)
Dim strSerialTxt, i
StopScript = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
strPubFolder = "C:\Users\Public\CMM-Manager"
strSerialFile = strPubFolder + "\part_num_" + strPartNum + ".txt"
'Check for folder and create if doesn't exist
If Not objFSO.FolderExists(strPubFolder) Then
objFSO.CreateFolder(strPubFolder)
End If
'Check if file exists
'If does not exist create it and populate 4 lines with serial numbers
If Not objFSO.FileExists(strSerialFile) Then
Do Until strFirstSerial >0
strFirstSerial = InputBox("This is the first " + strPartNum + " run on this machine. What is the starting serial number?")
If strFirstSerial = "" Then
endProg = MsgBox("Are sure you want to cancel?", 4)
If endProg = 6 Then
StopScript = 1
Exit Do
End If
End If
If Not strFirstSerial > 0 Then
MsgBox("Please enter a valid serial number")
End If
Loop
If StopScript = 0 Then
'Write text file
Set strSerialTxt = objFSO.CreateTextFile(strSerialFile)
strSerialTxt.WriteLine(strFirstSerial)
nxtSerial = strFirstSerial + 1
strSerialTxt.WriteLine(nxtSerial)
nxtSerial = nxtSerial + 1
strSerialTxt.WriteLine(nxtSerial)
nxtSerial = nxtSerial + 1
strSerialTxt.WriteLine(nxtSerial)
strSerialTxt.Close
End if
End If
CODE:
'Open file
If StopScript = 0 Then
Set objFile = objFSO.OpenTextFile(strSerialFile, 1)
i = 0
'readfile
Do While objFile.AtEndOfStream = False
SerialArr(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close
strSerial1 = SerialArr(0)
strSerial2 = SerialArr(1)
strSerial3 = SerialArr(2)
strSerial4 = SerialArr(3)
MsgBox(strSerial1)
MsgBox(strSerial2)
MsgBox(strSerial3)
MsgBox(strSerial4)
End If
CODE:
'Write out Serial numbers
If StopScript = 0 Then
'Open File
strSerialFile = strPubFolder + "\part_num_" + strPartNum + "_OUT.txt"
Set strSerialTxt = objFSO.CreateTextFile(strSerialFile)
'Write to file
strSerialTxt.WriteLine(strSerial1 + "_OUT")
strSerialTxt.WriteLine(strSerial2 + "_OUT")
strSerialTxt.WriteLine(strSerial3 + "_OUT")
strSerialTxt.WriteLine(strSerial4 + "_OUT")
'Close file
strSerialTxt.Close
End If