Assignment #1A
- Open Microsoft Word.
- Create a blank document.
- Get the "Developer" tab visible in the ribbon. To do this, first
press the "File" tab.
- Next press the "Options" button.
- Select "Customize Ribbon" and then turn on the "Developer" tab.
- You should now see the "Developer" tab displayed in the ribbon.
- Insert the text "Simple Calculator" and "Your Name". Then
insert a 3x3 table by selecting "Table" under the tab "Insert".
- Merge the right cells by selecting them and then right clicking
and selecting the option "Merge Cells".
- Insert the text "First number:", "Second number:", and "Answer".
Then insert a "Text Box" in the top middle cell of the table by
selecting "Text Box (ActiveX Control)" under the "Legacy Forms"
in the "Developer" tab.
- Right click on the text box you just created and select
"Properties."
- On the Properties window, give the textbox the name "txtNum1".
Optionally change the "BackColor", "BackStyle", "BorderColor",
"BorderStyle", "Font", and "Height".
- Copy and paste the textbox you just created into the
middle row, middle column. Right click on this new textbox,
and give it the name "txtNum2".
- Insert a label into the middle column of the last row,
by selecting the "Label" option under "Active X Controls",
"Legacy Tools" under the "Developer" tab.
-
Right click on the label you just created and select
"Properties." On the Properties window, give the
label the name "lblAnswer".
Optionally change the "BackColor", "BackStyle", "BorderColor",
"BorderStyle", and "Font".
- Insert a command button into the last column, last row,
by selecting the "Command Button (ActiveX Control)" option
under "Active X Controls", "Legacy Tools" under
the "Developer" tab.
-
Right click on the command button you just created and select
"Properties." On the Properties window, give the
command button the name "cmdAdd" and the Caption "+".
Optionally change the "BackColor", "BackStyle",
and "Font".
- Double click on the command button you just created.
This will open the code window for Visual Basic.
Enter the text "Option Explicit" at the top.
Then between the "Private Sub" and "End Sub" enter the text:
lblAnswer = val(txtFirst) + val(txtSecond)
This will add the values in the two textboxes and store
the answer in the label.
- Close the Visual Basic code window by pressing
the top "X". This will take you back to MS Word.
- Press the "Design Mode" button on the "Developer" tab.
This button toggles between displaying the code and
executing the code.
- Enter values in the textboxes for "First number:"
and "Second number:". Then select the command button
with the caption "+". When this button is selected
the values in the two textboxes will be added together.
- Repeat this process for the command buttons for
minus "-", multiplication "*", and division "/".
- Create a "Clear" command button. This will simply
clear the values in the two textboxes and one label.
Shown below is the code for the "Clear" command button.
|