ArtinSoft's Blogs

Software Migration Experts
Welcome to ArtinSoft's Blogs Sign in | Join | Help
in Search

Mauricio Rojas Blog

September 2007 - Posts

  • IE7 Print shrink to fit problem

    IE7 has an interesting bug...
    Someone decided to change the printing default
    to "Shrink to Fit".This is supposed to be good
    because it will make printing of web pages better
    but it affects several applications develop for
    IE, for example if you are using the Web Access
    to your Exchange server, or if you have an application
    that prints on a page that is not a letter size page


    Well a guy from a forum found an excellent solution.

    The only problem is that he refers a hot fix,
    but if you have problems with that hotfix, then
    do the following:

    1. Go to windowsupdate.microsoft.com

    2. Make sure you have the following updates:

    ** Security Update for Internet Explorer 7 for Windows XP (KB938127)
    ** Cumulative Security Update for Internet Explorer 7 for Windows XP (KB937143)

    And then run the following in the command prompt:
    reg add "HKLM\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_STF_Scale_Min" /v iexplore.exe /t REG_DWORD /d 100 /f
    
  • Remove unused references VB6

    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

    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
  • Coldfusion8 html cfgrid problem

    We had a problem with a cfgrid
    Coldfusion8 introduces an HTML cfgrid that is AWESOME!!!
    It is something you should use.
    It is based in the also excellent library Ext But recently we were extruglying with it because when we tried to capture exceptions in the update functions nothing happened and it was terrible because a real life application NEEDS exception handling. My code was something like this:
    First file was places.cfc

    <cfcomponent output="false">


    <cffunction name="getData" access="remote" output="false">
    <cfargument name="page">
    <cfargument name="pageSize">
    <cfargument name="gridsortcolumn">
    <cfargument name="gridsortdirection">
    <cfquery name="team" datasource="cfdocexamples">
    SELECT Emp_ID, FirstName, EMail
    FROM Employees
    <cfif gridsortcolumn neq "" or gridsortdirection neq "">
    order by #gridsortcolumn# #gridsortdirection#
    </cfif>
    </cfquery>
    <cfreturn QueryConvertForGrid(team, page, pageSize)>
    </cffunction>

    <cffunction name="editData" access="remote" output="false">
    <cfargument name="gridaction">
    <cfargument name="gridrow">
    <cfargument name="gridchanged">

    <cfif isStruct(gridrow) and isStruct(gridchanged)>
    <cfif gridaction eq "U">
    <cfset colname=structkeylist(gridchanged)>
    <cfset value=structfind(gridchanged,#colname#)>
    <cfquery name="team" datasource="cfdocexamples">
    update employees set aaa<cfoutput>#colname#</cfoutput> =
    '<cfoutput>#value#</cfoutput>'
    where Emp_ID = <cfoutput>#gridrow.Emp_ID#</cfoutput>
    </cfquery>
    <cfelse>
    <cfquery name="team" datasource="cfdocexamples">
    delete from employees where emp_id = <cfoutput>#gridrow.Emp_ID#
    </cfoutput>
    </cfquery>
    </cfif>
    </cfif>
    </cffunction>

    </cfcomponent>
     

    and the second file was grid2.cfm:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <script type="text/javascript">
    function errorhandler(id,message) {
    alert("Error while updating\n Error code: "+id+"\n Message: "+message);
    }
    </script>
    </head>

    <body>
    <cfform name="form01">
    <cfgrid format="html" name="grid01" pagesize=11
    stripeRows=true stripeRowColor="gray"
    bind="cfc:places.getData({cfgridpage},{cfgridpagesize},
    {cfgridsortcolumn},{cfgridsortdirection})"
    onerror="errorhandler"
    delete="yes" selectmode="edit"
    onchange="cfc:places.editData({cfgridaction},{cfgridrow},{cfgridchanged})">
    <cfgridcolumn name="Emp_ID" display=true header="Employee ID"/>
    <cfgridcolumn name="FirstName" display=true header="Name"/>
    <cfgridcolumn name="Email" display=true header="Email"/>
    </cfgrid>
    </cfform>
    </body>
    </html>

    And the problem where was it!!
    It was not in any of those files it was in the application.cfm There was an onError handler. So it was commented out and everything work perfect! Well I just like to write down these little details so I don't make this silly things twice. I hope this can be of any help
  • SVN get files without the .svn directories

    I felt so stupid today. Because when for a couple of months,
    every now and then, when someone asked me for a copy of the source code
    I just made a copy of my src directory and then searched for the .svn* folder
    and then I erased them,
    until by mistake i found the EXPORT function.
    I use SmartSVN and I was creating a new project
    and then the light came to me :S
    Well if it happens to you just remember there is a
    svn export
    command. This will get the code from the repository without all the nasty files.
  • Twips and .NET

    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

    .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

    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

    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
Powered by Community Server (Non-Commercial Edition), by Telligent Systems