Microsoft Small Basic
Program Listing: XLP892-0
List Program
'================================================'
' InputBox GUI (v1.01)
' by GoToLoop (2013/Nov)
' XLP892-0
' http://social.msdn.microsoft.com/Forums/en-US
'/c36749cd-673f-47a6-b5fe-1db6718038d3
' /problem-with-for-loop-and-graphicswindow
'================================================'
' -------------------------------------------------------------------------------------------------------------'
LF = Text.GetCharacter(10)
TAB = Text.GetCharacter(9)
NUM = 5
QUESTIONS = 3
OFFSET = 40
GAP = 60
GW = 600
GH = 400
' -------------------------------------------------------------------------------------------------------------'
GraphicsWindow.CanResize = "False"
GraphicsWindow.Width = GW
GraphicsWindow.Height = GH
GraphicsWindow.BackgroundColor = "DarkBlue"
GraphicsWindow.Clear()
CreateInputBoxes()
HideAllBoxes()
CreateConfirmButton()
HideConfirmButton()
Controls.ButtonClicked = ConfirmBox
GraphicsWindow.KeyDown = ExitCheck
EnterForms()
DisplayForms()
ClearScreen()
HideAllBoxes()
HideConfirmButton()
GraphicsWindow.Hide()
' -------------------------------------------------------------------------------------------------------------'
Sub CreateConfirmButton
GraphicsWindow.BrushColor = "Green"
confirmBtn = Controls.AddButton("Confirm" (GW - 80)/2, GH - 100)
EndSub
' -------------------------------------------------------------------------------------------------------------'
Sub HideConfirmButton
Controls.HideControl(confirmBtn)
EndSub
' -------------------------------------------------------------------------------------------------------------'
Sub ShowConfirmButton
Controls.ShowControl(confirmBtn)
EndSub
' -------------------------------------------------------------------------------------------------------------'
Sub CreateInputBoxes
GraphicsWindow.BrushColor = "DarkSlateGray"
For i = 1 To QUESTIONS
boxes[i] = Controls.AddTextBox(OFFSET, i*GAP)
Controls.SetSize(boxes[i] GW - 80, 25)
EndFor
EndSub
' -------------------------------------------------------------------------------------------------------------'
Sub ClearAllBoxes
For i = 1 To QUESTIONS
Controls.SetTextBoxText(boxes[i], "")
EndFor
EndSub
' -------------------------------------------------------------------------------------------------------------'
Sub HideAllBoxes
For i = 1 To QUESTIONS
Controls.HideControl(boxes[i])
EndFor
EndSub
' -------------------------------------------------------------------------------------------------------------'
Sub ShowAllBoxes
For i = 1 To QUESTIONS
Controls.ShowControl(boxes[i])
EndFor
EndSub
' -------------------------------------------------------------------------------------------------------------'
Sub ClearScreen
' Clears GraphicsWindow w/o erasing Shapes nor Controls objects.
Stack.PushValue("BackgroundColor", GraphicsWindow.BrushColor)
GraphicsWindow.BrushColor = GraphicsWindow.BackgroundColor
GraphicsWindow.FillRectangle(0,0 GW,GH)
GraphicsWindow.BrushColor = Stack.PopValue("BackgroundColor")
EndSub
' -------------------------------------------------------------------------------------------------------------'
Sub EnterForms
GraphicsWindow.BrushColor = "Red"
ShowAllBoxes()
ShowConfirmButton()
txt = "Enter your friend"
For idx = 1 To NUM
ClearAllBoxes()
ClearScreen()
GraphicsWindow.DrawText(OFFSET, GAP*0 + OFFSET txt + " #" + idx + "'s name: ")
GraphicsWindow.DrawText(OFFSET, GAP*1 + OFFSET txt + "'s phone number: ")
GraphicsWindow.DrawText(OFFSET, GAP*2 + OFFSET txt + "'s email address: ")
AwaitForConfirmation()
SaveForms()
EndFor
EndSub
' -------------------------------------------------------------------------------------------------------------'
Sub SaveForms
forms[idx]["Name"] = Controls.GetTextBoxText(boxes[1])
forms[idx]["Phone"] = Controls.GetTextBoxText(boxes[2])
forms[idx]["Email"] = Controls.GetTextBoxText(boxes[3])
forms[idx]["Time"] = Clock.Time
EndSub
' -------------------------------------------------------------------------------------------------------------'
Sub DisplayForms
fields = Array.GetAllIndices(forms[1])
For idx = 1 To NUM
arr = forms[idx]
TextWindow.WriteLine("Form #" + idx + ": " + LF)
For ask = 1 To QUESTIONS + 1
elem = fields[ask]
TextWindow.WriteLine(elem + "->"+ TAB + arr[elem])
EndFor
TextWindow.WriteLine(LF)
EndFor
EndSub
' -------------------------------------------------------------------------------------------------------------'
Sub AwaitForConfirmation
hasConfirmed = "False"
While hasConfirmed <> "True"
Program.Delay(100)
EndWhile
EndSub
' -------------------------------------------------------------------------------------------------------------'
Sub ConfirmBox
btn = Controls.GetButtonCaption(Controls.LastClickedButton)
If btn = "Confirm" Then
hasConfirmed = "True"
EndIf
EndSub
' -------------------------------------------------------------------------------------------------------------'
Sub ExitCheck
key = GraphicsWindow.LastKey
If key = "Escape" Then
Sound.PlayChimeAndWait()
Program.End()
EndIf
EndSub
' -------------------------------------------------------------------------------------------------------------'