Event Logging in Visual Basic 6

This is old-school, but you may be on a project requiring you to work in VB6 (Jay). You can log events to the NT event log by invoking the LogEvent method on the App object.

VB6 - LogEvent Method
http://msdn.microsoft.com/library/en-us/vb98/html/vbmthLogEventMethod.asp

It turns out you can only log events from a compiled application. It won't work if you're running your application from the VB6 environment for debugging purposes. The following article suggests creating an ActiveX DLL to hold the logging function.

INFO: App.LogEvent Only Logs in Compiled Applications
http://support.microsoft.com/default.aspx?scid=kb;en-us;161306

However, this won't work in ASP without some Registry modifications. I don't know about ASP.NET, but again this is old-school.

PRB: App.Logevent Does Not Work in Components that You Call from ASP on Windows 2000
http://support.microsoft.com/default.aspx?scid=kb;en-us;251264

There is a lengthy article devoted to ASP logging.

How To Log Events from Active Server Pages
http://support.microsoft.com/default.aspx?scid=kb;en-us;301309

You can also log events to your own file by invoking the StartLogging method on the App object.

VB6 - StartLogging Method
http://msdn.microsoft.com/library/en-us/vb98/html/vbmthstartloggingmethod.asp

Event logging is available in several contexts. I'm sure everyone knows how to do it in .NET (and now from VB6), but you can also do it from script.

Windows Script Host - LogEvent Method
http://msdn.microsoft.com/library/en-us/script56/html/wsmthlogevent.asp

Here is the search I used to find out all of this information.

MSDN search for LogEvent
http://search.microsoft.com/search/results.aspx?View=msdn&st=a&qu=LogEvent&c=0&s=1

posted by Chris with 0 Comments

Change the font size in VS.NET

I haven't tried it yet, but here is a utility to easily change the font size in VS.NET. This is great for presentations, such as the VTB (where someone mentioned wanting such a utility).

http://www.gotdotnet.com/workspaces/workspace.aspx?id=ab7b5f27-f844-43ab-95bd-0b0b2a707d62

posted by Chris with 5 Comments

Getting Computer and User Information in Script

You can use the WScript.Network component to get some computer and user information. Here's an example script that displays this information.

var x= new ActiveXObject("WScript.Network");
WScript.Echo(x.ComputerName);
WScript.Echo(x.UserDomain);
WScript.Echo(x.UserName);

This component also some methods to manage network drives and printers. See http://msdn.microsoft.com/library/en-us/script56/html/wsObjWshNetwork.asp for this and many other objects useful in scripting, such as the WScript.Shell component for accessing the environment and Registry and even sending keystrokes to other applications.

posted by Chris with 0 Comments

Converting Hexadecimal Strings to Numbers

It's easy enough to convert numbers and strings back and forth if they're decimal, but you have to do a little work if you want to use hexadecimal. To convert an integer to a hexadecimal string, use

i.ToString("x");

To convert a hexadecimal string to an integer, use

int.Parse(s, System.Globalization.NumberStyles.AllowHexSpecifier);

In VB.NET, you can use the options above or VB-specific expressions. To convert an integer to a hexadecimal string, use

Hex(i)

To convert a hexadecimal string to an integer, use

CInt("&H" & s)

It also works with the other VB converters (e.g. CLng and CSng).

posted by Chris with 0 Comments

Outlook Command-line Switches

Outlook supports several command-line switches you can use to restore Outlook settings to their factory defaults, solve problems, or even create new items. If you search Google for "Outlook command-line switches" you'll receive several hits for many versions of Outlook. Here are just a few.

MCSEworld
Outlook Tips
Microsoft Exchange Server

The definitive page is at office.microsoft.com, of course.

I think the most useful ones are those that reset some aspect of Outlook in case it decides to take a left turn into the weeds.

/CleanClientRules Starts Outlook and deletes client-based rules. For non-Exchange users.
/CleanFinders Sets Outlook 2003 Search Folders back to the default state (deletes custom Search Folders).
/CleanFreeBusy Cleans and regenerates free/busy information.
/CleanProfile Removes invalid profile keys and recreates default Registry keys where applicable.
/CleanPST Launches Outlook with a clean Personal Folders file (.pst).
/CleanReminders Cleans and regenerates reminders.
/CleanRules Starts Outlook and deletes client- and server-based rules.
/CleanSchedPlus Deletes all Schedule+ data (free/busy, permissions, and .cal file) from the server.
/CleanServerRules Starts Outlook and deletes server-based rules. Used only with Exchange server accounts.
/CleanSniff Deletes duplicate reminder messages.
/CleanViews Restores default views.
/FirstRun Starts Outlook as if it were run for the first time.
/ResetFolderNames Resets the language of the default folders to the language of the Outlook client.
/ResetFolders Restores missing folders for the default delivery location.
/ResetNavPane Clears and regenerates the Navigation Pane for the current profile.
/ResetOutlookBar Rebuilds the Outlook Bar.
/ResetWunderBar Rebuilds the new Outlook Control Bar in Outlook 2003.
/Sniff Starts Outlook and forces a detection of new meeting requests in the Inbox, and then adds them to the calendar.

I wonder what you can do with /altvba otmfilename?

posted by Chris with 1 Comments

SQL Cursors

Cursors allow you to loop through a result set in SQL. Use them sparingly since they consume significant resources. Here is a stored procedure that resets all of the clocks in your house (assuming you keep your clocks in SQL).

CREATE PROCEDURE dbo.ResetAllClocks
AS

SET NOCOUNT ON

DECLARE @ClockID int

DECLARE ClockCursor CURSOR FAST_FORWARD FOR
SELECT
ClockID FROM Clocks

OPEN
ClockCursor

FETCH NEXT FROM ClockCursor INTO @ClockID

WHILE @@FETCH_STATUS = 0
BEGIN EXECUTE ResetOneClock @ClockID

FETCH NEXT FROM ClockCursor INTO @ClockID
END

CLOSE ClockCursor
DEALLOCATE ClockCursor

You may also specify several cursor options. For instance, the FAST_FORWARD keyword (in bold above) enables SQL Server to optimize the cursor since it knows you only want a read-only, forward-only cursor. If you want to move through the result set forwards and backwards, specify the SCROLL keyword instead. If you want to add or remove rows to the tables involved in the cursor without affecting the cursor, use the STATIC keyword. There are several more keywords to control scope, locking, and type checking. It's also possible to use a cursor to update the underlying tables. See SQL Server Books Online and index DECLARE CURSOR for more information.

posted by Chris with 0 Comments

Google Search Tips

Here are the Google search tips Isela sent a while ago. Now that they're in the devblogs, you'll never lose them. You can always search for these search tips.

  1. Use the Google Toolbar. It's available at toolbar.google.com.
  2. Use quotation marks to enclose strings that contain spaces so Google doesn't look for the words individually.
  3. Use the plus symbol (+) before a word to force Google to include a word in a search it normally excludes, such as common words.
  4. Use the minus symbol (-) before a word to return pages not containing that word.
  5. Use the tilde (~) before a word to search for synonyms of that word.
  6. Use the intitle keyword before a word to force Google to search only in the titles of pages for that word.
  7. Use the intext keyword before a word to force Google to ignore the titles of pages when searching for that word.
  8. Use the site keyword followed by a domain to force Google to search only the site at that domain.
  9. Use Google's Preferences found at www.google.com/preferences. For instance, you can restrict Google to return pages in a specific language or tell Google you want results in a new window.
  10. Use Google Groups found on the Groups tab on their main page. This will search news groups where people often ask questions to problems and receive answers.

Here's an example that searches only www.snpp.com (the Springfield Nuclear Power Plant, a Simpsons site) for Homer, but not Marge, including the word “the” for anything to do with beer.

site:www.snpp.com Homer -Marge +the ~beer

posted by Chris with 1 Comments