Debugging AJAX

12. December 2007 05:00 by Mrojas in General  //  Tags: , , ,   //   Comments (0)
AJAX applications are great
Their coolness factor is high, and your clients
will be trilled by the new interactivity of your pages
But as a developer when you have a problem with
AJAX it could be hard to track. Because there is
a lot going on behind the scenes
Some of our costumers migrate their ASP applications to
to ASP.NET and it's natural that they want
some AJAX in it.
So I found a GREAT GREAT application for AJAX debugging
It's called fiddler. I cannot describe it all for you so go its site and watch the videos
The tool is just amazing :)
It really can see everything that the browser
receives and sends and more.
A definitive must Fiddler

Track Changes in VSS (Visual Source Safe)

24. October 2007 06:18 by Mrojas in General  //  Tags: , , , , ,   //   Comments (0)

MS VSS (Visual SourceSafe) is not really my preferred Source Control application, but
sometimes in your company that is what is available and you need to used it to have
at least some versioning of the code.

But haven't you had a situation where last week everything worked and
now everything is broken. And now is up to you to determine what went
wrong? I have it all the time.
 

VSS have some search tools but I really do not enjoy using them.
The Code Project Site provides an excellent tool called VssReporter

Sample Image - VssReporter.jpg

Do take a look at it, it makes it more easy to track changes. :)

 

MAN for .NET

5. October 2007 03:32 by Mrojas in General  //  Tags: , , , ,   //   Comments (0)
Microsoft recently published the MTPS Content Service

In brief, the MTPS Content Services are a set of
web services for exposing the content in
Microsoft/TechNet Publishing System (MTPS).


And Craig Andera, has develop a swift nice tool
called msdnman that you use from the command line to
get information from the MSDN

Also I recommend you to see this cool video of a Human LCD that Hugo sent me

VB6 Printer Object and PrintForm migration

1. October 2007 10:55 by Mrojas in General  //  Tags: , , ,   //   Comments (0)

If you ever had any problems while migrating from VB6 Printer Object or the PrintForm functionality
we have goods news for you the Microsoft Visual Basic 2005 Power Pack 2.0.
Our version of the Visual Basic Companion already provides and extended migration of the Printer Object,
and we're now updating it to use this new implementation. This Printer Compatibility Library makes it a
breeze to migrate Printer Functionality.

This is the description of the PowerPack:

"The new Line and Shape controls included in this version of the Visual Basic 2005 Power Packs are
a set of three graphical controls that enable you to draw lines, ovals, and rectangles on forms and
containers at design time making it much easier to enhance the look of your user interface.
These new shape controls also provide events such as click and double-click allowing developers
to respond and interact with end users.

The Printer Compatibility Library allows projects that used the Printer and Printers Collection in Visual Basic 6.0
 to be upgraded without having to re-write your printing logic. By simply adding a reference to the library, declaring a
Printer and making a few minor syntax changes, your project will be able to print using the Printers collection
and Printer object as it did in Visual Basic 6.0. This version adds a new Write method to the Printer object which
allows you to print text without a forced carriage return similar to the semicolon syntax used by Print method in Visual Basic 6.0.

The PrintForm component is designed to bring back the ability to easily print a Windows Form.
With this the new PrintForm component you can once again layout the Windows Form exactly as
you want it and allow your users to print the form as a quick report."

You can download the PowerPack from here

NOTE: there's is another link that only includes the Printer Library but MS recommends to download the PowerPack
because minor upgrades and fixes will be done on the PowerPack distribution

 

Remove unused references VB6

28. September 2007 11:33 by Mrojas in General  //  Tags: , , , , , , , ,   //   Comments (0)

As part of the VB Companion Development group, my day to day includes
migrating several project from different clients, to develop custom mappings
and custom functionality for their migration needs or to add new features
for the next VB Companion version.

A long part of the initialization in the migration process consists of the load and
analysis of the COM references indicated in the .VBP project file.

Sometimes I have notice that there are several references that are never used.
Removing these references will provide a great save in time because the migration will
not have to incur in any time for TypeLib and TypeInfo extraction.

I look for a tool that let me get rid of the VB6 unused referencences but I found none.
So I decided to create one myself. And I created the VB6 Project References Cleaner Addin

The concept of the tool is simple, someone from a group posted the idea I just implemented.
The addin goes thru all the references and one by one tries to remove it.
And then compiles the project. It the project compiles,then the reference was not neccesary.
If you mark the remove option the tool will remove the references for you.

This tool will NOT SAVE the project file. You decide if you what to save it.

I'm attaching the source code and the dll. To used it just take the VB6References.dll and run:

  regsvr32 VB6References.dll
After that the tool will appear in the Addins menu in VB6 SOURCE CODE and BINARIES

 

 

 

VB6 API calls to .NET

27. September 2007 10:06 by Mrojas in General  //  Tags: , , , ,   //   Comments (0)
Every SERIOUS VB6 application, ended up requiring
that you import some functionality from the windows API or another DLL.
However if you were looking for a .NET equivalent and
google did not take you to the right page,
there is a document (a little old I might say) called
Microsoft Win32 to Microsoft .NET Framework API Map

I remember a couple of other pages that were even more complete,
but right know I can only remember http://pinvoke.net that gives some info about APIs

Twips and .NET

20. September 2007 04:46 by Mrojas in General  //  Tags: , , ,   //   Comments (0)

In the VB world previous to .NET a concept you probably had to deal with was TWIPS.

What were Twips? Well if you do not remember those happy VB6 times, let me refresh your memory:

Twips are screen-independent units to ensure that the proportion of screen elements are the same on all display systems.
A twip is defined as being 1/1440 of an inch.


A Pixel is a screen-dependent unit, standing for 'picture element'.
A pixel is a dot that represents the smallest graphical measurement on a screen.

In .NET everything is pixels. So if you migrated something from VB6 using the Upgrade Wizard you might found several expressions like:

VB6.TwipsToPixelsX(ctrl.Left)

or VB6.PixelsToTwipsY(ctrl.Height)

There is an X and a Y version of this function, because the conversion factor is not the same for both axis.

Sadly you can even found some expressions like:

VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(ctrl.Left))

In a strict sense there could be minor differences because of the conversion factors. But in it seams that things like that can be removed because all controls Bound properties like Left, Top, Bottom, Right are in pixels. So why will you convert your pixels units to Twips units to then convert them back to Pixels if they where already in Pixels????

Also you can find something like:

VB6.TwipsToPixelsX(ctrl.Left + ctrl.Width + 30) which should be something like:

ctrl.Left + ctrl.Width  + VB6.TwipsToPixelsX(30)

If you have an application migrated with the Upgrade Wizard you can use some regular expressions to improve those expressions. If the conversion is something like:

VB6.TwipsToPixelsY(VB6.PixelsToTwipsX(ctrl.Left)) then be careful because conversion factor might produce a different value, due to the change of axis.

 

 

jeje Or you can uset the VBCompanion, the extensible version of the Upgrade Wizard!!!

 

Casting in .NET

13. September 2007 04:20 by Mrojas in General  //  Tags: , , ,   //   Comments (0)

.NET has a more strict typing than VB6
So you must check in some circumstances if your object implements an interface or not.

So I had used the as and is operators in C# but I did not know how to do that.
I did I little research and I discovered some things about casting operators for VB.NET

 

Operator Example Observations
CType Dim testNumber As Long = 1000
' The following line of code sets testNewType to 1000.0.
Dim testNewType As Single = CType(testNumber, Single)
 
Throws InvalidCastException or OverflowException

It could be less eficient due to VB.Net helper routines.

This is a Narrowing and Widening operator.

It can be overloaded

Public Structure digit
Private dig As Byte
    Public Sub New(ByVal b As Byte)
        If (b OrElse b > 9) Then Throw New _
            System.ArgumentException("Argument outside range for Byte")
        Me.dig = b
    End Sub
    Public Shared Widening Operator CType(ByVal d As digit) As Byte
        Return d.dig
    End Operator
    Public Shared Narrowing Operator CType(ByVal b As Byte) As digit
        Return New digit(b)
    End Operator
End Structure
 

 

DirectCast Dim f As New System.Windows.Forms.Form
Dim c As System.Windows.Forms.Control
' The following conversion succeeds.
c = DirectCast(f, System.Windows.Forms.Control)
 
Throws InvalidCastException. Is more efficient than CType because it does not depend on the Visual Basic helper runtime functions. It can even detect some errors as invalid casts during compile time
 

However it requires a relationship of inheritance of implementation
For example:

Dim q As Object = 2.37
Dim i As Integer = CType(q, Integer)
' The following conversion fails at run time
Dim j As Integer = DirectCast(q, Integer)
 

The run-time type of q is Double. CType succeeds because Double can be converted to Integer. However, the first DirectCast fails at run time because the run-time type of Double has no inheritance relationship with Integer, even though a conversion exists
 

TryCast     Dim obj As MyType = TryCast(obj, MyType)
    If obj Is Nothing Then
      ' Object could not be cast
 
  Else
     ' Object was casted

   End If
Throws no exceptions.


All this information has been taken from the MSDN site. This is just a quick summary. For more information see:

Type Conversion Functions
Conversion Functions (Visual Basic)

Widening and Narrowing Conversions
Implicit and Explicit Conversions
 

Fixed Len Strings in Visual Basic

7. September 2007 09:34 by Mrojas in General  //  Tags: , , ,   //   Comments (0)

This is a nostalgic note. Someone asked me, "hey, how do you make a fixed len string in VB6?"
As the computer geek that I am, that the kind of questions I like to be able to answer.
These are important questions like all those questions from the 80's rally:

The name of all the original thundercats...
The planet where Luck Skywalker went to learn with Yoda...
Which Star Trek character appear in ALL the episodes (yes it is Spock, Kirk is not in all of them)
Well, the thing is to define a fixed len string in VB6 you do something like:


Dim aString As String * 10

If you do something like:

aString = "Mau" ' aString ==> "Mau "

That's all

Fixed length strings are automatically filled with spaces to pad them to their fixed-length. How do you get rid of the extra spaces? Duh!!! with RTrim$ don't you remember

When a variable like aString is declared, it will be filled with Null characters until it is used.

And yes functions (RTrim$, LTrim$, and Mid$) will not trim Null characters, so be sure to assign it with an empty string "" immediately.


Ahh! and by the way when you translate that to .NET, .NET does not have a fixed len string so the easiest thing to do is use:
Microsoft.VisualBasic.Compatibility.VB6.FixedLengthString.

[C#]

using Microsoft.VisualBasic.Compatibility;
...

void foo()

{

VB6.FixedLengthString aString = VB6.FixedLengthString(10, "Mau");

}

 

Migrating BANAMEX

7. September 2007 04:14 by Mrojas in General  //  Tags: ,   //   Comments (0)
Yesterday someone told me and I checked out El Financiero online. There's an article about Artinsoft there. If you don't know about us. We do Software Migration, and BANAMEX decided to upgrade their platform from VB6 to .NET. It's a huge amount of code, and a very interesting project :) See: Article

DoEvents?? in .NET

7. May 2007 08:51 by Mrojas in General  //  Tags: , ,   //   Comments (0)
This is small Example. I had a POS Application in VB6 with this code. Me.EpsonFPHostControl1.SendCommand While EpsonFPHostControl1.State = EFP_S_Busy DoEvents Wend This code is almost the same in VB.NET Me.AxEpsonFPHostControl1.SendCommand() While AxEpsonFPHostControl1.CtlState = EpsonFPHostControlX.TxFiscalState.EFP_S_Busy Application.DoEvents() End While

Migration of VB6 POS

7. May 2007 08:46 by Mrojas in General  //  Tags: , , , , , ,   //   Comments (0)

POS (Point of Sale) software is everywhere. Whether you're at a Bar, at Denny's, Pizza Hut, BK or at the Duty Free. It is maybe one of the software's more commonly used. A POS system is generally simple. It manages a basic inventory, registers sales, and somethings manages credit card payments. Obviously there are far more complex POS systems. A lot of POS systems where programmed in VB6. But as you know VB6 language (and I'm not discussing the reasons here) is now a dead language. A lot of customers do not want to buy VB6 applications, even if they get the job done. So it's time to move on. This is the First of a series of posts around issues migrating VB6 POS applications. If you have any comments just send them now!

More Color to your Traces!

29. May 2006 08:37 by Mrojas in General  //  Tags: , ,   //   Comments (0)

Most Visual Basic programmers are familiar with using Debug.Print to follow their code's execution. The .NET environment introduces Tracing falicities that allows you to send messages to files or the console.

However the console output could be improved by using colors to highlight certain events. 
I developed a simple ColorTraceListener that can be used either with the My.Application.Log object or the Trace.TraceXXX methods. 
I first thing to do is create a ClassLibrary. It will be called ColorTraceListener. Add a ColorTraceListener.cs File and fill it with the following code:
 

Imports System

Imports System.Diagnostics

Imports System.Globalization

Imports System.Text

Imports System.Runtime.InteropServices 

Public Class ColorTraceListener

    Inherits ConsoleTraceListener

    Public Sub New()

        MyBase.New()

    End Sub 

    Public Sub New(ByVal useErrorStream As Boolean)

        MyBase.New(useErrorStream)

    End Sub 

    Friend Function IsEnabled(ByVal opts As TraceOptions) As Boolean

        Return ((opts And Me.TraceOutputOptions) <> TraceOptions.None)

    End Function 
 
 

    False)> _

    Public Overrides Sub TraceData(ByVal eventCache As TraceEventCache, ByVal source As String, ByVal eventType As TraceEventType, ByVal id As Integer, ByVal data As Object)

        If ((Me.Filter Is Nothing) OrElse Me.Filter.ShouldTrace(eventCache, source, eventType, id, Nothing, Nothing, Nothing, data)) Then

            Me.WriteHeader(source, eventType, id)

            Dim text1 As String = String.Empty

            If (Not data Is Nothing) Then

                text1 = data.ToString

            End If

            Me.WriteLine(text1)

            Me.WriteFooter(eventCache)

        End If

    End Sub 

    False)> _

    Public Overrides Sub TraceData(ByVal eventCache As TraceEventCache, ByVal source As String, ByVal eventType As TraceEventType, ByVal id As Integer, ByVal ParamArray data As Object())

        If ((Me.Filter Is Nothing) OrElse Me.Filter.ShouldTrace(eventCache, source, eventType, id, Nothing, Nothing, Nothing, data)) Then

            Me.WriteHeader(source, eventType, id)

            Dim builder1 As New StringBuilder

            If (Not data Is Nothing) Then

                Dim num1 As Integer = 0

                Do While (num1 < data.Length)

                    If (num1 <> 0) Then

                        builder1.Append(", ")

                    End If

                    If (Not data(num1) Is Nothing) Then

                        builder1.Append(data(num1).ToString)

                    End If

                    num1 += 1

                Loop

            End If

            Me.WriteLine(builder1.ToString)

            Me.WriteFooter(eventCache)

        End If

    End Sub 
 

    False)> _

    Public Overrides Sub TraceEvent(ByVal eventCache As TraceEventCache, ByVal source As String, ByVal eventType As TraceEventType, ByVal id As Integer, ByVal message As String)

        If ((Me.Filter Is Nothing) OrElse Me.Filter.ShouldTrace(eventCache, source, eventType, id, message, Nothing, Nothing, Nothing)) Then

            Me.WriteHeader(source, eventType, id)

            Me.WriteLine(message)

            Me.WriteFooter(eventCache)

        End If

    End Sub 
 

    False)> _

    Public Overrides Sub TraceEvent(ByVal eventCache As TraceEventCache, ByVal source As String, ByVal eventType As TraceEventType, ByVal id As Integer, ByVal format As String, ByVal ParamArray args As Object())

        If ((Me.Filter Is Nothing) OrElse Me.Filter.ShouldTrace(eventCache, source, eventType, id, format, args, Nothing, Nothing)) Then

            Me.WriteHeader(source, eventType, id)

            If (Not args Is Nothing) Then

                Me.WriteLine(String.Format(CultureInfo.InvariantCulture, format, args))

            Else

                Me.WriteLine(format)

            End If

            Me.WriteFooter(eventCache)

        End If

    End Sub 
 
 
 
 

    Private Sub WriteFooter(ByVal eventCache As TraceEventCache)

        If (Not eventCache Is Nothing) Then

            Me.IndentLevel += 1

            If Me.IsEnabled(TraceOptions.ProcessId) Then

                Me.WriteLine(("ProcessId=" & eventCache.ProcessId))

            End If

            If Me.IsEnabled(TraceOptions.LogicalOperationStack) Then

                Me.Write("LogicalOperationStack=")

                Dim stack1 As Stack = eventCache.LogicalOperationStack

                Dim flag1 As Boolean = True

                Dim obj1 As Object

                For Each obj1 In stack1

                    If Not flag1 Then

                        Me.Write(", ")

                    Else

                        flag1 = False

                    End If

                    Me.Write(obj1.ToString)

                Next

                Me.WriteLine(String.Empty)

            End If

            If Me.IsEnabled(TraceOptions.ThreadId) Then

                Me.WriteLine(("ThreadId=" & eventCache.ThreadId))

            End If

            If Me.IsEnabled(TraceOptions.DateTime) Then

                Me.WriteLine(("DateTime=" & eventCache.DateTime.ToString("o", CultureInfo.InvariantCulture)))

            End If

            If Me.IsEnabled(TraceOptions.Timestamp) Then

                Me.WriteLine(("Timestamp=" & eventCache.Timestamp))

            End If

            If Me.IsEnabled(TraceOptions.Callstack) Then

                Me.WriteLine(("Callstack=" & eventCache.Callstack))

            End If

            Me.IndentLevel -= 1

        End If

    End Sub 

    Private Sub WriteHeader(ByVal source As String, ByVal eventType As TraceEventType, ByVal id As Integer)

        Dim oldColor As ConsoleColor = Console.ForegroundColor

        Select Case eventType

            Case TraceEventType.Error

                Console.ForegroundColor = ConsoleColor.Red

            Case TraceEventType.Critical

                Console.ForegroundColor = ConsoleColor.Magenta

            Case TraceEventType.Information

                Console.ForegroundColor = ConsoleColor.White

                'Case TraceEventType.Resume

                'Case TraceEventType.Start

                'Case TraceEventType.Suspend

                'Case(TraceEventType.Transfer)

                'Case TraceEventType.Verbose

            Case TraceEventType.Warning

                Console.ForegroundColor = ConsoleColor.Yellow

        End Select

        Me.Write(String.Format(CultureInfo.InvariantCulture, "{0} {1}:", New Object() {source, eventType.ToString}))

        Console.ForegroundColor = oldColor

        Me.Write(String.Format(CultureInfo.InvariantCulture, " {0} : ", New Object() {id.ToString(CultureInfo.InvariantCulture)}))

    End Sub

End Class 

The methods that handle the headers in the TextWriteListener are private (WriteHeader and WriterFooter) so we need to override them. Reflector comes very handy in this cases. 

No to test it Create a Vb Console Application: 

Module Module1 

    Sub Main() 
 

        My.Application.Log.WriteEntry("Error!", TraceEventType.Error)

        My.Application.Log.WriteEntry("Warning", TraceEventType.Warning)

        My.Application.Log.WriteEntry("Info", TraceEventType.Information)

        My.Application.Log.WriteEntry("Info", TraceEventType.Critical) 

        Trace.TraceError("An Error Happened!")

        Trace.TraceInformation("Just letting you know!")

        Trace.TraceWarning("Watch the road ahead") 

    End Sub 

End Module 

And use a simple configuration file like the following: 

xml version="1.0" encoding="utf-8" ?>

<configuration>

    <system.diagnostics>

      <trace autoflush="true">

        <listeners>

          <add name="ColorLog" />

        listeners>

      trace>

        <sources>

            This section defines the logging configuration for My.Application.Log -->

            <source name="DefaultSource" switchName="DefaultSwitch">

                <listeners>

                    <add name="ColorLog"/>

                listeners>

            source>

        sources>

        <switches>

            <add name="DefaultSwitch" value="Verbose" />

        switches>

       <sharedListeners>

          <add name="ColorLog" type="Mrojas.ColorTraceListener, ColorTraceListener" />

        sharedListeners>

    system.diagnostics>

configuration> 
 

Categories