What does “useStrict” do?

AppStudio 6 introduces a new project property called useStrict. It catches a number of previously non fatal errors in your code and gives error messages.

Here’s an example. If you have the following code:

a = "george"

where a has not been defined, you will get an error with useStrict set to True. There is no error if it is False. UseStrict forces you to have better code.

The solution is to declare the variable before use, using Dim for BASIC and var for JavaScript.

Dim a    ' BASIC
var a;   // JavaScript
a = "george"

Caution: If you turn useStrict on with an existing project, you need to do a complete retest of every part of your project. It will throw errors in code which worked before.

Here is a list of issues found by useStrict:

  • Disallows global variables. (Catches missing var declarations and typos in variable names)
  • Silent failing assignments will throw error in strict mode (assigning NaN = 5;)
  • Attempts to delete undeletable properties will throw (delete Object.prototype)
  • Requires all property names in an object literal to be unique (var x = {x1: “1”, x1: “2”})
  • Function parameter names must be unique (function sum (x, x) {…})
  • Forbids octal syntax (var x = 023; some devs assume wrongly that a preceding zero does nothing to change the number.)
  • Forbids the with keyword
  • eval in strict mode does not introduce new variables
  • Forbids deleting plain names (delete x;)
  • Forbids binding or assignment of the names eval and arguments in any form
  • Strict mode does not alias properties of the arguments object with the formal parameters. (i.e. in function sum (a,b) { return arguments[0] + b;} This works because arguments[0] is bound to a and so on. )
  • arguments.callee is not supported
  • Keywords are checked, including some new ones: implements, interface, let, package, private, protected, public, static, and yield.

Using appStorage to save App-level Data

Previously, we looked at serverStorage, which allows you to save data from your app on the Volt server instead of on the device. serverStorage is saved for the user of the app – other users cannot look at it.

appStorage is data which is shared by all the users of the app. Some possible uses are:

  • A product list, with the latest prices and availability.
  • A message to all users.
  • A table with the latest tax rates or exchange rates.

appStorage works just like serverStorage. It has the same functions. The big differences are that all users of the app see the exact same data, and only Dashboard apps can modify it.

Regular users of the app can use getItem() and getAllItems.

The function clear(), removeItem() and setItem() can be used if the following two conditions are met:

  1. Dashboard Access in Project Properties is set to true.
  2. The name used to sign into the app is the same as the name used to upload the app to Volt.

To use these functions, there is an additional 3rd parameter with the VoltID of the app whose appStorage is to be changed:

appStorage.setItem("SimpleString", "ABCD", "XxXxXx", done);

Dashboard apps include the Dashboard itself, as well as apps which have Volt Dashboard Access project property set to True. You can check NSB.voltDashboardAccess at runtime to see if Dashboard access is enabled.

This is a powerful features, but it should be used wisely. Set Volt Dashboard Access to false for your users so they only read the data in appStorage. If you have an app which creates and changes data for them, do so in a separate app with Volt Dashboard Access set to true.

Using serverStorage to save data on the Volt Server

AppStudio 6.1 brings a new Volt feature: serverStorage. It lets you save and retrieve data on the Volt server. Here are a few uses:

  • As a backup: Keep critical data in the server, so if the phone gets lost or damaged, information is not lost.
  • Multiple devices: If the user runs your app on multiple devices (desktop included), your app can pick up where it left off with the same data.
  • Support: As the owner of the app, you can examine what is in your user’s serverStorage.
  • Data Sharing: The owner of the app can read and write to users’ serverStorage using a different app. Use this to send specific information to users, or to get data the user has collected.

It’s easy to use. You save and retrieve values using a named key. The values can be of any data type: numbers, strings, arrays or objects. There are no limits on the number of values you keep, nor how big the values can be, other than that they be reasonable. If you need to use a lot of data, check with us at support. Here are some examples:
Continue reading “Using serverStorage to save data on the Volt Server”

Using the Clipboard

ClipboardData lets you access the data on the Clipboard. You can:

  • Use and modify the data cut or copied to the clipboard
  • Use and modify data pasted from the clipboard.

It can be used in Input, Textarea and Textbox controls in all frameworks. It controlled by the oncopy, oncut and onpaste events. The information about the clipboard is passed as a parameter to these events.
Continue reading “Using the Clipboard”

The manifestFile property and online apps

In Project Properties, there is a property named ‘manifestFile’. The setting of this property can have a big effect on how your app works, online and offline.

The default setting is appcache. This causes AppStudio to collect the names of the files in your project and put them in a special file called OfflineApp.appcache. When your app is downloaded to a device, this file is checked by the browser. The files named are stored in the browser’s persistent storage on the device. This allows your app to run even without an internet connection, since all the files needed are present.

Each time a cached app is started, the browser checks to see if the OfflineApp.appcache file has been updated on the server: if so, the new version of the app is downloaded. If it can’t reach the server (perhaps because the device is offline), it does nothing and runs normally.

If the OfflineApp.appcache file has been deleted on the server, the app is deleted from the device.

The manifestFile property can also be set to no caching. The OfflineApp.appcache file won’t be created, and the app will not work in offline mode. It’s worth doing if your app will only work if the device is online: for example, if it has a lot of Ajax calls which are necessary for operation. A side benefit is that you won’t get any “Cache Error” messages.

If you change an app from appcache to no caching, be sure to clear your browser’s cache. Otherwise, it will still think it’s a cached app.

The final choice for this setting is manifest. It’s an obsolete setting. When the standard was first set, it specified .manifest as the ending for the file. Microsoft pointed out that it already was using .manifest for something else. Oops. The standard was revised to call it .appcache instead. Some early AppStudio projects were created in the .manifest days – changing the file suffix now could cause cache errors.

Positioning Controls (II)

In our last post on positioning, we discussed the different ways of arranging controls on a form. This time, we’re going to have a closer look at static positioning and how you can get your controls to the proper place on your form.

You might want to open a new project in AppStudio and play along. Start a new form with position set to static. Add three Bootstrap buttons:

screen-shot-2016-11-22-at-9-38-39-am

Notice how they position themselves? They automatically go to the left side of the screen, below the previous button. Let’s see what ways we have to put them on the same line.
Continue reading “Positioning Controls (II)”

Using Adsense with Volt

search-1Adsense is Google’s web ad service. If you agree to display Google’s ads on your site, you’ll collect money each time someone clicks on an add.

To do so, add the AdSense control to your app. Choose the size (320×50 up to 300×250) and position it. AdSense will automatically display ads in the space. You’ll need to set Client number and Adsense slot number.

Get the Client and slot numbers from Google Adsense when you sign up. Follow Google’s instructions for the rest: they are pretty good.

One of the requirements is to list the name of the site your app is hosted on. If you don’t have a site, no problem. You can use Volt. Simply supply the URL to your app on Volt:

screen-shot-2016-11-21-at-3-52-32-pm

Here’s an ad in an app:

screen-shot-2016-11-22-at-5-10-10-am

And here’s a link you can try yourself: https://adsense-wets-correctly.volt.live/

Now tell people about your app and watch the money roll in!

Make your own Bootstrap Theme

AppStudio lets you manipulate many of the features of the Bootstrap controls. Essential to their appearance, however, is the theme they use. By changing the theme, you can affect the color and appearance of all your Bootstrap controls. AppStudio includes 18 Bootstrap themes: bootstrap, bootstrap-enhanced, cerulean, cosmo, cyborg, darkly, flatly, journal, lumin, paper, readable, sandstone, simplex, slate, spacelab, superhero, united and yeti.

But what if you want to make your own theme? It’s surprisingly easy to do using the Bootstrap Theme Customizer. You start it from http://getbootstrap.com/customize/ or AppStudio’s Tools menu. It includes full documentation – we just present an overview here.

Continue reading “Make your own Bootstrap Theme”