Hi to all
I'd made a little script really usefull for me.
It put or remove the ' sign for commenting or decommenting block of line in a
vbscript or visual basic files.
Hope it can be usefull.
'*******************************************************************************
' Filename : AddRemoveVbsComment.vbs
'
' Description : Put or Remove a Vbs's remark at the biginning
' of every selected lines
'
' Created : 26 October 2007
' Created by : LordMax aka Max Enrico from Italy
'
' Note : This extension detect only the first selected
line of code.
' Be sure that's the one you
want!
' P.S. I'm using CTRL+ALT+M for this
function 'cause is good
' for me. You're free to change
the combination like you want
'
' You may distribute this script freely, but please keep this header
intact.
'*******************************************************************************
Option Explicit
Const MODULE_NAME = "AddRemoveVbsComment"
Const MODULE_VER = "0.1"
Const MODULE_TITLE = "Add or Remove Vbs comment mark"
Sub Init
addMenuItem MODULE_TITLE, "Utilities", MODULE_NAME, "CTRL+ALT+M"
End Sub
' Detect if remarks are present or not and call the right sub
Sub AddRemoveVbsComment()
Dim editor
Dim strInput
Set editor = newEditor()
editor.assignActiveEditor
strInput = editor.selText
if left(strInput, 1) = "'" then
call Removevbscomment
else
call Addvbscomment
end if
End sub
Sub Addvbscomment()
Dim editor
Dim strInput, strTemp
Dim intCount, intPos
Set editor = newEditor()
editor.assignActiveEditor
strInput = editor.selText
If Len(strInput) > 0 Then
strInput = "'" & strInput
intCount = Len(strInput)
intPos = instr(1, strInput, chr(10))
do until intPos=0
strTemp = left (strInput, intPos) & "'" & right
(strInput, intCount - intPos)
strInput = strTemp
intCount = Len(strInput)
intPos = instr(intPos +1, strInput, chr(10))
loop
' used to verify if selection is at the biginning of the line
or not
if instr(intCount-1, strInput, chr(10)) then
editor.selText (left (strInput, intCount-1)) '
'cause it place another remark
at the end of the line
else
editor.selText strInput
end if
Else
MsgBox "Please select some text... ", 48, MODULE_TITLE
End If
Set editor = Nothing
End Sub
Sub Removevbscomment()
Dim editor
Dim strInput, strTemp
Dim intCount, intPos
Set editor = newEditor()
editor.assignActiveEditor
strInput = editor.selText
If Len(strInput) > 0 Then
if instr(1, strInput, "'") = 1 then ' to remove first remark
strInput = right(strInput, Len(strInput)-1)
end if
intCount = Len(strInput)
intPos = instr(1, strInput, "'")
do until intPos=0
if intPos > 1 then
if mid (strInput, intPos-1, 1) = chr(10) then
strTemp = left (strInput, intPos-1) &
right (strInput, intCount -
(intPos))
strInput = strTemp
intCount = Len(strInput)
end if
end if
intPos = instr(intPos+1, strInput, "'")
loop
editor.selText strInput
Else
MsgBox "Please select some text... ", 48, MODULE_TITLE
End If
Set editor = Nothing
End Sub
--
<http://forum.pspad.com/read.php?2,35782,43856>
PSPad freeware editor http://www.pspad.com