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

Call PHP from C#

23. August 2007 12:00 by Mrojas in General  //  Tags:   //   Comments (0)
Sometimes you might have a situation where you have a VB Application you want to migrate to C# but you also have some PHP code you are depending on? Sounds familiar? Well it isn't really a typical scenario jajaja But anyway if you had the urge to do that now project Phalanger can help you with that just check it out And if you need help in the VB6 to C# stuff just write any question you have :)

Geek Survival Kit

23. August 2007 09:35 by Mrojas in General  //  Tags:   //   Comments (0)
As any geek I live frustrated by the lack of good tools in Windows. Notepad, and Paint are just a couple of examples. I was just dreaming for a nice, light replacement for those applications. Well, recently somebody wrote a nice page with amazing freeware that you can use: Amazing Tools

Migrate SQL Server 2000 to SQL Server 2005

19. July 2007 17:20 by Mrojas in General  //  Tags:   //   Comments (0)

The first time you have to upgrade your database from SQL Server 2000 to SQL Server 2005, you might thing is simple process.

And and in very simplistic way of looking at the world it is.

But a REAL migration, from a REAL production database can be a lot more complex that what you can imagine.

A good friend of mine has had to experience recently the various venues of migration like this, and I really recommend his blog, he gives "Jedi" style tips you must consider if you want the Force to be with you.


For all things related to VB6 to C# or VB.NET software migration, be sure to visit Artinsoft's website.

Localize your VB apps

28. May 2007 06:45 by Mrojas in General  //  Tags: , , ,   //   Comments (0)
Localize a VB6 application can be cumbersome, specially if it was not even originally planned to be localized.
Nowadays is common that you're clients might demand support for different languages.
While a localization task is still difficult, we have found excellent results performing it during a VB Migration.
Our tools allow us to easily externalize all your strings. After that the traslation task becomes easy, and you can even use the help
of nice projets like Automatically Translate your .NET resource files with Google Translate

Active Directory, Password Expired

14. May 2007 08:46 by Mrojas in General  //  Tags:   //   Comments (0)
There are a list of situations you might want to handle with Active Directory:

525 - user not found
52e - invalid credentials
530 - not permitted to logon at this time
532 - password expired
533 - account disabled
701 - account expired
773 - user must reset password

 
This is an extract of the Java Forum to handle these cases. Good Luck!
 
} catch (AuthenticationException e) {
String tempString;
StringTokenizer tokenizerTemp = new StringTokenizer(e.toString());
while (tokenizerTemp.hasMoreElements()) {
         tempString = tokenizerTemp.nextToken();
         if (tempString.equalsIgnoreCase("AcceptSecurityContext")) {
                 while (tokenizerTemp.hasMoreElements()) {
                          tempString = tokenizerTemp.nextToken();
                          if (tempString.startsWith("773"))
                                   setIsPasswordExpired(true);
                          if (tempString.startsWith("52e"))
                                   setIsPasswordWrong(true);
                          if (tempString.startsWith("533"))
                                   setIsAccountDisabled(true);
                 }
         }
}
throw new NamingException();
}

 

 

Active Directory LDAP and Java

14. May 2007 08:29 by Mrojas in General  //  Tags:   //   Comments (0)

It is common that after a migration to Java, specially coming from legacy platforms like LINC or COBOL, that our clients want to take advantage of new technologies. So it happens that they are now authenticating against an Active Directory or another LDAP server. And thanks to the new platforms it is really easy for us to help them integrate this new functionality.
This is sample program that show how to authenticate with for example a Windows Active Directory.

import java.io.BufferedReader;
import
java.io.InputStreamReader;
import
java.util.Hashtable;

import javax.naming.Context;
import
javax.naming.NamingEnumeration;
import
javax.naming.NamingException;
import
javax.naming.directory.Attributes;
import
javax.naming.directory.SearchControls;
import
javax.naming.directory.SearchResult;
import
javax.naming.ldap.InitialLdapContext;
import
javax.naming.ldap.LdapContext;

public class LDAPTest
{
       static class LDAP
     
{
            static String ATTRIBUTE_FOR_USER = "sAMAccountName";
            public Attributes authenticateUser(String username, String password, String _domain, String host, String dn)
            {

                  String returnedAtts[] ={ "sn", "givenName", "mail" };
                  String searchFilter = "(&(objectClass=user)(" + ATTRIBUTE_FOR_USER + "=" + username + "))";
                  //Create the search controls

                  SearchControls searchCtls = new SearchControls();
                  searchCtls.setReturningAttributes(returnedAtts);
                  //Specify the search scope

                  searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
                  String searchBase = dn;
                  Hashtable environment = new Hashtable();
                  environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
                  //Using starndard Port, check your instalation

                  environment.put(Context.PROVIDER_URL, "ldap://" + host + ":389");
                  environment.put(Context.SECURITY_AUTHENTICATION, "simple");

                  environment.put(Context.SECURITY_PRINCIPAL, username + "@" + _domain);
                  environment.put(Context.SECURITY_CREDENTIALS, password);
                  LdapContext ctxGC = null;
                  try
                 
{
                        ctxGC = new InitialLdapContext(environment, null);
                        //    Search for objects in the GC using the filter

                        NamingEnumeration answer = ctxGC.search(searchBase, searchFilter, searchCtls);
                        while (answer.hasMoreElements())
                        {
                              SearchResult sr = (SearchResult)answer.next();
                              Attributes attrs = sr.getAttributes();
                              if (attrs != null)
                              {
                                    return attrs;
                              }
                        }

                   }
                  catch (NamingException e)
                 
{
                        System.out.println("Just reporting error");
                       
e.printStackTrace();
                  }
                  return null;
            }
     }

      public static void main(String[] args) throws Exception
     
{
            InputStreamReader converter = new InputStreamReader(System.in);
            BufferedReader in = new BufferedReader(converter);
            System.out.println("Please type username:");
            String username = in.readLine();
            System.out.println("Please type password:");
            String password = in.readLine();
            LDAP ldap = new LDAP();

            //Yo specify in the authenticate user the attributes that you want returned

            //Some companies use standard attributes like 'description' to hold an employee ID

            //The ActiveDirectory data can be enhanced to add custom attributes like

            //printer

            // Some instalations usually have several ACtiveDirectoryServers, lets say

            // 192.150.0.8, 192.150.0.7 y 192.150.0.9 and they use a

            // DNS round robin to balance the load

            Attributes att = ldap.authenticateUser(username, password, "mydomain.com", "myactivedirectoryhost.com", "DC=mydomain,DC=com");
            if (att == null)
            {
                  System.out.println("Sorry your use is invalid or password incorrect");
            }
            else
           
{
                  String s = att.get("givenName").toString();
                  System.out.println("GIVEN NAME=" + s);
            }
      }
}

 

 

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!