PowerBASIC Forms |
|
Learn how to create a Password dialog box using PowerBASIC Forms. In this QuickStart Tutorial you will learn how to create a new Dialog, add controls to the Dialog and how to respond to user input of these controls. |
|
Create a Username/Password dialog.
PBFORMS
| 1.
Create a New dialog. |
 |
An
empty dialog has been created,
ready to be filled in. |

The base for a Windows program - an
empty
design dialog. |
2. Bring up the Dialog Properties (double-click on the dialog or press
F4).
3. On tab page 1 - change the caption to: PowerEntry

4. Press OK to approve of the new caption and close the Dialog
Properties.
Our
blank dialog now has a caption. Now we'll
add controls to the dialog.
|

|
Labels
5. Select the Label control in the Toolbox dialog. 
6. Move the mouse to the upper left corner of the dialog, about 5
pixels in.
7. Click and drag the mouse to create a Label - release at size 40x10.
(PBForms statusbar shows the size in Bottom/Right corner).
8. Bring up the Label's Properties (double-click on the Label or press
F4).
9. Change the caption to: User name:
9. Press Ok.
10. Press the Down arrow key twice to move the Label down 2 steps, to
pos 5, 7.
11. With the Label control selected, press Ctrl+C to
copy it.
12. Press Ctrl+V to paste a copy of right under
Label1.
13. Press the Down arrow key 5 times to move Label2 down 5 steps, to
pos 5, 22.
14. Bring up the Label Properties (double-click on Label or press F4).
15. Change the caption to: Password:
TextBoxes (text fields)
16. Double-click on the TextBox control in the Toolbox dialog. 
17. Move the created TextBox1 up to position 45, 5 - right next to
Label1.
18. Expand the TextBox1 width to 150.
19. Bring up the TextBox1 Properties (double-click on TextBox1 or press
F4).
20. Remove the caption text for TextBox1 and OK the change.
21. With the TextBox control selected, press Ctrl+C
to copy it.
22. Press Ctrl+V to paste a copy of it right under
TextBox1.
23. Bring up the TextBox2 Properties (double-click on TextBox2 or press
F4).
24. Remove the caption text for TextBox2.
25. Add %ES_PASSWORD style to TextBox2 on tab page 2
and OK the changes.

Buttons
26. Select the Button control in the Toolbox dialog. 
27. Create a button size 50x15 at position 90, 50.
28. Bring up the Button1 Properties (double-click on the Button or
press F4).
29. Change the caption text for Button1 to: OK
30. Select a new Button id, %IDOK, from the ID name
ComboBox dropdown list.
31. Press Ok.
32. Select the Button control in the Toolbox dialog again.
33. Create a button size 50x15 at position 140, 50.
34. Bring up the Button2 Properties (double-click on Button or press
F4).
35. Change the caption text for Button2 to: Cancel
36. Select a new Button id, %IDCANCEL, in the ID name
ComboBox.
37. Press Ok.
Final design steps
38.
Resize the dialog to size 201, 70.
39. Test the dialog - Exit test mode
(just to show test mode).
40. Activate the menu - &File.
41. Save the project as PwrEntry.bas
42. Activate the menu again - &Tools.
|
 |
Now let's look at the souce code PB/Forms has generated (PwrEntry.bas)
43. Select Open file in IDE - PBEdit. (in the ToolBar
or the Tools menu)

PBEDIT

44. In PBEdit, bring up the Code Finder dialog.

45. Double-click on ShowDIALOG1Proc (or select it and
press Ok).
46. Add the following code at top of the ShowDIALOG1Proc:
LOCAL
sName, sPassWord AS STRING , so it
looks like:
CALLBACK FUNCTION ShowDIALOG1Proc() LOCAL sName, sPassWord AS STRING
Scroll down to %WM_COMMAND.
48. Add code under CASE %IDOK , so it
looks like:
CASE %IDOK IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
CONTROL GET TEXT CBHNDL, %IDC_TEXTBOX1 TO sName IF LEN(TRIM$(sName)) = 0 THEN MSGBOX "You must submit a name!", _ %MB_OK OR %MB_TASKMODAL, "PowerEntry" CONTROL SET FOCUS CBHNDL, %IDC_TEXTBOX1 EXIT FUNCTION END IF
CONTROL GET TEXT CBHNDL, %IDC_TEXTBOX2 TO sPassWord IF LEN(TRIM$(sPassWord)) = 0 THEN MSGBOX "You must submit a password!", _ %MB_OK OR %MB_TASKMODAL, "PowerEntry" CONTROL SET FOCUS CBHNDL, %IDC_TEXTBOX2 EXIT FUNCTION END IF
' For demonstration purpose, we only grab the text from ' the two input fields/TextBoxes and test their length. ' This would be the place to make sure each entry also ' is valid against the specifications needed for entry.
MSGBOX "User name: " + sName + $CRLF + _ "PassWord: " + sPassWord, _ %MB_OK OR %MB_TASKMODAL, "PowerEntry"
DIALOG END CBHNDL, %IDOK END IF
| 49.
Compile and Execute (Run) the code. |
 |
And here's the result:

Your PowerEntry program is now ready for a first test round.
|