Create Android .apk files using PhoneGap

From Lennie De Villiers:

Instructions to compile an NSBasic app to PhoneGap on Android on MS (Windows only)

  1. Download Java JDK 1.6
  2. Set the Java class path and add the Java bin folder to the PATH variable so that you can run Java (“javac”) from the command line
  3. Download latest Apache Ant
  4. Download Apache Ant to a folder and set the PATH variable to the bin folder so that you can run ant from the command line
  5. set the ANT_HOME variable to the Ant home folder
  6. Download the latest version of Ruby
  7. Set the PATH variable to the bin folder of Ruby so that you can run it from the command line
  8. Get the latest source code of Phone Gap for Android from the GIT repo:
  9. Set the PATH variable to the bin folder so that you can run droidgap.bat from the command line (droidgap.bat is just a wrapper that calls the Ruby script)
  10. Open an command prompt and CD to a folder that contains your NSBasic script files (Index.htm etc)
  11. Rename “index.htm” to “index.html”
  12. Run “droidgap create”. This will create an Android solution using your NSBasic script files.
  13. Compile the application using Ant and deploy to device for testing.

Getting data from a remote server

This turns out to be pretty easy.

First, you’ll need to reformat the data on the server a bit and rename
the file:

Contents of the file:


Call it whatever you like – in my sample, it’s data.js.

Here’s the code in an NS Basic/App Studio program:

'GetData - gets some data from a remote site and processes it

Function Button1_onclick()
  head = document.getElementsByTagName("head")[0]
  newScript = document.createElement("script")
  newScript.type = "text/javascript"
  newScript.src = ""
End Function

Function processData(s)
  For i=0 To UBound(data)-1
    Textarea1.value=Textarea1.value & data(i) & vbcrlf
  End If
End Function

The data in data.js is actually a mini program: it calls a function called processData with the data you want to download.

In the above code, Button1_onclick() takes that file, inserts it into your program and executes it. The code in the file calls processData, which interprets the incoming data and, in this case, simply displays it.

You’ll have to take care that no one can modify data.js, or they could
have all kinds of fun!

This sample will be included in the next build.

What about Palm’s WebOS?

Michael Strupp took some time to try out NS Basic/App Studio on a Palm Pre Plus. In theory, it should work OK: it uses the same HTML5 + WebKit + JavaScript framework that NS Basic/App Studio does. Here’s his report:

I had a chance to try out NSBasic App Studio on my Palm Pre Plus and it looks like it works fine – even the email example worked great (the message loaded into my gmail app, including the body of the text). From what I read, WebOS (the OS running on the Palm Pre) is basically all built upon the WebKit model, so the two seem made for each other.

The only sample app that I tested that I couldn’t get to work right was the one where you squeeze and expand the picture of Mario – I think this is because the WebOS browser natively responds to those gestures already. Otherwise, it seems to work great.


Make App Store apps using AppMobi

Lennie De Villiers from South Africa has built an NS Basic app into AppMobi. AppMobi takes your apps and turns them into packages suitable for submission to the App Store. If you try this, let us know how it goes for you. We will probably turn this into a full Tech Note. Here are his notes:

  1. Register for a free account on, this free account allows you to test the application but if you want to deploy to the App Store then you need to pay the license fee.
  2. Download and install AppMobi XDK IDE, this requires Chrome and Java 6 run-time. The XDK is a full IDE that run within the web browser.
  3. Run the IDE and start a new project.
  4. Choose “Open project folder” menu option.
  5. It open all the project folders… Within this folder you will find “image” folder and the index.html file
  6. Replace these files with your files (see attached sample)
  7. Back at the IDE choose the Reload button. You will see that the interface will change to show the Twitter example.
  8. Go to on your mobile phone
  9. Login
  10. you might need to download the test program to your phone (SlimFat)
  11. Choose your application
  12. Choose “Test Local” or “Test Anywhere”
  13. Chose Launch
  14. SlimFat will open up and run with your NSBasic application.
  15. To deploy to the App Store you need to purchase a license.

More information on how the XDK IDE works etc can be found on the AppMobi web site.

Tip: Images in a Grid

Ever want to put an image in a grid control?

a="<img src='mario.jpg'>"

The cells in a grid will render HTML as their values. We’re just creating a simple html tag that goes into the cell.

Tip: Using Japanese (or other extended alphabets)

Japanese and other extended alphabets are working pretty well with NS Basic/App Studio now, with one exception: the characters show up on the Design Screen as rectangles. It’s because the Design Screen does not  know what font to use.

The solution is to specify the font in the style property of the
control. Put this string into the style property:

font-family: 'MS UI Gothic';

and it will display properly. For other languages, you will need to change the font name to something that is appropriate.

Tip: Delay when refreshing app on device

Did you notice that the first time you hit refresh on the device, you don’t seem to see the updated app?

Here is what is going on:

First, there is a pause while the files are moved into place on

The next time you run the program (or refresh), the device runs its current version from memory while it gets the latest manifest from the server. It compares them: if the manifest has changed, it then downloads the whole application again and saves it to the device. Once this is complete, the new version of the app will run next time you do a refresh.

There are properties you can check to see if the download is complete.

Tip: Including JavaScript Libraries

Here’s a tip that came up in an email conversation with a beta tester:

>>>Wishes of New Functions:
>>>- Factorial, Combinations and Permutations
>>Here’s a really nice part about NS Basic/App Studio: it is easily
>>extensible. If you find a JavaScript library with these functions, it
>>can be used in your program.
>Is there possibility to have universal library with Factorial etc. and
>add this library to code (LoadLibrary, uses, include etc)?

Yes. Here’s how to do it:

  <script src="somelibrary.js" type="text/javascript"></script>

The code in someLibrary.js will become part of your program, and you will be able to call the functions in someLibrary just like you would function in your own program.