Converting a VB project to App Studio

Recently, a customer asked us if we could convert an existing Visual Basic project to App Studio, so he could run it on iOS and Android devices. We had a look, saw it was a good candidate and went ahead with the conversion. It’s pretty much complete now and working fine.

Let’s have a look at the steps to do this:

  1. First, we opened the VB project and a new App Studio project side by side. In the App Studio project, we filled in the project name, the version number, copyright info, etc.
  2. The project has two forms, so we created them using the same names as in the VB project.
  3. There isn’t any way to copy the form layouts from VB to App Studio, so they each had to be set up. The two forms had a total of 67 controls. It took an hour or two to recreate them all. Most of them were Labels, CommandButtons, ComboBoxes and TextBoxes: we created the new controls with the same names as the old ones. There was some cases where the VB program used grouped command buttons as sort of a radio button: we changed those to real radio buttons which look and work better. In some cases, the text on buttons was changed to an icon.
  4. Deal with crowding of controls. To allow them to be finger friendly, buttons need to be larger in a mobile app than for a desktop app. This meant repositioning everything a bit
  5. Code can be copied. There was code for each form, plus a code module with general purpose code. Each form’s code was copied to the new project, and a code module added for the general purpose code.
  6. Now, time to clean up the code syntax differences between VB and App Studio.
    • All variables are of type Variant in App Studio. The “As String…” etc. clauses need to be removed using Find/Replace.
    • No such thing as “Public” or “Private” for a function. Find/Replace them.
    • Change _Click() to _onclick(), _Change to _onchange() in function names.
    • Make sure that global arrays are DIMmed at the top of each code module. App Studio doesn’t (yet) complete remember global arrays really are global.
    • Make sure that all function calls end with (). VB lets you get sloppy with this.
  7. Time to start testing! Since all the controls have the same names, the code actually runs the first time. Not well, but it’s very encouraging. Time to clean up some specific issues:
    • The app saves its settings to a .txt file. App Studio can’t do .txt files, but localStorage will work the same way. Here’s the code for VB:
      Sub ReadINI()
          Dim d As String
          'Opens the file and reads the data into camINI array
          On Error Resume Next
          Open App.Path & "camINI.txt" For Input As 1
          If Err <> 0 Then
            'Now open it
            Open App.Path & "camINI.txt" For Input As 1
          End If
          Input #1, d: camINI(1) = strUnCypher(d)
          Input #1, d: camINI(2) = strUnCypher(d)
          Input #1, d: camINI(3) = strUnCypher(d)
          Close 1
      End Sub

      And here’s the code for App Studio:

      Sub ReadINI()
          If typeof(localStorage.d1)="undefined" Then CreateINI
          camINI(1) = strUnCypher(localStorage.d1)
          camINI(2) = strUnCypher(localStorage.d2)
          camINI(3) = strUnCypher(localStorage.d3)  
      End Sub
    • The app does a lot of complex calculations. We’ll want to test those carefully. Right away, we notice that we are getting “undefined” for many of the results. Digging into the code, we find a variable named INFINITY. That’s fine in VB, but it’s a reserved word in App Studio. We change it to InfinityVal.
    • Things are looking a lot better now. Most of the calculations are correct. But in one of them, we’re getting 9.46 instead of 9.38. Digging into this one, we find that the AppStudio CSng() function is returning 0.33 instead of 0.333. We’ve found a bug in App Studio. I pass it on to the support guys and have a fix in a few hours.
    • Some numbers aren’t displaying properly. The values are correct: the Format() function isn’t working. No wonder: App Studio, based on VBScript, doesn’t have a Format() function. We make this change and all is fine:
      strMinimumFocus = Format(sngMinimumFocus, "0.00") & "m"

      changed to…

      strMinimumFocus = FormatNumber(sngMinimumFocus, 2) & "m"
    • Form_Load() is not called automatically as in VB. Add a statement to do that.
  8. It’s running fairly well now. Those are the major things that needed to be done: I’m sure there were a few more details that I missed. Just a couple more steps:
  9. Create a Help screen. There were some HTML files that explained how to use the app. We added a third form to display them.
  10. Deploy the app and try it out on some iOS and Android devices. Things are looking good!

There is still more work to do before shipping. The screen layouts were simply copied to App Studio, without thinking hard about whether the work flow or appearance could be improved for Mobile devices. Hooking the app up to the user’s “Buy Now” button also needs to be tested.

The app is in the customer’s hands now for further testing. We’ve shown, though, that a VB app with a couple of forms, over 60 controls and a lot of specialized calculations can be ported to iOS and Android devices in a couple of days. Not all apps will be this straightforward, but it certainly is much faster and easier than any other way of doing this.

Got a VB project you’d like to have run on iOS and Android? Contact us – we may be able to help!