Using the VBA Label
to Create Flash Cards
This tutorial uses the VBA label to create flash cards and uses Excel.
First, go to the VBA Editor/IDE; ALT + F11.
Right click on any line/branch in the VBAProject Explorer at the upper left below the toolbars. Go to Insert and click on UserForm.
Click on the capital A, which is the VBA Label control, and then drag the mouse on the form in a down and to the right fashion to create a label. You can resize the label after you have draw/created it by using the white squares along the border of the label.
SIDEBAR----- you can also resize the form by clicking on any blank space on it and using the white squares along the border. SIDEBAR-----
For this flash card example we'll ne 3 VBA labels, So...
Right click on the VBA label and choose Copy.
Click on a blank space on the form and choose Paste. A new VBA label is created in the center of the form. drag it to under the first label.
Repeat the previous step and move the third label under the second.
In the toolbox, click on the rectangular icon which is the Command Button and then click on the form to create one, or drag to draw it. Repeat to create a second command button.
Now, create two checkboxes, we're going to sophisticate our flash cards.
Add another VBA label in the upper right hand corner of the form in the same way that you added the first VBA label.
On the lower left of your screen you should see the Properties window.
Click on the left Command Button. Its properties now appear in the Properties window. Change its Name to Answer - the first property - and its Caption to Answer - the eighth row.
Click on the right Command Button. Its properties now appear in the Properties window. Change its Name to StopRun - the first property - and its Caption to Close - the eighth row. "Close" is not a legal name for a control because it is a VBA Keyword so we use StopRun here.
Click on the left Checkbox. Change its Name to Num and its Caption to No..
Click on the right Checkbox. Change its Name to Cap and its Caption to Capitols.
SIDEBAR----- After you see that the code works, you can reposition the controls and change the font size if you like. To change the font, its size, etc. click on the current font in the Font property and then on the ellipsis. SIDEBAR-----
Right click on the form in the Project window and then on View Code...
Copy the following code to the code window...
Copy the 50 states and their capitals from click here To select the states/capitals, drag your mouse from Alabama down though Cheyenne. Right click the selected text, open Notepad (Start menu>Run, type notepad, press Enter). Paste the states into Notepad (Edit menu > Paste) and save it to your desktop as abc (or something else). Close Notepad and the web page with the 50 states.
In Excel, click in cell A1 (on Sheet1). Go to the Data menu,
click Import External Data then Import Data. Choose the file abc
(or the something else), make sure "Delimited" is marked near the upper
left of the dialog box. Press Finish and then Enter. You should have
the 50 states in column A from rows 1 to 50 and the capitals next to
them in column B.
All this code runs from within the form. We need a Sub to open the form.
Right click on any line in the VBAProject window, then on Insert, and choose Module. Paste the following in the code window of the module...
Sub OpenForm()Put the cursor within any of these three lines of code and press F5 to run the code.
If you want to see how the code works in slow motion - step in mode - you can set a breakpoint by putting the cursor in the line...
Private Sub Answer_Click()
and pressing F9 to toggle the breakpoint on. Run the OpenForm subroutine as before. When you click on the Question/Answer button the code will stop on that line and from there you can press F8 to step through the code one line at a time to see how it works.
You could also start stepping through the code (F8) from the OpenForm subroutine and when you get caught in the loop that sets all the values in the iUsed array, set a breakpoint after the loop and press F5 once to complete the loop and then continue with F8.
If, along with memorizing the 50 state capitals, you have memorized the states in alphabetical order, you can check the No. checkbox. You would then be prompted with a number and have to know the state corresponding to it, or, if you also checked the Capitals checkbox, know the state and the capital.
site is powered by Site Build It!. If you enjoy it, please check out