Skip to content

Instantly share code, notes, and snippets.

View bervukas's full-sized avatar

Bernard Vukas bervukas

View GitHub Profile
@bervukas
bervukas / VariableNames.vb
Last active March 1, 2016 11:27
VBA Example: Variable Names
Sub Test()
Dim data As String
Dim data2 As Integer
Dim foo As Boolean
Dim wph As Integer
Dim dummy as Long
''
' etc.
End Sub
@bervukas
bervukas / MagicValuesFixed.vb
Created February 28, 2016 07:27
A better approach to using Magic Values in VBA
Private Const PASSWORD_LENGTH = 7
Sub SetPassword(password As String)
If (Len(password) > PASSWORD_LENGTH) Then
' Display error
End If
End Sub
@bervukas
bervukas / MagicValues.vb
Created February 28, 2016 07:20
Magic values example in VBA
Sub SetPassword(password As String)
If (Len(password) > 7) Then
' Display error
End If
End Sub
@bervukas
bervukas / IncorrectVariableDeclaration.vb
Last active March 1, 2016 11:47
Declaring variables on a single line in VBA
Sub CalculatePayroll()
Dim a, b, c, d As Integer '' Incorrect
'' Do this instead:
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer
@bervukas
bervukas / Comments.vb
Created February 26, 2016 15:44
Don't use the comments that merely restate the code
i = i + 1 ' increment i by one
@bervukas
bervukas / HungarianFixed.vb
Last active March 1, 2016 12:28
How to fix Hungarian notation
Function CalculateTotal(productId As String,
quantity As Integer,
unitPrice As Double) As Double
''''
' etc.
End Function
@bervukas
bervukas / Hungarian Notation.vb
Last active March 1, 2016 09:19
Hungarian notation example in VBA
Function CalculateTotal(sProductId As String,
iQuantity As Integer,
dUnitPrice As Double) As Double
''''
' etc.
End Sub
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon startFromScratch="false">
<tabs>
<tab id="customTab" label="Custom Tab">
<group id="customGroup" label="Custom Group">
<button id="customButton" label="Custom Button" imageMso="HappyFace" size="large" />
</group>
</tab>
</tabs>
</ribbon>