strive4peace
AWF VIP
- Local time
- Today, 09:34
- Joined
- Apr 3, 2020
- Messages
- 1,023
Hello fellow Access Lovers!
We all want code we post to be better understood -- whether we're asking questions or answering them -- or coming back ourselves at some future time!
So this download is to give you green comments! without having to tag them yourself
Experienced programmers may not realize how much those green lines really help those who are struggling to understand!
Attached are 3 versions of this tool to add color tags to code for posting, like here on Access World Forums. And now one more version too ... NEW! (30 April) add-in to color comments AND keywords
Choose whichever download you want:
When you open the database, the form to tag code automatically opens (or when you launch the Add-in)
On the form, there are 4 textboxes showing you the tags that will be added before and after code, and before and after comments. They're set for Access World Forums using rich text code. You can change these tags to something else, if desired -- for instance, enter HTML if you have web pages with code that you want to make better understood.
When you make the form window taller, in 2007+, the code boxes grow since they're anchored. 2003- doesn't have anchoring -- but you can always go to the design view and change the size of the boxes yourself. If you resize the window, before you save it, change some property so it sticks.
In your AWF post:
Here is an example of what the code will look like in your post, using the code behind the f_ColorCOMMENTsGreen_s4p form:
EDIT: 12 April 2020: REPLACED DOWLOADS
changed the code to look to see if single quote in in a double quoted string. If so, it is ignored. This helps some of the coloring issues ... maybe most? If you see another place where it doesn't color what it should, or colors what it shouldn't, please post the line it failed on. And if you know how to fix it, post your code change so the download can be updated too (or maybe I'll figure it out), -- collaboration, and inspiration, drives us to be the best
Please share your comments! Thank you!
We all want code we post to be better understood -- whether we're asking questions or answering them -- or coming back ourselves at some future time!
So this download is to give you green comments! without having to tag them yourself
Experienced programmers may not realize how much those green lines really help those who are struggling to understand!
Attached are 3 versions of this tool to add color tags to code for posting, like here on Access World Forums. And now one more version too ... NEW! (30 April) add-in to color comments AND keywords
Choose whichever download you want:
- ACCDB: Access 2007 database (works in higher versions too) -- ColorCommentsGreen_s4p_200412_ACCDB.zip
- MDB: 2000 database. Perhaps someone can test this and make sure it works ok? thanks! Compile it first! and then SAVE. It isn't compiled for better chance of success -- mdb2K_ColorCommentsGreen_s4p_200412_NOT_COMPILED.zip
- ACCDA : Add-in (this is an ACCDB that's been renamed. Works in 2007+ higher versions too) -- Addin_ColorCommentsGreen_s4p.zip
- ACCDA: Add-in to Color Comments Green and Keywords Blue https://msaccessgurus.com/tool/Addin_ColorCode.htm
- one form (f_ColorCOMMENTsGreen_s4p) with all the code it needs behind the form
- one table (s4p_Code) The table is only necessary to allow longer code -- otherwise Access runs out of string space.
- AutoExec macro -- maximize and open form ... Add-in only maximizes
The Add-in also has a UsysRegInfo table for registry information. To install an Add-in, you must run Access as Administrator. By doing this, you can launch the add-in anytime, and save time so you can use the form to tag code anytime you're in Access! -- in any database!
Here is an 11-minute video to teach you how to install an Access Addin (and make one if you want to do that too!):
When you open the database, the form to tag code automatically opens (or when you launch the Add-in)
- Paste or write what you want in the Original Code textbox.
- TAB out of the Original Code control to run its AfterUpdate event, which adds tags to display the Result code for you.
- Press Alt-C to Copy the result code to the clipboard so you can paste it in a forum post, or wherever else you want. The shortcut seems to work better than clicking the button using Access 2007 with my crazy dual-installation.
Alternately, of course, you can select and copy whatever you want. F2 to toggle between insertion point and select whole value.
On the form, there are 4 textboxes showing you the tags that will be added before and after code, and before and after comments. They're set for Access World Forums using rich text code. You can change these tags to something else, if desired -- for instance, enter HTML if you have web pages with code that you want to make better understood.
When you make the form window taller, in 2007+, the code boxes grow since they're anchored. 2003- doesn't have anchoring -- but you can always go to the design view and change the size of the boxes yourself. If you resize the window, before you save it, change some property so it sticks.
In your AWF post:
- click the icon to Toggle BB code so you see the codes instead of the effects, and paste
Otherwise the codes won't work right!
Here is an example of what the code will look like in your post, using the code behind the f_ColorCOMMENTsGreen_s4p form:
Rich (BB code):
Option Compare Database
Option Explicit 'require variable declaration
'NEED table: s4p_Code
' so this will work with long code too
Private Sub Form_Load()
'200410 strive4peace
'clear old data
Me.codeOrig = Null
Me.codeResult = Null
End Sub
Private Sub codeOrig_AfterUpdate()
'200410,11,12 strive4peace
'read lines from codeOrig
'construct string to post in codeResult with specified tags
'process one line at a time
Dim sOrig As String _
, sLine As String _
, sBeforeComment As String _
, sAfterComment As String _
, sDeli As String _
, vResult As Variant _
, iPosSingleQuote As Integer _
, iPosDoubleQuote1 As Integer _
, iPosDoubleQuote2 As Integer _
, i As Integer _
, bInComment As Boolean _
, bAllComment As Boolean _
, bLook As Boolean
Dim aLine() As String
'set delimiter for lines
sDeli = vbCrLf
'initialize vResult
vResult = Null
With Me
'exit if code to process is blank
If IsNull(.codeOrig) Then GoTo Proc_WriteResult
'code to process
sOrig = .codeOrig
'set text to add before and after comment
sBeforeComment = Nz(.txtBeforeComment, "")
sAfterComment = Nz(.txtAfterComment, "")
End With
bInComment = False
bAllComment = False
'split code at line breaks
aLine = Split(sOrig, sDeli)
'process each line -- append color code before and after comment
For i = LBound(aLine) To UBound(aLine)
sLine = aLine(i)
bAllComment = False
iPosDoubleQuote1 = 0
iPosDoubleQuote2 = 0
'see if there is a single quote inside the string
iPosSingleQuote = InStr(sLine, "'")
If iPosSingleQuote > 0 Then
If Left(Trim(sLine), 1) = "'" Then
bAllComment = True
Else
'make sure single quote isn't inside double quotes
bLook = True
Do While bLook
'see if there is a double quote before the single quote
iPosDoubleQuote1 = InStr(Left(sLine, iPosSingleQuote), """")
If iPosDoubleQuote1 > 0 Then
'see if there is a double quote after the single quote
iPosDoubleQuote2 = InStr(iPosSingleQuote + 1, sLine, """")
If iPosDoubleQuote2 > 0 Then
'look for another single quote after the double quote end
iPosSingleQuote = InStr(iPosDoubleQuote2 + 1, sLine, "'")
If Not iPosSingleQuote > 0 Then
bLook = False
End If
Else
bLook = False
End If
Else
bLook = False
End If
Loop
End If
End If
If bAllComment Or iPosSingleQuote > 0 Then
If bInComment And Not bAllComment Then
'comment is at end of line
'end previous comment
vResult = vResult & sAfterComment
bInComment = False
End If
If Not bInComment Then
sLine = Left(sLine, iPosSingleQuote - 1) _
& sBeforeComment _
& Mid(sLine, iPosSingleQuote)
bInComment = True
End If
Else
If bInComment = True Then
vResult = vResult & sAfterComment
bInComment = False
End If
End If
vResult = (vResult + vbCrLf) & sLine
Next i
With Me
vResult = .txtBeforeCode & vResult & .txtAfterCode
End With
Proc_WriteResult:
Me.codeResult = vResult
End Sub
Private Sub cmd_Copy2Clipboard_Click()
'200411 strive4peace
'copy result code to the clipboard
Dim sCode As String
With Me.codeResult
If Nz(.Value, "") = "" Then Exit Sub
sCode = .Value
End With
'MSForms.DataObject
With CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
.SetText sCode
.PutInClipboard
End With
MsgBox "Press Ctrl-V to paste code with tags where you want it", , "Done"
End Sub
EDIT: 12 April 2020: REPLACED DOWLOADS
changed the code to look to see if single quote in in a double quoted string. If so, it is ignored. This helps some of the coloring issues ... maybe most? If you see another place where it doesn't color what it should, or colors what it shouldn't, please post the line it failed on. And if you know how to fix it, post your code change so the download can be updated too (or maybe I'll figure it out), -- collaboration, and inspiration, drives us to be the best
Please share your comments! Thank you!
Attachments
Last edited: