Tuesday, September 19, 2006

Add an error handler routine to your Code

It is important to catch and handle errors on your programs. Yes we are all perfect and our systems do not generate errors, but our users are not perfect and since they do not know what they are doing, we should provide them with some tools to tell us what they did wrong.

This is an VB6 error handler routine

Public Sub HandleError(ErrNumber As Double, Description As String, CurrentModule As String, CurrentControl As String, CurrentRoutine As String)

On Error GoTo OOPS

'Writes error messages to a log file and displays a message

Dim ErrorMsg As String
Dim FileNum As Integer
Dim fileName As String

'Parse the error message
ErrorMsg = "Error : " & Trim(Str(ErrNumber)) & " " & Description & " at " & CurrentModule

If Len(Trim(CurrentControl)) > 0 Then ErrorMsg = ErrorMsg & "." & CurrentControl
If Len(Trim(CurrentRoutine)) > 0 Then ErrorMsg = ErrorMsg & "." & CurrentRoutine

'Display a message box
MsgBox ErrorMsg

'Save the error to a file so you can track errors
FileNum = FreeFile

fileName = App.Path & "\" & App.EXEName & ".err"

Open fileName For Append As #FileNum
Print #FileNum, ErrorMsg
Close #FileNum

ExitHere:
Exit Sub
OOPS:

MsgBox "Error : " & Err.Number & " " & Error$ & " at basGlobal.HandleError"
Resume ExitHere
End Sub



Assuming you want to add an error handler to one of your command buttons on a form:

Private Sub cmdAdd_Click()

On Error GoTo OOPS

Dim Type As String
Dim SQL As String

... your code here

ExitHere:
Exit Sub

OOPS:
HandleError Err, Error$, Me.Name, "cmdAdd", "Click"
Resume ExitHere

End Sub


You can get fancy and create an error handler class that can keep a collection of your errors, etc.
But most important keep it simple otherwise you will have to debug your error handler too.

My next posting will have an error handler class in .Net

Tuesday, September 12, 2006

Mapinfo Professional Geocode with Oracle

I have been working on project that integrates MapInfo, oracle and .Net web development.

How to import MapInfo tables to Oracle.

1.- In your oracle database, create a table space "MapInfo", user: MapInfo password:MapInfo

2.- Create a ODBC Machine Data source pointing to your Oracle Database "MapInfo Oracle" . Make sure the user name has access to your "MapInfo" Table space.

3.- Open MapInfo

4.- go to --> Tools --> Easy loader

5.- click on ODBC, select the machine source tab and select your "MapInfo Oracle" connection

Username: mapinfo
password: mapinfo

6.- Select the mapinfo source directory which would usually be at C:\Program Files\MapInfo Data\US_ExchangeInfoPlus or where ever map info was installed.

7.- You have to select one table at the time:

usnpaxx
uswcpt
uswcreg

on the server table select the appropiate processing option to create the table, append or replace.

8.- Click on update.

Your Oracle database will be updated with MapInfo tables.