Tutorial: Programming in Visual Basic 6.0
Tutorial: Programming in Visual Basic 6.0
Tutorial: Programming in Visual Basic 6.0
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Add a clear command button with the follow<strong>in</strong>g code to allow the user to do another<br />
calculation.<br />
txtOne.Text = “”<br />
txtTwo.Text = “”<br />
lblAnswer.Caption = “”<br />
txtOne.SetFocus<br />
The SetFocus method returns the cursor to the first <strong>in</strong>put box.<br />
Set properties to pretty it up.<br />
Check that it works. Use <strong>in</strong>tegers, very big numbers, very small numbers, negative<br />
numbers, zeros, etc. Is your label big enough for all values? If you set the label’s<br />
autosize property to true it will stretch to fit.<br />
Add a remark (put ‘ at the beg<strong>in</strong>n<strong>in</strong>g of the l<strong>in</strong>e) at the top of your code which <strong>in</strong>cludes<br />
your name and the date.<br />
Connect to a B<strong>in</strong>ary Selection menu head<strong>in</strong>g on the ma<strong>in</strong> form.<br />
Sequence algorithms<br />
programs <strong>in</strong> Activities 1 — 3 were all constructed from sequence algorithm<br />
The<br />
Each l<strong>in</strong>e of code followed another with only one possible pathway for each<br />
constructs.<br />
So, for each sub procedure, the algorithm would consist of <strong>in</strong>put, output and a<br />
event.<br />
of process steps, e.g.<br />
series<br />
Private Sub cmdClear_Click() `user <strong>in</strong>put<br />
txtOne.Text = “”<br />
`sequence of processes <strong>in</strong>itializ<strong>in</strong>g variables<br />
txtTwo.Text = “”<br />
lblAnswer.Caption = “”<br />
txtOne.SetFocus<br />
End Sub `output<br />
B<strong>in</strong>ary selection<br />
next group of programs you will write uses the second algorithm construct —<br />
The<br />
Selection allows multiple pathways for any event and allows for choices to be<br />
selection.<br />
made. Selection constructs can be B<strong>in</strong>ary (two way) or Multiway (multiple choices)<br />
selection uses the If – End If or the If – Else – End If statements. Here<br />
B<strong>in</strong>ary<br />
the syntax <strong>in</strong> <strong>Visual</strong> <strong>Basic</strong>.<br />
is<br />
OR<br />
comparison test Then<br />
If<br />
or more <strong>Visual</strong> <strong>Basic</strong> statements<br />
One<br />
End If<br />
comparison test Then<br />
If<br />
or more <strong>Visual</strong> <strong>Basic</strong> statements<br />
One<br />
Else<br />
or more <strong>Visual</strong> <strong>Basic</strong> Statements<br />
One<br />
If End<br />
(You have used b<strong>in</strong>ary selection <strong>in</strong> your calculator to prevent a user divid<strong>in</strong>g by zero.)