Getting started with deadDrop

Here's how to get started with ScriptDB as a dead drop. For this example, I'll be instrumenting Integrating Excel with Maps and Earth to use a dead drop to pass data between Excel and the generated app. You should familiarize yourself with A VBA API for scriptDB, since we'll be using that API.

Getting the code

You'll need various modules and classes in your workbook. You can incorporate these into your own workbook automatically (How to update modules automatically in VBA) using 

Public Function gtDeadDropLoad()

' scriptdbcom & deaddrop
  gtDoit "8767201", True
  
' parsecom - may want to use parse.com instead
  gtDoit "7663169", True

End Function

but for playing around with this example, just download googleMapping.xlsm from Downloads. The required libraries are also in cDataSet.xlsm.


Setting up for access to scriptDB from Excel.

To be able to access the correct scriptDB from Excel, various parameters and keys are needed. This only needs to be done once per user/PC combination. Since you may not want to share these, I recommend a separate workbook, but the public scriptDB credentials we are going to use for deadDrop playing are in googleMapping.xlsm, and look like this. You should execute this on the PC you are going to use to store the credentials in the PC registry under an entry called "messages". In future, we'll use that entry name to get handles to the scriptDb deadDrop.

Private Sub firstTimescriptdbMessages()
    
    Dim scriptdbCom As cScriptDbCom
    Set scriptdbCom = New cScriptDbCom
    
    With scriptdbCom.init(, _
                "messages", _
                , _
                "messagesKey", _
                "xliberation", _
                False, _
                "scriptDBMessages", _
                False, _
                "https://script.google.com/macros/s/AKfycbzvnq2IZu3JpngnuVxfnPAZYPooVBTULkUyiLFnItfvRxY0NrI/exec")
        .tearDown
    End With
    
End Sub

Setting up for access to scriptDB from your co-operating webapp.

Since we are going to generate a web app from Excel, that web app will also need to know how to access the scriptDb instance you are planning to use. Just as for the PC, this needs to be run only once. It uses local web storage if it can, or if your browser is old it might use cookies instead. You need to run this in the same way you will be executing the webapp - this because the cookie storage is domain specifc. The normal way for googleMapping.xlsm is to execute it locally from the PC, however some people move it to a web site. 
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>deaddroptest - ramblings.mcpher.com</title>

<link rel="stylesheet" type="text/css" href="http://xliberation.com/cdn/css/d3flights.css">
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="https://apis.google.com/js/client.js"></script>
<script type="text/javascript" src="http://xliberation.com/t/gas/js/scriptdbapi.js"></script>
<script type="text/javascript" src="http://xliberation.com/t/gas/js/firsttime.js"></script>
<script type="text/javascript" src="http://xliberation.com/cdn/js/ccookie.js"></script>
<script>
(function () {
  google.load("jquery", "1");
  google.setOnLoadCallback(function() {
    firstTimeMessages ();
    renderScriptDb("registered","#register");
    function renderScriptDb(control,id) {
      $(id).text(control);
    }
  });
})();
</script>
</head>
<body>
<h2>
Register this domain/computer for deaddrop messages
</h2>
<div id="register">
</div>
</body>
</html>

For convenience, I've included this code in the template section of googleMapping.xlsm, and you can generate and execute it like this. If you are planning to execute from a web site rather than locally, then move the generated file there and execute it. 

Public Sub registerDeadDrop()
    Dim ds As cDataSet, cc As cCell, fName As String, sf As String
    Set ds = New cDataSet

    With ds.populateData(wholeSheet(cGeoCodingParameters), , , True, cCustomCode)
        Set cc = .cell("local register", "code")
        If Not cc Is Nothing Then
            sf = cc.toString & vbCrLf
        Else
            MsgBox ("could not find how to register local for deaddrop")
            Exit Sub
        End If
        
        fName = "localDeadDropRegister.html"

        If openNewHtml(fName, sf) Then
            OpenUrl fName
        End If
       
       .tearDown
    End With
    
End Sub

That's the preparation over. 

If you decide to create your own scriptDB environment eventually, you'll need to create your own version of firstTimeMessages() for both VBA (shown earlier) and JavaScript (below). 


You can get me on Google plus, Twitter or this forum. See ScriptDB as a dead drop for more on this
For help and more information join our forumfollow the blogfollow me on twitter
Comments