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:

processData("1,1000,500,500,500,500,500,500,1001,2000,1000,1000,1000");

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 = "http://www.nsbasic.com/data.js"
  head.appendChild(newScript)  
End Function

Function processData(s)
  data=Split(s,",")
  Textarea1.value=""
  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.