HTA with dynamically generated HTML Tables with onclick faults - vbscript

Right. I need help here. I have a HTA, and it runs completely fine. UNTIL I do the following to my code. I am working with VBScript. Code below:
<Script language="vbscript">
Sub DisplayDB_Click
Dim conn, str1, str2
str2 = "Hello"
MainTitle.InnerHTML = "<h2>Main Call Queue</h2>"
Set conn = CreateObject("ADODB.Connection")
conn.Open "DSN=LongbowLogin"
Set rsData = conn.Execute("SELECT * FROM MainTable WHERE CallStat='Open' ORDER BY P_ID DESC;")
str1 = "<table border=1 cellpadding=5><tr><th>Call Id</th><th>Full Name</th><th>Postcode</th><th>Site Code</th><th>Problem Title</th><th>Category</th><th>SubCategory</th><th>Call Status</th></tr>"
Do Until rsData.EOF = True
str1 = str1 & "<tr><td onclick=msgbox(str2)>" & rsData("P_Id") & "</td><td>" & rsData("FirstN") & "</td><td>" & rsData("PostCode") & "</td><td>" & rsData("SiteNumber") & "</td><td>" & rsData("PTitle") & "</td><td>" & rsData("PCat") & "</td><td>" & rsData("SCat") & "</td><td>" & rsData("CallStat") & "</td></tr>"
rsData.moveNext
Loop
str1 = str1 & "</table>"
MainDisplay.InnerHTML = str1
conn.Close
Call CheckState
End Sub
This code makes a HTML Table out of a SQL Select Statement and places it in a Span tag named MainDisplay under InnerHTML. This part works beautifully. However - After I add the
< td onclick='msgbox(str2)' > part, it will not work.
I click the first cell, and I get a message: "Line 1, 'str2' is not defined.".
I actually want it to say
< td onClick='CellID Me') > , CellID being a sub later in the same script block. I am doing this msgbox to troubleshoot.
str2 clearly is defined, so I'm clearly missing something here...
Any help here would be great, I'm going mad...
Many Thanks.

VBScript does no variable interpolation:
>> Dim str2 : str2 = "I'm str2 and this is my content"
>> Dim sRes : sRes = "<td onclick=MsgBox str2></td>"
>> WScript.Echo sRes
>>
<td onclick=MsgBox str2></td>
You'll have to splice the content into the result - and follow VBScript's rules about parentheses and quotes:
>> Dim str2 : str2 = "I'm str2 and this is my content"
>> Dim sRes : sRes = "<td onclick='MsgBox """ & str2 & """'></td>"
>> WScript.Echo sRes
>>
<td onclick='MsgBox "I'm str2 and this is my content"'></td>
This explains your immediate problem. Your real world task - attach a onclick event handler to all TDs - is better solved by creating the table using the DOM (.createElement, appendChild) than by trying to tame string concatenations into .innerHTML.

To make the MsgBox work you'll have to change this:
"<tr><td onclick=msgbox(str2)>" & rsData("P_Id") & ...
into this:
"<tr><td onclick='msgbox(""" & str2 & """)'>" & rsData("P_Id") & ...
However, I already told you that the code
"<tr><td onclick='Cell Me'>" & rsData("P_Id") & ...
works in principle. I verified this with an HTA that creates a table from a CSV on button-click.
VBScript:
Sub DisplayDB_Click
Set conn = CreateObject("ADODB.Connection")
conn.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
& "Dbq=c:\Temp;Extensions=asc,csv,tab,txt;"
Set rsData = conn.Execute("SELECT * FROM sample.csv;")
str1 = "<table border=1 cellpadding=5><tr>"
For Each field In rsData.Fields
str1 = str1 & "<th>" & field.Name & "</th>"
Next
str1 = str1 & "</tr>"
Do Until rsData.EOF
str1 = str1 & "<tr>"
For Each field In rsData.Fields
str1 = str1 & "<td onclick='Cell Me'>" & field.Value & "</td>"
Next
str1 = str1 & "<tr>"
rsData.moveNext
Loop
str1 = str1 & "</table>"
MainDisplay.InnerHTML = str1
conn.Close
End Sub
Sub Cell(obj)
MsgBox obj.innerHtml
End Sub
HTML:
<p><input type="button" onClick="DisplayDB_Click" value="Show Table"/></p>
<div id="MainDisplay"></div>
If this code doesn't work for you, the issue is somewhere else in the HTA.
As Ekkehard.Horner suggested, the table could also be created using createElement and appendChild, e.g. like this:
Sub Cell
MsgBox Me.innerHtml
End Sub
Function NewField(text, isHeader)
If isHeader Then
Set e = document.createElement("th")
Else
Set e = document.createElement("td")
End If
e.AppendChild document.createTextNode(text)
e.onClick = GetRef("Cell")
Set NewField = e
End Function
Function NewRow(values, isHeader)
Set r = document.createElement("tr")
For Each v In values
r.appendChild NewField(v, isHeader)
Next
Set NewRow = r
End Function
Sub DisplayDB_Click
...
lastCol = rsData.Fields.Count-1
Dim cols
ReDim cols(lastCol)
For i = 0 To lastCol
cols(i) = rsData.Fields(i).Name
Next
Set thead = document.createElement("thead")
thead.appendChild NewRow(cols, True)
Set tbody = document.createElement("tbody")
Do Until rsData.EOF
For i = 0 To LastCol
cols(i) = rsData.Fields(i).Value
Next
tbody.appendChild NewRow(cols, False)
rsData.MoveNext
Loop
Set table = document.createElement("table")
table.appendChild thead
table.appendChild tbody
document.getElementById("parent").appendChild table
...
End Sub

Related

Remove duplicate values from a string in classic asp

I have below code in classic asp
str=Request.Form("txt_str")
"txt_str" is text box in a classic asp form page where I am entering below values:
000-00001
000-00001
000-00001
000-00002
response.write str
hence str will be 000-00001 000-00001 000-00001 000-00002
array = split(str,Chr(44))
if str <> "" then
x=empty
for i = 0 to ubound(array)
if array(i) <> "" then
array_2 = split(array(i),chr(13) & chr(10))
for j = 0 to ubound(array_2)
if array_2(j) <> "" then
if x=empty then
x= "'" & array_2(j) & "'"
else
x= x & ",'" & array_2(j) & "'"
end if
end if
next
end if
next
End if
response.write x
hence x will be returned as '000-00001','000-00001','000-00001','000-00002'
I want to remove duplicate values from x and display only it as:
x = '000-00001','000-00002'
How can i achieve this.Any help on this would be appreciated.
Thanks
To remove duplicates of string lists, the best option IMO is to use a Dictionary object. You can use this short function to do the task on a given string array:
Function getUniqueItems(arrItems)
Dim objDict, strItem
Set objDict = Server.CreateObject("Scripting.Dictionary")
For Each strItem in arrItems
objDict.Item(strItem) = 1
Next
getUniqueItems = objDict.Keys
End Function
A simple test:
' -- test output
Dim arrItems, strItem
arrItems = Array("a","b","b","c","c","c","d","e","e","e")
For Each strItem in getUniqueItems(arrItems)
Response.Write "<p>" & strItem & "</p>"
Next
This is a sample for your use case:
' -- sample for your use case
Dim strInput, x
strInput = Request.Form("txt_str")
x = "'" & join(getUniqueItems(split(str, Chr(44))), "','") & "'"
BTW, did you notice that Array and Str are VBScript Keywords, so you may run into issues with using such variable names. Therefore, I think it is common practice in VBScript to use prefixes for variable names.
If it's a ordered list, consider using a variable with last value:
lastval = ""
array = split(str,Chr(44))
if str <> "" then
x=empty
for i = 0 to ubound(array)
if array(i) <> "" then
array_2 = split(array(i),chr(13) & chr(10))
for j = 0 to ubound(array_2)
if array_2(j) <> "" then
if array_2(j) <> lastval then
lastval = array_2(j)
if x=empty then
x= "'" & array_2(j) & "'"
else
x= x & ",'" & array_2(j) & "'"
end if
end if
end if
next
end if
next
End if

user login form vb6 error

hi,
i write programme in vb6 and depend on ms access database
i create table in ms access (users)
then i make module :-
Public DB As New ADODB.Connection
Public RS As New ADODB.Recordset
Public RSS As New ADODB.Recordset
Public SQLS As String
Public UserNames As String
Public UserPassword As String
Sub POOLCONNECTION()
If DB.State = adStateOpen Then DB.Close
DB.Provider = "Microsoft.JET.OLEDB.4.0"
DB.Open App.Path & "\data.mdb"
End Sub
and i make some forms for user :-
1- i make check user form to create administrator user for the first time to use. if there are no records this form will create admin user
code:-
Private Sub Form_Load()
Text1 = " "
Text2 = " "
Text3 = " "
POOLCONNECTION
SQLS = " Select * From Users "
If RS.State = adStateOpen Then RS.Close
RS.Open SQLS, DB, adOpenKeyset, adLockPessimistic
If Not RS.RecordCount = 0 Then
FRMLOGIN.Show
Unload Me
End If
End Sub
Private Sub save_Click()
If Text1 = " " Then
MsgBox " Sorry, You Must Type Username ", vbCritical + vbMsgBoxRight, "Error"
Text1.SetFocus
Exit Sub
End If
If Text2 = " " Then
MsgBox " Please Type Old Password ", vbCritical + vbMsgBoxRight, " Error "
Text2.SetFocus
Exit Sub
End If
SaveMsg = MsgBox(" åá ÊÑíÏ ÇäÔÇÁ ãÏíÑ ááäÙÇã ?", vbQuestion + vbMsgBoxRight + vbYesNo, " Êã ÇáÍÝÙ ")
If SaveMsg = vbYes Then
RS.AddNew
RS![UserName] = Text1
RS![Password] = Text2
RS![GAdd] = True
RS![GEdit] = True
RS![GPrint] = True
RS![GCreateUser] = True
RS![GDelete] = True
RS.Update
MsgBox " Êã ÍÝÙ ÇáÈíÇäÇÊ", vbInformation + vbMsgBoxRight, " Saved "
' Save This Informations
UserNames = Text1
UserPassword = Text2
' Long Main
Set RS = Nothing
Set DB = Nothing
MDIForm1.Show
Unload Me
End If
End Sub
for the second time use after i have making adimn user login form show and i try to login with the admin user .. eof didn't read the records
login code :
Private Sub Command1_Click()
If Text1 = "" Or Text2 = "" Then
MsgBox " ÚÝæÇ íÌÈ ßÊÇÈÉ ÇÓã ÇáãÓÊÎÏã æßáãÉ ÇáãÑæÑ ", vbCritical + vbMsgBoxRight, " ÎØà Ýì ÇáÏÎæá"
Exit Sub
End If
SQLS = "Select * From Users Where Username = ' " & Text1 & " ' And Password = ' " & Text2 & " ' "
If RS.State = adStateOpen Then RS.Close
RS.Open SQLS, DB, adOpenKeyset, adLockPessimistic
If RS.EOF Then
MsgBox " Sorry, The Username And Password Is Wrong ! ", vbCritical + vbMsgBoxRight, " Error Login "
Else
Set RS = Nothing
Set DB = Nothing
MDIForm1.Show
Unload Me
End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
POOLCONNECTION
End Sub
Private Sub text1_keypress(keyAscii As Integer)
If keyAscii = 13 Then
Text2.SetFocus
End If
End Sub
Private Sub text2_keypress(keyAscii As Integer)
If keyAscii = 13 Then
Command1.SetFocus
End If
End Sub
Remove unnecessary spaces before and after texts:
SQLS = "Select * From Users Where Username = '" & Text1 & "' And Password = '" & Text2 & "' "

Pop up alert vb 6

Can someone help me. I'm having a hard time with this. All I need is to display an alert message whenever the medicines expired.My problem is when I got two or more expired medicines it doesn't alert all.Instead it alerts one medicine.Please help.
here is my code
Private Sub Form_Activate()
On Error Resume Next
With Main
.Text4 = Adodc1.Recordset.Fields("MedicineName")
.Text1.Text = Adodc1.Recordset.Fields("genericname")
.Text3.Text = Adodc1.Recordset.Fields("StockQuantity")
.Combo3 = Adodc1.Recordset.Fields("Expmonth")
.Combo4 = Adodc1.Recordset.Fields("Expday")
.Combo5 = Adodc1.Recordset.Fields("Expyear")
End With
Dim expirationdate As Date
expirationdate = CDate(Combo3 & "/" & Combo4 & "/" & Combo5)
datepicker.Value = Format(Now, "MMM-DD-yyyy")
If datepicker > expirationdate Then
MsgBox Text4.Text & " is expired ", vbExclamation, "Warning!"
If MsgBox("Do you want to dispose " & Text4 & "?", vbQuestion + vbYesNo, "Message") = vbYes Then
Adodc1.Recordset.Delete
ElseIf vbNo Then
Exit Sub
End If
End If
End Sub
Private Sub Form_Load()
Adodc1.CommandType = adCmdUnknown
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\clinic.mdb" & ";Persist Security Info=False"
Adodc1.RecordSource = "select * from inventory order by Expyear asc"
Adodc1.Refresh
Adodc1.Refresh
End sub
You need to loop through all of the records in your recordset. Currently, you're operating on the FIRST record only.
Do Until Adodc1.Recordset.EOF
' Assign values to textboxes, test date, etc.
' Fetch the next record...
Adodc1.Recordset.MoveNext
Loop
Bond is correct, you need to iterate over your recordset to display the message for each record that is expired.
Private Sub Form_Activate()
Dim expirationdate As Date
On Error Resume Next '<-- this is going to cause a problem if you never check for errors
Adodc1.Recordset.MoveFirst 'make sure the control is positioned on the first record
Do While Adodc1.Recordset.EOF = False 'loop over all of the records
With Main
.Text4.Text = Adodc1.Recordset.Fields("MedicineName")
.Text1.Text = Adodc1.Recordset.Fields("genericname")
.Text3.Text = Adodc1.Recordset.Fields("StockQuantity")
.Combo3 = Adodc1.Recordset.Fields("Expmonth")
.Combo4 = Adodc1.Recordset.Fields("Expday")
.Combo5 = Adodc1.Recordset.Fields("Expyear")
End With
expirationdate = CDate(Combo3 & "/" & Combo4 & "/" & Combo5)
datepicker.Value = Format(Now, "MMM-DD-yyyy")
If datepicker > expirationdate Then
MsgBox Text4.Text & " is expired ", vbExclamation, "Warning!"
If MsgBox("Do you want to dispose " & Text4 & "?", vbQuestion + vbYesNo, "Message") = vbYes Then
Adodc1.Recordset.Delete
End If
End If
Adodc1.Recordset.MoveNext
Loop
End Sub

Duplicate error in current scope vb 6

Can someone help me. I'm trying to display an alert msgbox with two different recordset in one form so whenever there is an expired medicine it will both display and alert at the same time. But it gives me an error "Duplicate error in current scope"
In this line
Dim expirationdate As Date
Do While Not Adodc2.Recordset.EOF = True
'----------'
Private Sub Form_Activate()
Dim expirationdate As Date
Me.AutoRedraw = True
Adodc1.Recordset.MoveFirst
Do While Not Adodc1.Recordset.EOF = True
With Main
.Text4.Text = "" & Adodc1.Recordset.Fields("MedicineName")
.Text1.Text = Adodc1.Recordset.Fields("genericname")
.Text3.Text = Adodc1.Recordset.Fields("StockQuantity")
.Combo3.Text = Adodc1.Recordset.Fields("Expmonth")
.Combo4.Text = Adodc1.Recordset.Fields("Expday")
.Combo5.Text = Adodc1.Recordset.Fields("Expyear")
End With
expirationdate = CDate(Combo3 & "/" & Combo4 & "/" & Combo5)
datepicker.Value = Format(Now, "MMM-DD-yyyy")
If datepicker > expirationdate Then
MsgBox Text4.Text & " is Expired! ", vbExclamation, "Warning"
If MsgBox("Do you want to dispose " & Text4 & "?", vbQuestion + vbYesNo, "Message") = vbYes Then
Adodc1.Recordset.Delete
Else
Exit Sub
End If
End If
Adodc1.Recordset.MoveNext
Loop
'________________'
Dim expirationdate As Date
Me.AutoRedraw = True
Adodc2.Recordset.MoveFirst
Do While Not Adodc2.Recordset.EOF = True
With Main
.Text10 = Adodc2.Recordset.Fields("roomno")
.Text11 = "" & Adodc2.Recordset.Fields("MedicineName")
.Text2 = Adodc2.Recordset.Fields("GenericName")
.Text12.Text = Adodc2.Recordset.Fields("StockQuantity")
.Combo10 = Adodc2.Recordset.Fields("Expmonth")
.Combo11 = Adodc2.Recordset.Fields("Expday")
.Combo12 = Adodc2.Recordset.Fields("Expyear")
End With
expirationdate = CDate(Combo10 & "/" & Combo11 & "/" & Combo12)
datepicker2.Value = Format(Now, "MMM-DD-yyyy")
If datepicker2 < expirationdate Then
MsgBox "OK!", vbInformation, "Working"
Else
MsgBox "Medicine Expired!.", vbExclamation, " Warning!"
If MsgBox("Do you want to delete " & Text11 & "?", vbQuestion + vbYesNo, "Message") = vbYes Then
Adodc2.Recordset.Delete
Exit Sub
End If
End If
Adodc2.Recordset.MoveNext
Loop
End Sub
Try this. You are sometimes relying on the default properties of your controls. This is generally bad, so I added the properties. I also removed the Exit Sub line. If the user clicks No you don't want to exit the sub, you want to continue looping through the Adodc2 Recordset.
Me.AutoRedraw = True
Adodc2.Recordset.MoveFirst
Do While Not Adodc2.Recordset.EOF = True
With Main
.Text10.Text = Adodc2.Recordset.Fields("roomno")
.Text11.Text = "" & Adodc2.Recordset.Fields("MedicineName")
.Text2.Text = Adodc2.Recordset.Fields("GenericName")
.Text12.Text = Adodc2.Recordset.Fields("StockQuantity")
.Combo10.Text = Adodc2.Recordset.Fields("Expmonth")
.Combo11.Text = Adodc2.Recordset.Fields("Expday")
.Combo12.Text = Adodc2.Recordset.Fields("Expyear")
End With
expirationdate = CDate(Combo10.Text & "/" & Combo11.Text & "/" & Combo12.Text)
datepicker2.Value = Format(Now, "MMM-DD-yyyy")
If datepicker2.Value < expirationdate Then
MsgBox "OK!", vbInformation, "Working"
Else
MsgBox "Medicine Expired!.", vbExclamation, " Warning!"
If MsgBox("Do you want to delete " & Text11.Text & "?", vbQuestion + vbYesNo, "Message") = vbYes Then
Adodc2.Recordset.Delete
End If
End If
Adodc2.Recordset.MoveNext
Loop

Need Visual Studio macro to add banner to all C# files

Can someone post a Visual Studio macro which goes through all C# source files in a project and adds a file banner? Extra credit if it works for any type of source file (.cs, .xaml, etc).
Here you go, I provide an example for .cs and .vb but shouldn't be hard for you to adjust it to your other file type needs: Edited to recursively add header to sub-folders
Sub IterateFiles()
Dim solution As Solution = DTE.Solution
For Each prj As Project In solution.Projects
IterateProjectFiles(prj.ProjectItems)
Next
End Sub
Private Sub IterateProjectFiles(ByVal prjItms As ProjectItems)
For Each file As ProjectItem In prjItms
If file.SubProject IsNot Nothing Then
AddHeaderToItem(file)
IterateProjectFiles(file.ProjectItems)
ElseIf file.ProjectItems IsNot Nothing AndAlso file.ProjectItems.Count > 0 Then
AddHeaderToItem(file)
IterateProjectFiles(file.ProjectItems)
Else
AddHeaderToItem(file)
End If
Next
End Sub
Private Sub AddHeaderToItem(ByVal file As ProjectItem)
DTE.ExecuteCommand("View.SolutionExplorer")
If file.Name.EndsWith(".cs") OrElse file.Name.EndsWith(".vb") Then
file.Open()
file.Document.Activate()
AddHeader()
file.Document.Save()
file.Document.Close()
End If
End Sub
Private Sub AddHeader()
Dim cmtHeader As String = "{0} First Line"
Dim cmtCopyright As String = "{0} Copyright 2008"
Dim cmtFooter As String = "{0} Footer Line"
Dim cmt As String
Select Case DTE.ActiveDocument.Language
Case "CSharp"
cmt = "//"
Case "Basic"
cmt = "'"
End Select
DTE.UndoContext.Open("Header Comment")
Dim ts As TextSelection = CType(DTE.ActiveDocument.Selection, TextSelection)
ts.StartOfDocument()
ts.Text = String.Format(cmtHeader, cmt)
ts.NewLine()
ts.Text = String.Format(cmtCopyright, cmt)
ts.NewLine()
ts.Text = String.Format(cmtFooter, cmt)
ts.NewLine()
DTE.UndoContext.Close()
End Sub
Visual Studio macro to add file headers
Here is the jist of it. No, I have not debugged this, that is an excercise for the reader. And, this is done off the top of my head. (Except the File commenter...That's a real Macro that I use).
function CommentAllFiles
option explicit
Dim ActiveProjectFullName
Dim dte80 As EnvDTE80.Solution2
ActiveProjectFullName = dte80.Projects.Item(0).FullName
If ActiveProjectFullName = "" Then
MsgBox("No project loaded!")
Exit Sub
End If
Err.Number = 0
doc.Open(ActiveProjectFullName, "Text", True)
If Err.Number <> 0 Then
MsgBox("Open " + ActiveProjectFullName + " failed: " & Hex(Err.Number))
Exit Sub
End If
ActiveDocument.Goto(1, 1, vsMovementOptions.vsMovementOptionsMove)
' Build search string
Dim SearchString
Dim vsFindOptionsValue As Integer
SearchString = "^SOURCE=.*" + dn + "$"
while ActiveDocument.Selection.FindText(SearchString, vsFindOptions.vsFindOptionsFromStart + vsFindOptions.vsFindOptionsRegularExpression)
Dim TheFile
TheFile = ActiveDocument.Selection.Text
TheFile = Mid(TheFile, 8)
doc.Open(TheFile)
wend
ActiveDocument.Close()
end function
Tried and true "Flower Box" adder:
Function IsClassDef()
Dim ColNum
Dim LineNum
Dim sText
sText = ActiveDocument.Selection.ToString()
If sText = "" Then
'ActiveDocument.Selection.WordRight(dsExtend)
'sText = ActiveDocument.Selection
'sText = ucase(trim(sText))
End If
If (sText = "CLASS") Then
IsClassDef = True
Else
IsClassDef = False
End If
End Function
Sub AddCommentBlock()
'DESCRIPTION: Add Commecnt block to header, CPP files and Class Defs
AddCPPFileDesc()
End Sub
Sub AddCPPFileDesc()
'DESCRIPTION: Add File desc block to the top of a CPP file
Dim selection As EnvDTE.TextSelection
ActiveDocument.Selection.StartOfLine()
Dim editPoint As EnvDTE.EditPoint
selection = DTE.ActiveDocument.Selection()
editPoint = selection.TopPoint.CreateEditPoint()
Dim bOk, sExt, IsCpp, IsHdr, sHeader, IsCSharp
bOk = True
IsCpp = False
IsCSharp = False
If ActiveDocument.Selection.CurrentLine > 10 Then
If MsgBox("You are not at the top of the file. Are you sure you want to continue?", vbYesNo + vbDefaultButton2) = vbNo Then
bOk = False
End If
End If
If (bOk) Then
sExt = ucase(right(ActiveDocument.Name, 4))
IsCpp = sExt = ".CPP"
IsHdr = Right(sExt, 2) = ".H"
IsCSharp = sExt = ".CS"
If (IsCpp) Then
sHeader = left(ActiveDocument.Name, len(ActiveDocument.Name) - 3) + "h"
FileDescTopBlock(1)
editPoint.Insert("#include " + Chr(34) + "StdAfx.h" + Chr(34) + vbLf)
editPoint.Insert("#include " + Chr(34) + sHeader + Chr(34) + vbLf)
ElseIf (IsCSharp) Then
FileDescTopBlock(1)
Else
If IsHdr Then
'If IsCLassDef() Then
'AddClassDef()
'Else
AddHeaderFileDesc()
'End If
Else
FileDescTopBlock(1)
End If
End If
End If
End Sub
Sub AddHeaderFileDesc()
FileDescTopBlock(0)
Dim selection As EnvDTE.TextSelection
ActiveDocument.Selection.StartOfLine()
Dim editPoint As EnvDTE.EditPoint
selection = DTE.ActiveDocument.Selection()
editPoint = selection.TopPoint.CreateEditPoint()
editPoint.Insert("#pragma once" + vbLf)
End Sub
Sub FileDescTopBlock(ByVal HasRevHistory)
'DESCRIPTION: Add File desc block to the top of a CPP file
Dim selection As EnvDTE.TextSelection
ActiveDocument.Selection.StartOfLine()
ActiveDocument.Selection.EndOfLine()
Dim sComment
sComment = ActiveDocument.Selection.ToString()
If Left(sComment, 2) = "//" Then
ActiveDocument.Selection.Delete()
sComment = LTrim(Mid(sComment, 3))
Else
sComment = ""
End If
Dim sLineBreak
Dim sFileName
Dim sBlock
sLineBreak = "////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////"
sFileName = ActiveDocument.Name
ActiveDocument.Selection.StartOfDocument()
sBlock = sLineBreak & vbLf & _
"// File : " & sFileName & vbLf & _
"// Author : Larry Frieson" & vbLf & _
"// Desc : " & sComment & vbLf & _
"// Date : " & CStr(Now.Date()) & vbLf & _
"//" & vbLf & _
"// Copyright © 20" + Right(CStr(Now.Year.ToString()), 2) + " MLinks Technologies. All rights reserved" + vbLf
If (HasRevHistory > 0) Then
sBlock = sBlock & _
"//" & vbLf & _
"// Revision History: " & vbLf & _
"// " & CStr(Now) & " created." & vbLf & _
"// " & vbLf
End If
sBlock = sBlock + sLineBreak + vbLf
Dim editPoint As EnvDTE.EditPoint
selection = DTE.ActiveDocument.Selection()
editPoint = selection.TopPoint.CreateEditPoint()
editPoint.Insert(sBlock)
End Sub
Hope this helps, or at least gives you some ideas. Again, I didn't test/debug the "source file looper", I figure you can handle that.
Larry

Resources