Skip to content

Instantly share code, notes, and snippets.

@yiminghe
Last active December 17, 2021 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yiminghe/ba75422198cf472485e61009c0c8812d to your computer and use it in GitHub Desktop.
Save yiminghe/ba75422198cf472485e61009c0c8812d to your computer and use it in GitHub Desktop.
vba demo
<!DOCTYPE html>
<html>
<head>
<title>vba demo</title>
<meta charset="UTF-8" />
</head>
<body>
<div>
<a href="https://bl.ocks.org/yiminghe/ba75422198cf472485e61009c0c8812d" target="_blank">blocks</a> &nbsp;
<a href="https://gist.github.com/yiminghe/ba75422198cf472485e61009c0c8812d" target="_blank">gist</a>
<br/>
</div>
<div id="app"></div>
<script type="module">
import { Context } from 'https://unpkg.com/vba@0.0.26/dist-web/index.js';
const sampleCode = `
sub main
debug.print 1
debug.print 2
end sub
`.trim();
let ret = [];
const MsgBoxSub = {
name: "debug.print",
argumentsInfo: [
{
name: "msg"
}
],
async value(args) {
ret.push((await args.getValue("msg"))?.value);
console.log(ret[ret.length - 1]);
}
};
async function main() {
const context = new Context();
context.registerSubBinding(MsgBoxSub);
await context.load(sampleCode);
await context.callSub("main");
// console log 1 and 2
document.getElementById("app").innerHTML =
`
<h2>demo of npm package: vba</h2>
` + ret.join("<br>");
}
main();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment