Declare Function Parse(ToParse as String)

Dim Shared Parsed(100) as String

Function Parse(ToParse as String)
	Dim CurrentPosition as Integer
	Dim CurrentCharacter as String
	Dim WordCount as Integer
	Dim WordSize as Integer
	For CurrentPosition = 1 to Len(ToParse)
		CurrentCharacter = MID$(ToParse,CurrentPosition,1)
		Select Case CurrentCharacter
			Case " "
				If Not WordSize = 0 Then
					Parsed(WordCount + 1) = MID$(ToParse, CurrentPosition - WordSize, WordSize)
				End If
				WordCount = WordCount + 1    
				WordSize = 0
			Case CHR$(34), "'", ","
				If Not WordSize = 0 Then
					Parsed(WordCount + 1) = MID$(ToParse, CurrentPosition - WordSize, WordSize)
				End If
				WordSize = 1
				Parsed(WordCount + 1) = MID$(ToParse, CurrentPosition - WordSize + 1, WordSize)
				WordCount = WordCount + 1    
				WordSize = 0
			Case Else
				WordSize = WordSize + 1
		End Select
		If CurrentPosition = Len(ToParse) Then
			WordSize = WordSize - 1
			Parsed(WordCount + 1) = MID$(ToParse, CurrentPosition - WordSize, WordSize + 1)
		End If
	Next CurrentPosition
	Parsed(0) = MKI$(WordCount)
End Function
