Hi,
Can I set the IDE to automatically print separators (line) between functions/subs? It shows the lines, but how can I print them? I found myself doing this manually for all subs so they look more readable.
Thanks
Printable View
Hi,
Can I set the IDE to automatically print separators (line) between functions/subs? It shows the lines, but how can I print them? I found myself doing this manually for all subs so they look more readable.
Thanks
anyone?
You don't need any lines to make it readable.
Just follow a few rules and you won't ever have readability problems again. :rolleyes:
Rule #1: Always have at least one empty line between procedures.
Rule #2: Do not use variable-declaration symbols. They're ugly.Code:' Unreadable:
Sub Proc1()
' Stuff
End Sub
Sub Proc2()
' Stuff
End Sub
Sub Proc3()
' Stuff
End Sub
' Readable:
Sub Proc1()
' Stuff
End Sub
Sub Proc2()
' Stuff
End Sub
Sub Proc3()
' Stuff
End Sub
Rule #3: Always indent the code depending on the context. Also, it is good to leave empty lines between lines of code. For example, I always separate the Dim lines from the other lines, etc.Code:' Unreadable:
Dim X%, Y&, Z!, A@, B$, C#
' Readable:
Dim X As Integer, Y As Long, Z As Single, A As Currency, B As String, C As Double
' If you have many variables of the same type, you can use a shortcut:
' Instead of:
Dim A As Long, B As Long, C As Long, D As Long
Dim E As String, F As String, G As String, H As String
Dim I As Double, J As Double, K As Double, L As Double
Dim M As Boolean, N As Boolean, O As Boolean, P As Boolean
' You can use:
DefLng A-D
DefStr E-H
DefDbl I-L
DefBool M-P
Dim A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P
Rule #4: Do not use the : (colon) operator. It looks ugly. Also, try to put several Dim lines depending on the data type.Code:' Unreadable:
Sub MySub()
Dim X As Integer, Y As Integer, Z As Integer
For X = 1 To 10
For Y = 1 To 10
For Z = 1 To 10
Debug.Print "(" & X & ", " & Y & ", " & Z & ")"
Next Z
Next Y
Next X
End Sub
' Readable:
Sub MySub()
Dim X As Integer, Y As Integer, Z As Integer
For X = 1 To 10
For Y = 1 To 10
For Z = 1 To 10
Debug.Print "(" & X & ", " & Y & ", " & Z & ")"
Next Z
Next Y
Next X
End Sub
If you still absolutely must print the lines... Do it manually. :rolleyes:Code:' Unreadable:
Dim DoIt As Boolean, X As Integer, Y As Integer, Z As Integer
Function MyProc() As Integer
If DoIt Then Y = 27: Z = 3: DoIt = False: Call SomeOtherProc: X = SomeFunction: MyProc = X + Y
End Sub
' Readable:
Dim DoIt As Boolean
Dim X As Integer, Y As Integer, Z As Integer
Function MyProc() As Integer
If DoIt Then
Y = 27
Z = 3
DoIt = False
Call SomeOtherProc
X = SomeFunction
MyProc = X + Y
End If
End Function
' Also readable:
Dim DoIt As Boolean
Dim X As Integer, Y As Integer, Z As Integer
Function MyProc() As Integer
If Not DoIt Then Exit Function
Y = 27
Z = 3
DoIt = False
Call SomeOtherProc
X = SomeFunction
MyProc = X + Y
End Function
Because that helps me alot ;)Quote:
Code:' You can use:
DefLng A-D
DefStr E-H
DefDbl I-L
DefBool M-P