First Steps Getting Started with Visual Basic 6.0

Gary Beene's VB Tutor VB Primer Links VS Mag Extreme VB MVPS VB-net VB About.com Duane Moore's VB Links VB6 Database Pgmg

Open VB IDE

after Patricia Hartman's Teach Yourself Visual Basic 6
  1. Select New from the File menu (or click the New Projects icon on the Toolbar)
  2. Select Standard.EXE
  3. Select Form1 in Properties window (middle RHS); name it Form2
  4. Find the Captions attribute of Form2 (5 down from name), enter MOUSE EVENTS into the Caption. (The Form title bar changes to MOUSE EVENTS)
  5. From ToolBox along LHS, double click the CommandButton icon to place a CommandButton in the center of the form.
  6. In Properties window (middle RHS), change the Caption of Command1 to Mouse Down. (The Button is re-labled Mouse Down)
  7. On the Form2, Double Click on the Mouse Down Button; a code editor window appears. The code editor window has two drop-down menus.
  8. In the left-hand drop-down menu of code editor window, select Commnad1
  9. In the right-hand drop-down menu of code editor window, select MouseDown
  10. In the code editor window appears the following code stub:
    Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X as Integer, Y as Integer)
    
    End Sub
    
  11. Add two lines of code so that the result is
    Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X as Integer, Y as Integer)
       Beep
       MsgBox "BUTTON= " + Format$(Button) + ", X= " + Format$(X) + ", _ Y= " + Format$(Y)
    End Sub
    
  12. Do similarly to create a MouseUp Command button - Note, when you add a second CommandButton, it appears to eclipse the first one! Just drag it aside and first one is still there...
  13. Save Project (either icon or File -> Save Project)
  14. VERY Important! to run, click the Run Icon on top tool bar (it's a blue right-facing triangle)
  15. A new run-time window with your form containing your two buttons... click on either button.

From Learn to Program with Visual Basic 6 by John Smiley

Notes on syntax

  1. Continuation character is underscore preceded by blank: use when splitting a line of code onto two lines.
  2. to print on a form, eg form1, Form1.Print "Eat at Joe's"
  3. Private Sub Command1_Click()
      If WeekDay(Now) = vbSunday Then Form1.Print "Eat " & _
                           "at Joe's"
      If WeekDay(Now) = vbMonday Then Form1.Print "Eat " & _
                           "at Tom's"
    End Sub
    
  4. Count to ten:
    Private Sub Command1_Click()
      Dim lngCounter AS long     ' Declare the counter variable
      For lngCounter = 1 to 1000 ' Loop
         Debug.Print lngCounter
      Next lngCounter
    End Sub
    
  5. Declare variables with "Dim" statement; use common VB naming convention of first 3 letters reflect variable type, if known. (if you just say "Dim myvariable" the type is "Variant" by default) Variant data type is good for receiving interactive user input which may be numeric or alphabetic, etc.
  6. Defining several integers:
    Dim intPrice1 As Integer, intPrice2 As Integer, intPrice3 As Integer
  7. Command separator is ":"
    e.g.
    Dim intPrice1 As Integer: Dim intPrice2 As Integer
ControlPrefix VariablePrefix
Check Boxchk Booleanbin
Combo Boxcbo Currencycur
Command Buttoncmd Doubledbl
Common Dialog ControldigDate & Timedat
Datadat Longlng
Formfrm Integerint
Framefra Singlesng
Gridgrd Stringstr
Imageimg Variantvar
LabelIbl  
List Boxlst  
Menumnu  
Option Buttonopt  
Picturepic  
Shapeshp  
Text Boxtxt  
Timertmr  

dkerr(replace with @ symbol)mindspring.com


back to Index | back to Links


last updated 5-17-2004 dek