Sub Main()
' -------------------------------------------------------------------
' Rimmel
' Macro for importing tool table from semi-colon delimited text file
' -------------------------------------------------------------------

    Dim textFilePath As String
    Const ForReading = 1
    Dim strLine As String 
    Dim toolArr(9) As String

    textFilePath = "C:\mach3\ToolTable.txt"
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile(textFilePath, ForReading)
    
    entries = 0

    Do While objFile.AtEndOfStream = False
        entries = entries + 1
        
        strLine = objFile.ReadLine
        
        ' ---------------------------------------------------------
        ' toolArr = Split(strLine, ";") would have done nicely
        ' here but Split() does not seem to be supported in the 
        ' Mach3 scripting language (VBScript) - strange
        ' So instead had to mackle together something from the
        ' available functions - a manual split if you like
        ' ---------------------------------------------------------
        
        For i = 0 To 8
    	    toolArr(i) = GetFirstElement(strLine)
    	    strLine = RemoveFirstElement(strLine)
        Next i
        For y = 0 To 8
            If y = 0 Then
            	SetToolDesc(CDbl(toolArr(0)), toolArr(y + 1)) 
            Else
            	SetToolParam(CDbl(toolArr(0)), y, CDbl(toolArr(y + 1))) 
            End If
        Next y
    Loop

    objFile.Close
    Message("Tool Table:- [" & entries & "] Entries Imported")
    
End Sub    


Function GetFirstElement(pStr As String) As String
    ' Part of the manual Split Functions
    x = InStr(pStr, ";")
    If x > 0 Then
        lStr = Left(pStr, x - 1)
        GetFirstElement = lStr
    End If    
End Function

Function RemoveFirstElement(pStr As String) As String
    ' Part of the manual Split Functions
    x = InStr(pStr, ";")
    If x > 0 Then
        lStr = Right(pStr, Len(pStr) - x)
        RemoveFirstElement = lStr
    End If
End Function