Sub TernaryToText
If Ternary < 1 And Text.ConvertToLowerCase(Ternary) <> Text.ConvertToUpperCase(Ternary) Then
GraphicsWindow.ShowMessage("The input is not an integer","Error")
ElseIf Text.IsSubText(Text.GetLength(Ternary)/5,".") Then
GraphicsWindow.ShowMessage("Cannot get text if ternary is not in groups of 5","Error")
Else
String = ""
For i = 1 To Text.GetLength(Ternary)/5
Value = Text.GetSubText(Ternary,i*5-4,5)
Total = ""
For g = Text.GetLength(Value) To 1 Step -1
Total = Total+Text.GetSubText(Value,g,1)*Math.Power(3,Text.GetLength(Value)-g)
EndFor
String = Text.Append(String,Text.GetCharacter(Total))
EndFor
Controls.SetTextBoxText(Box,String)
EndIf
EndSub
Sub TextToTernary
TernaryValue = ""
For i = 1 To Text.GetLength(Txt)
ASCIIValue = Text.GetCharacterCode(Text.GetSubText(Txt,i,1))
w = 0
For g = 1 To 5
w = w + 1
Remainder = Math.Remainder(ASCIIValue,3)
ASCIIValue = Math.Floor(ASCIIValue/3)
Trite[w] = Remainder
EndFor
For f = w To 1 Step -1
TernaryValue = Text.Append(TernaryValue,Trite[f])
EndFor
EndFor
Controls.SetTextBoxText(Box,TernaryValue)
EndSub