' -----------VBScript macros For Code-Genie V3.0 -------------
' In order To enable the macro feature you must install the
' ScriptContol from Microsoft. Some places where you can Find
' it:
' www.code-genie.com/sc.exe
' www.activex.com
' www.microsoft.com

'------------ Sample macros ---------------

' Greetings
sub vbGreetings
	MsgBox "Hello World"
end sub

' Append text to the end of doc
sub vbAppend
	Doc.SSE=cgDocEnd 'or =Doc.GetSize
	Doc.SelText="Text to append goes here"
End Sub

' Remove the selected text
sub vbDelSelection
	Doc.SelText=""
end sub

'Select the word the cursor is currently over
SUB vbSelWord
	Doc.SS=Doc.AuxMove(Doc.SE,cgWordLeft)
	Doc.SE=Doc.AuxMove(Doc.SE,cgWordRight)
end sub

' Remove the 3rd row
sub vbRemove3rdRow
	' Row numbering starts from 0:
	if Doc.LineCount<3 Then
		Exit Sub ' Less than 3 rows
	End If
	Doc.SS=Doc.LineToPos(2)
	Doc.SE=Doc.AuxMove(Doc.SS,cgLineEnd)
	If Doc.SE<Doc.GetSize Then
		' Add the end of the line, too
		Doc.SE=Doc.SE+1
	End If
	Doc.SelText="" ' Remove it!
End Sub

' prefix each line with "row No:"
' where No is the number of the given row
sub vbPrefixLines
	for nLine=0 To Doc.LineCount-1
		Doc.SSE=Doc.LineToPos(nLine)
		Doc.SelText="row "&(nLine+1) & ": " 'Using '&' for string concatenation
	next
end sub

' Remove HTML-tags from the doc
sub vbRemoveHTMLTags
	'Remove the selection if any, so Replace applies to the whole doc
	Doc.SSE=Doc.SE
	' remove the comments first
	Doc.Replace "/<!--.*-->/Us","",cgFindRegExp 'Regular replace
	' then remove the html-tags
	Doc.Replace "/<.*>/Us","",cgFindRegExp 'Regular replace
end sub

' Multiplication-table
' from 1x1 to 9x9
sub vbMulTable
	Doc.SSE=Doc.SE ' remove the selection
	for i=1 to 9
		for j=1 to 9
			Doc.SelText=i & "x" & j & "= " & (i*j) & vbNewLine
		next 'j
	next 'i
end sub

' Moves To the Next function definition
Sub vbCPPNextFunctionDef()
	nLine=Doc.PosToLine(Doc.SSE)
	if nLine<Doc.LineCount-2 Then
		Doc.SSE=Doc.LineToPos(nLine+2)
		a=Doc.Find("^\{",cgFindRegExp)
		If a<>-1 Then
			a=Doc.PosToLine(a)-1
			Doc.SSE=Doc.LineToPos(a)
		End If
	end if
End Sub

' Moves To the previous function definition
Sub vbCPPPrevFunctionDef()
	a=Doc.Find("^\{",cgFindUp+cgFindRegExp)
	if a<>-1 Then
		nLine=Doc.PosToLine(a)
		if nLine>0 Then
			nLine=nline-1
		end if
		Doc.SSE=Doc.LineToPos(nLine)
	End If
End Sub

'--------- User Defined Macros ------------

' Description
Sub MacroName
	Doc.SSE=Doc.SE
	Doc.Replace "<t(.*)>","\t<t\1>",cgFindRegExp
End Sub
