Showing posts with label dictionary. Show all posts
Showing posts with label dictionary. Show all posts

Tuesday, June 26, 2012

Small Basic Spell Checker - 25 lines challenge


'Spell checker example - wxv722-2
'Uses Dictionary.GetDefinition(word) - Need internet access
'Harry Hardjono
'June 2012 - 25 line small basic challenge version
'
Str="abcdefghijklmnopqrstuvwxyz'ABCDEFGHIJKLMNOPQRSTUVWXYZ"
While (inputtext<>" ")
TextWindow.WriteLine("  ")
TextWindow.WriteLine("Enter your sentence: ")
inputtext=text.Append(TextWindow.Read()," ")
For i=1 To Text.GetLength(inputtext)
  If (Text.GetIndexOf(Str,Text.GetSubText(inputtext,i,1))=0) Then    'Not word
    If (Word<>"") Then
      If (Dictionary.GetDefinition(Word)="") Then  
      TextWindow.BackgroundColor="white"
      TextWindow.ForegroundColor="black"
      TextWindow.Write(Word)
      TextWindow.BackgroundColor="black"
      TextWindow.ForegroundColor="white"
      Else
      TextWindow.Write(Word)
      EndIf
      Word=""
    EndIf
    TextWindow.Write(Text.GetSubText(inputtext,i,1))
  Else 'Word
    Word=Text.Append(Word,Text.GetSubText(inputtext,i,1))
  EndIf
endfor
EndWhile

Tuesday, June 12, 2012

Small Basic Spell Checker


'Spell checker example - wxv722-1
'Uses Dictionary.GetDefinition(word) - Need internet access
'Harry Hardjono
'June 2012
'
Init:
Str="abcdefghijklmnopqrstuvwxyz'ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Word=""


Loop:
TextWindow.BackgroundColor="black"
TextWindow.ForegroundColor="white"
TextWindow.WriteLine("  ")
TextWindow.WriteLine("Enter your sentence: ")
inputtext=text.Append(TextWindow.Read()," ") 'bug fix. ^_^;

If (inputtext=" ") Then
  Goto End
EndIf


For i=1 To Text.GetLength(inputtext)
  curchar=Text.GetSubText(inputtext,i,1)
  If (Text.GetIndexOf(Str,curchar)=0) Then
    'Not word
    If (Word<>"") Then
      WordDef=Dictionary.GetDefinition(Word)
      If (WordDef="") Then
      TextWindow.BackgroundColor="white"
      TextWindow.ForegroundColor="black"
      TextWindow.Write(Word)
      TextWindow.BackgroundColor="black"
      TextWindow.ForegroundColor="white"
      Else
      TextWindow.Write(Word)
      EndIf
      Word=""
    EndIf
    TextWindow.Write(curchar)
  Else 'Word
    Word=Text.Append(Word,curchar)
  EndIf
endfor

Goto Loop

End:
Program.End()