One feller's views on the state of everyday computer science & its application (and now, OTHER STUFF) who isn't rich enough to shell out for www.myfreakinfirst-andlast-name.com
Using 89% of the same design the blog had in 2001.
FOR ENTERTAINMENT PURPOSES ONLY!!!
Back-up your data and, when you bike,
always wear white.
As an Amazon Associate, I earn from qualifying purchases. Affiliate links in green.
Friday, March 21, 2003
I've always wondered how to make one of those neat little plug-ins for Visual Basic 6.0 that insert code into the file you're working on. I'm no master, but I finally started checking about and have it proof-of-concepted, at least.
In all of my vb apps, I like to use a separate module to handle errors, in case I want to start changing the way they're handled. By having it pulled out, I've got one place that I have to alter to make error handling change globally. But scrawling that error handling crap the same way every time I'd add a method drove me crazy.
Enter the "AddIn" project in VB6. When you start a new project, select "AddIn". Add a button called cmdInsertText (for this example). Insert this code:
' Insert text into code module.
Private Sub cmdInsertText_Click()
Dim vbComp As VBComponent
Dim strToInsert As String
Set vbComp = VBInstance.ActiveVBProject.VBE.SelectedVBComponent
vbComp.CodeModule.AddFromString strToInsert
End Sub
... and then build it. Voila. It's in the Add-Ins menu for all your other VB projects, and it'll insert a new sub at the top of your current file. Woohoo!
Needs some extra stuff to be really useful, but a decent start. Got most of what I needed from the VB6 help topic "Manipulating Code with Add-Ins" and F2.
posted by ruffin
at 3/21/2003 02:44:00 PM
The postings on this site are [usually] my own and do not necessarily reflect the views of any employer, past or present, or other entity. About Our Author