Microsoft Small Basic

Program Listing: HDJ631-0
'Wordlist to Array Converter - (C)opyright 2017 by Matthew L. Parets aka Coding Cat - No rights reserved as long as no money made and this statement is maintained
'Any lists of words or phrases entered into the top text box will be converted into
' a Smallbasic array to be easily added to a program.
'Originally designed to convert a dictionary to a word guessing game, words with '
' and words small then five letters will be filtered out.
'Sample Conversation of 3000 pluse word dictionary: HKZ204

GraphicsWindow.Show()

GraphicsWindow.BackgroundColor = GraphicsWindow.GetColorFromRGB(255,255,200)
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.Title = "Word list to Array Converter"

Timer.Tick = WhenResizeTimeTicks
Timer.Interval = 250
ifStack = ""

SetControls()

Controls.ButtonClicked = OnButtonClick

Sub SetControls
If GraphicsWindow.Height >= 145 And GraphicsWindow.Width >= 210 then
prevWid = GraphicsWindow.Width
prevHei = GraphicsWindow.Height
GraphicsWindow.Clear()
GraphicsWindow.DrawText(5,10,"Word List to Convert:")
button = Controls.AddButton("Convert List", GraphicsWindow.Width - 96,5)
txtBox = Controls.AddMultiLineTextBox(5,35)
Controls.SetSize(txtBox, GraphicsWindow.Width - 10, GraphicsWindow.Height - 125)
GraphicsWindow.DrawText(5, GraphicsWindow.Height - 75, "Resulting Word Array:")
resBox = Controls.AddMultiLineTextBox(5, GraphicsWindow.Height - 55)
Controls.SetSize(resBox, GraphicsWindow.Width - 10, 50)
Else
GraphicsWindow.Width = 210
GraphicsWindow.Height = 145
EndIf
EndSub

Sub WhenResizeTimeTicks
If prevWid = GraphicsWindow.Width And prevHei = GraphicsWindow.Height Then
If Timer.Interval < 5000 Then
Timer.Interval = Timer.Interval + (250 / 4)
EndIf
Else
Timer.Interval = 250
SetControls()
EndIf
EndSub

Sub OnButtonClick
nl = Text.GetCharacter(13) + Text.GetCharacter(10)
wordCnt = 0
resStr = ""
token = "!" 'Becuase smallbasic won't concatenate digits

buffer = Controls.GetTextBoxText(txtBox)
buffer = Text.ConvertToLowerCase(buffer)
token = ""
For i = 1 To Text.GetLength(buffer)

thisChar = Text.GetSubText(buffer,i,1)
If (text.GetCharacterCode(thisChar) <> 10 and text.GetCharacterCode(thisChar) <> 13 ) then
token = "" + token + "" + thisChar
'TextWindow.Write(thisChar)
Else
ProcessToken()
endif

EndFor
ProcessToken()
'TextWindow.WriteLine(resStr)
resStr = "WordList = " + Text.GetCharacter(34) + resStr + Text.GetCharacter(34)
'TextWindow.WriteLine(resStr)
resStr = resStr + nl
resStr = resStr + "WordCount = " + wordCnt + nl
Controls.SetTextBoxText(resBox, resStr)
EndSub

Sub ProcessToken
token = Text.GetSubText(token,2,Text.GetLength(token))
'TextWindow.WriteLine("--" + token + "--")
If Text.GetLength(token) >= 5 then
apstro = Text.GetIndexOf(token,"'")
If apstro = 0 Then
wordCnt = wordCnt + 1
resStr = resStr + wordCnt + "=" + token + ";"
EndIf
EndIf
token = "!" 'Becuase smallbasic won't concatenate digits
EndSub