VBA is an abbreviation for "Visual Basic for Applications".
It is a computer programming language.
Here is an example:
Option Compare Database
'''''''''
' modification log
' 2014 april yourname wrote this program.
'
' 2014 April 30 - yourname changed this code
' to fix problem with the button bouncing off the right
' edge.
'''''''''''''''''''''''''''''''''''''''''''''
Dim strDirectionHorizontal As String
Dim strDirectionVertical As String
Dim intFormWidth As Integer
Dim intJumpHorizontal As Integer
Dim intJumpVertical As Integer
Dim intKount As Integer
Private Sub Form_Load()
' initialize variables
strDirectionHorizontal = "LEFT"
strDirectionVertical = "UP"
intJumpHorizontal = 10 'pixels picture element
intJumpVertical = 10 'pixels picture element
''''Me.Width = 3000 'setting the width of the form in PIXELS
''''Box1.Width = 3000
'MsgBox "THE WIDTH OF THE FORM IS " & Me.Width & " PIXELS"
intFormWidth = Me.Width
End Sub
Private Sub cmdVBA_Click()
' this event is fired when you click on the button
intKount = 0
' LOOP 10 TIMES (ENDLESS LOOP)
MOVE: ' COLON : SEMI-COLON ;
'call sub-routine
Call MovingButton
intKount = intKount + 1
If intKount < 1000 Then GoTo MOVE ' label
' CTRL-ALT-DEL TASK MANAGER
End Sub
Public Sub MovingButton()
Dim intRightEdge As Integer
Dim intBottomEdge As Integer
Dim intTopEdge As Integer
' move up UNTIL you reach the top
If cmdVBA.Top < intJumpVertical _
Or strDirectionVertical = "DOWN" Then
' moving down
'''''commented out''''Box1.BackColor = vbGreen
strDirectionVertical = "DOWN"
cmdVBA.Top = cmdVBA.Top + intJumpVertical
' calculate bottom edge
intBottomEdge = Box1.Height - cmdVBA.Height
If cmdVBA.Top >= intBottomEdge Then
' change direction ... move up
Box1.BackColor = vbBlack
strDirectionVertical = "UP"
cmdVBA.Top = cmdVBA.Top - intJumpVertical
End If
Else
' moving up ''''''''''''''''
cmdVBA.Top = cmdVBA.Top - intJumpVertical
If cmdVBA.Top < intJumpVertical _
Or strDirectionVertical = "DOWN" Then
' change the color to green
Box1.BackColor = vbGreen
End If
End If
' if we are bouncing off the left edge,
' change the direction to 'right'
' change the box color
If cmdVBA.Left <= intJumpHorizontal Then
strDirectionHorizontal = "RIGHT"
Box1.BackColor = &H11FFFF ' hex color
End If
If strDirectionHorizontal = "RIGHT" Then
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' check for the right edge of the form
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' calculate the position of the right edge of the button
intRightEdge = cmdVBA.Left + cmdVBA.Width
' fir testing purposes only
'MsgBox "intRightEdge=" & intRightEdge
' 2014 April 30 - yourname changed this code
' to fix problem with the button bouncing off the right
' edge.
intFormWidth = Box1.Width ''' Me.Width
'MsgBox "intformwidth=" & intFormWidth ' for testing only
If intRightEdge >= intFormWidth Then ' NESTED IF
strDirectionHorizontal = "LEFT"
Box1.BackColor = vbBlue ' change background color to blue
Else
' move the button to the right
cmdVBA.Left = cmdVBA.Left + intJumpHorizontal ' ADD intJumpHorizontal PIXELS
End If
Else
' move the button to the LEFT
cmdVBA.Left = cmdVBA.Left - intJumpHorizontal ' SUBTRACT intJumpHorizontal PIXELS
End If
' REFRESH THE DISPLAY
' REDRAW THE SCREEN
DoEvents
End Sub