-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path525.html
More file actions
644 lines (644 loc) · 51.8 KB
/
Copy path525.html
File metadata and controls
644 lines (644 loc) · 51.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SmallBASIC | FORM</title>
<meta name="description" content="Creates a form object from a MAP variable. This provides access to the following sub-commands: doEvents, close, refresh. The form MAP may contain the following properties: value, inputs, focus. Inputs is an array of MAP, each may contain the following properties: x, y, width, height, value, label, name, type, backgroundColor, color, visible, isExit, selectedIndex, length, noFocus, onclick">
<link rel="canonical" href="525">
<link rel="keywords" href="FORM(map)">
<link rel="stylesheet" href="/css/style.css">
<link rel="icon" type="image/png" href="/images/sb-desktop-32x32.png">
<script src="/clipboard.js"></script>
</head>
<body>
<button onclick="topFunction()" id="BackToTopBtn" title="Go to top">⯅</button>
<script src="/backtotop.js"></script>
<div class="wrapAll clearfix">
<nav class="navigation">
<div class="logo">
<a href="/"><img src='/images/sb-logo.png?v=2' alt="logo"></a>
</div>
<div class="navlinks">
<a href="/pages/download.html">Download</a>
<a href="/pages/news.html">News</a>
<a href="/pages/community.html">Community</a>
<a href="/pages/articles.html">Resources</a>
<a class='active' href="/pages/reference.html">Language Reference</a>
<a href="/pages/guide.html">SmallBASIC Manual</a>
</div>
</nav>
<div class="mainsection">
<div class="tabs clearfix">
<div class="tabsRight">
<a target="_github" href="https://github.com/smallbasic/smallbasic.github.io/blob/master/_build/reference/525-console-form.markdown">Edit</a>
<a target="_github" href="https://github.com/smallbasic/smallbasic.github.io/commits/master/_build/reference/525-console-form.markdown">History</a>
</div>
</div>
<div class="article">
<h1>FORM</h1>
<blockquote>f = FORM(formMap)</blockquote>
<div class="siteSub">
<p>
<a href="/">Home</a> >
<a href="/pages/reference.html">Reference</a> >
<a href="/pages/console.html">Console</a>
</p>
</div>
<p>Creates a form object <code>f</code> from a MAP variable
<code>formMap</code>. Form object <code>f</code> gives access to the
following GUI elements:</p>
<ul>
<li>Push button</li>
<li>Label</li>
<li>Hyperlinked text</li>
<li>Listbox</li>
<li>Dropdown listbox</li>
<li>Single or multi-line text input</li>
<li>Image button</li>
</ul>
<p>In listboxes and dropdown listboxes press and hold mouse button to
scroll through the items. Alternatively arrow keys can be used. Press
return or space for selecting the highlighted item.</p>
<h3 id="the-form-object">The form object</h3>
<p><code>f = form(formMAP)</code> provides access to the following
sub-commands of the form object <code>f</code>:</p>
<table>
<colgroup>
<col style="width: 29%" />
<col style="width: 70%" />
</colgroup>
<thead>
<tr class="header">
<th>Sub-command</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>doEvents()</td>
<td>Process system events for mouse and keyboard handling.</td>
</tr>
<tr class="even">
<td>close()</td>
<td>Closes the active FORM.</td>
</tr>
<tr class="odd">
<td>refresh(n)</td>
<td><code>n = 1</code> copy the UI state into the FORM input variables
<code>f.inputs</code>. <code>n = 0</code> update the UI state using the
FORM input variables <code>f.inputs</code>.</td>
</tr>
</tbody>
</table>
<p>The form object <code>f</code> may contain the following
properties:</p>
<table>
<thead>
<tr class="header">
<th>Property</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>value</td>
<td>The value from the active input field.</td>
</tr>
<tr class="even">
<td><strong>inputs</strong></td>
<td>Array of inputs.</td>
</tr>
<tr class="odd">
<td>focus</td>
<td>Index to the focused input.</td>
</tr>
</tbody>
</table>
<h3 id="defining-the-input-fields">Defining the input fields</h3>
<p><code>inputs</code> is an array of type MAP, each element may contain
the following attributes:</p>
<table>
<colgroup>
<col style="width: 53%" />
<col style="width: 46%" />
</colgroup>
<thead>
<tr class="header">
<th>Attribute</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>x</td>
<td>X coordinate.</td>
</tr>
<tr class="even">
<td>y</td>
<td>Y coordinate.</td>
</tr>
<tr class="odd">
<td>width</td>
<td>Width.</td>
</tr>
<tr class="even">
<td>height</td>
<td>Height.</td>
</tr>
<tr class="odd">
<td>value</td>
<td>The internal value associated with the input.</td>
</tr>
<tr class="even">
<td>label</td>
<td>The display label for the input.</td>
</tr>
<tr class="odd">
<td>name</td>
<td>The name of the input.</td>
</tr>
<tr class="even">
<td><strong>type</strong></td>
<td>The type of input, see below.</td>
</tr>
<tr class="odd">
<td>help</td>
<td>Listbox or single line text input help text.</td>
</tr>
<tr class="even">
<td>backgroundColor</td>
<td>Background color.</td>
</tr>
<tr class="odd">
<td>color</td>
<td>Forground color.</td>
</tr>
<tr class="even">
<td>isExit</td>
<td>Whether clicking the input exits the current program.</td>
</tr>
<tr class="odd">
<td>isExternal</td>
<td>Whether the <code>link</code> field opens in an external
browser.</td>
</tr>
<tr class="even">
<td>resizable</td>
<td>Whether the field can be resized.</td>
</tr>
<tr class="odd">
<td>visible</td>
<td>Whether the input field is visible.</td>
</tr>
<tr class="even">
<td>selectedIndex</td>
<td>The selected item in a listbox or choice.</td>
</tr>
<tr class="odd">
<td>length</td>
<td>Length of a TEXT input field in number of characters.</td>
</tr>
<tr class="even">
<td>noFocus</td>
<td>The input cannot receive focus.</td>
</tr>
<tr class="odd">
<td>onclick</td>
<td>SUB to invoke when clicked.</td>
</tr>
</tbody>
</table>
<p>The type attribute can be one of the following:</p>
<table>
<thead>
<tr class="header">
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>“button”</td>
<td>Push button.</td>
</tr>
<tr class="even">
<td>“label”</td>
<td>Display label.</td>
</tr>
<tr class="odd">
<td>“link”</td>
<td>Hyperlinked text.</td>
</tr>
<tr class="even">
<td>“listbox”</td>
<td>Listbox.</td>
</tr>
<tr class="odd">
<td>“choice”</td>
<td>Dropdown listbox.</td>
</tr>
<tr class="even">
<td>“text”</td>
<td>Single or multi-line text input.</td>
</tr>
<tr class="odd">
<td>“image”</td>
<td>Image button.</td>
</tr>
</tbody>
</table>
<h3 id="change-or-read-the-gui-elements">Change or read the GUI
elements</h3>
<p>Once the GUI elements are rendered on screen they can be changed for
example to respond to user input. By calling <code>f.refresh(1)</code>
the current state of the GUI elements will be copied to <code>f</code>.
The content of <code>f</code> is rendered to screen, when calling
<code>f.refresh(0)</code>. <code>f.inputs</code> is an array of MAP
variables. The first element of that array is the first GUI element
added to <code>formMap.inputs</code>. For example the color of the first
element can be changed:</p>
<div class="sourceCode" id="cb1"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>f.inputs[<span class="dv">0</span>].<span class="fu">color</span> = <span class="dv">12</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a>f.refresh(<span class="dv">0</span>)</span></code></pre></div>
<p>To get a list of all available elements of the n-th GUI element, you
can simply use <code>print f.inputs[n]</code>.</p>
<h3
id="example-1-creating-a-push-button-using-callback-function">Example 1:
Creating a push button using callback function</h3>
<p>When using buttons in combination with callback functions, the
<code>doEvents()</code> function is not necessary. Without this function
the execution of the program will not be blocked. In the following
example a number will be incremented in a while loop and printed to the
screen. When the button is pressed, the callback function is executed
and will block the program until the callback function ends.</p>
<div class="sourceCode" id="cb2"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>button.type = <span class="st">"button"</span></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a>button.x = <span class="dv">120</span></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a>button.y = <span class="dv">120</span></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a>button.<span class="kw">label</span> = <span class="st">"Button"</span></span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a>button.backgroundcolor = <span class="fu">rgb</span>(<span class="dv">60</span>, <span class="dv">60</span>, <span class="dv">60</span>)</span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a>button.onclick = @ButtonClicked <span class="co">' Callback function, definition see below</span></span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a>formMAP.inputs << button</span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a>f = <span class="fu">form</span>(formMAP)</span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a><span class="kw">while </span><span class="dv">1</span></span>
<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a> ii++</span>
<span id="cb2-14"><a href="#cb2-14" aria-hidden="true" tabindex="-1"></a> <span class="fu">locate</span> <span class="dv">0</span>,<span class="dv">0</span>: <span class="kw">print</span> ii</span>
<span id="cb2-15"><a href="#cb2-15" aria-hidden="true" tabindex="-1"></a> <span class="fu">delay</span>(<span class="dv">100</span>) </span>
<span id="cb2-16"><a href="#cb2-16" aria-hidden="true" tabindex="-1"></a><span class="kw">wend</span></span>
<span id="cb2-17"><a href="#cb2-17" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-18"><a href="#cb2-18" aria-hidden="true" tabindex="-1"></a>f.<span class="fu">close</span>()</span>
<span id="cb2-19"><a href="#cb2-19" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-20"><a href="#cb2-20" aria-hidden="true" tabindex="-1"></a><span class="kw">sub </span>ButtonClicked()</span>
<span id="cb2-21"><a href="#cb2-21" aria-hidden="true" tabindex="-1"></a> <span class="fu">locate</span> <span class="dv">1</span>,<span class="dv">0</span></span>
<span id="cb2-22"><a href="#cb2-22" aria-hidden="true" tabindex="-1"></a> Clicked++</span>
<span id="cb2-23"><a href="#cb2-23" aria-hidden="true" tabindex="-1"></a> <span class="kw">print</span> <span class="st">"Button clicked "</span> + Clicked + <span class="st">" times"</span></span>
<span id="cb2-24"><a href="#cb2-24" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span></span></code></pre></div>
<h3 id="example-2-creating-a-push-button-using-doevents-result">Example
2: Creating a push button using doEvents result</h3>
<div class="sourceCode" id="cb3"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>button.type = <span class="st">"button"</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a>button.x = <span class="dv">120</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a>button.y = <span class="dv">120</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a>button.<span class="kw">label</span> = <span class="st">"Button"</span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a>button.backgroundcolor = <span class="fu">rgb</span>(<span class="dv">60</span>, <span class="dv">60</span>, <span class="dv">60</span>)</span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a>button.value = <span class="dv">1</span> <span class="co">' unique value to identify the button</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a>formMAP.inputs << button</span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true" tabindex="-1"></a>f = <span class="fu">form</span>(formMAP)</span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true" tabindex="-1"></a><span class="kw">while </span><span class="dv">1</span></span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true" tabindex="-1"></a> f.doEvents()</span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true" tabindex="-1"></a> <span class="kw">if(</span>f.value == <span class="dv">1</span>) <span class="kw">then</span></span>
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true" tabindex="-1"></a> ii++</span>
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true" tabindex="-1"></a> <span class="fu">at</span> <span class="dv">0</span>,<span class="dv">0</span></span>
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true" tabindex="-1"></a> <span class="kw">print</span> <span class="st">"Button cklicked "</span> + ii + <span class="st">" times."</span></span>
<span id="cb3-18"><a href="#cb3-18" aria-hidden="true" tabindex="-1"></a> <span class="kw">endif </span></span>
<span id="cb3-19"><a href="#cb3-19" aria-hidden="true" tabindex="-1"></a><span class="kw">wend</span></span>
<span id="cb3-20"><a href="#cb3-20" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-21"><a href="#cb3-21" aria-hidden="true" tabindex="-1"></a>f.<span class="fu">close</span>()</span></code></pre></div>
<h3 id="example-3-creating-a-label">Example 3: Creating a label</h3>
<div class="sourceCode" id="cb4"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>l.type = <span class="st">"label"</span></span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a>l.x = <span class="dv">120</span></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a>l.y = <span class="dv">120</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a>l.<span class="kw">label</span> = <span class="st">"Label"</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a>l.<span class="fu">color</span> = <span class="fu">rgb</span>(<span class="dv">255</span>, <span class="dv">60</span>, <span class="dv">60</span>)</span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a>f.inputs << l</span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a>f = <span class="fu">form</span>(f)</span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true" tabindex="-1"></a><span class="kw">while </span><span class="dv">1</span></span>
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true" tabindex="-1"></a> f.doEvents()</span>
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true" tabindex="-1"></a><span class="kw">wend</span></span>
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-15"><a href="#cb4-15" aria-hidden="true" tabindex="-1"></a>f.<span class="fu">close</span>()</span></code></pre></div>
<h3 id="example-4-creating-a-link-to-an-external-website">Example 4:
Creating a link to an external website</h3>
<div class="sourceCode" id="cb5"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>l.type = <span class="st">"link"</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>l.x = <span class="dv">120</span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a>l.y = <span class="dv">120</span></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a>l.<span class="kw">label</span> = <span class="st">"Link to SmallBASIC website"</span></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a>l.value = <span class="st">"https://smallbasic.github.io"</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a>l.isExternal = <span class="dt">true</span></span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a>l.<span class="fu">color</span> = <span class="fu">rgb</span>(<span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">255</span>)</span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a>f.inputs << l</span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a>f = <span class="fu">form</span>(f)</span>
<span id="cb5-12"><a href="#cb5-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-13"><a href="#cb5-13" aria-hidden="true" tabindex="-1"></a><span class="kw">while </span><span class="dv">1</span></span>
<span id="cb5-14"><a href="#cb5-14" aria-hidden="true" tabindex="-1"></a> f.doEvents()</span>
<span id="cb5-15"><a href="#cb5-15" aria-hidden="true" tabindex="-1"></a><span class="kw">wend</span></span>
<span id="cb5-16"><a href="#cb5-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-17"><a href="#cb5-17" aria-hidden="true" tabindex="-1"></a>f.<span class="fu">close</span>()</span></code></pre></div>
<h3 id="example-5-creating-a-listbox">Example 5: Creating a listbox</h3>
<div class="sourceCode" id="cb6"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>l.type = <span class="st">"listbox"</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a>l.x = <span class="dv">120</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a>l.y = <span class="dv">120</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a>l.height = <span class="dv">200</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a>l.width = <span class="dv">100</span></span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a>l.value = <span class="st">"cats|dogs|fish|birds|insects"</span></span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a><span class="co">' alternative way is to pass an array:</span></span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true" tabindex="-1"></a><span class="co">' l.value = ["cats", "dogs", "fish", "birds", "insects"]</span></span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true" tabindex="-1"></a>l.<span class="fu">color</span> = <span class="fu">rgb</span>(<span class="dv">255</span>, <span class="dv">255</span>, <span class="dv">255</span>)</span>
<span id="cb6-10"><a href="#cb6-10" aria-hidden="true" tabindex="-1"></a>l.backgroundColor = <span class="fu">rgb</span>(<span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">100</span>)</span>
<span id="cb6-11"><a href="#cb6-11" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-12"><a href="#cb6-12" aria-hidden="true" tabindex="-1"></a>f.inputs << l</span>
<span id="cb6-13"><a href="#cb6-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-14"><a href="#cb6-14" aria-hidden="true" tabindex="-1"></a>f = <span class="fu">form</span>(f)</span>
<span id="cb6-15"><a href="#cb6-15" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-16"><a href="#cb6-16" aria-hidden="true" tabindex="-1"></a><span class="kw">while </span><span class="dv">1</span></span>
<span id="cb6-17"><a href="#cb6-17" aria-hidden="true" tabindex="-1"></a> f.doEvents()</span>
<span id="cb6-18"><a href="#cb6-18" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb6-19"><a href="#cb6-19" aria-hidden="true" tabindex="-1"></a> <span class="co">' Check for value of the active input field</span></span>
<span id="cb6-20"><a href="#cb6-20" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span>(<span class="fu">len</span>(f.value) > <span class="dv">0</span>) <span class="kw">then</span></span>
<span id="cb6-21"><a href="#cb6-21" aria-hidden="true" tabindex="-1"></a> <span class="fu">at</span> <span class="dv">0</span>,<span class="dv">0</span></span>
<span id="cb6-22"><a href="#cb6-22" aria-hidden="true" tabindex="-1"></a> <span class="kw">print</span> f.value; <span class="st">" "</span></span>
<span id="cb6-23"><a href="#cb6-23" aria-hidden="true" tabindex="-1"></a> <span class="kw">end if </span> </span>
<span id="cb6-24"><a href="#cb6-24" aria-hidden="true" tabindex="-1"></a><span class="kw">wend</span></span>
<span id="cb6-25"><a href="#cb6-25" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-26"><a href="#cb6-26" aria-hidden="true" tabindex="-1"></a>f.<span class="fu">close</span>()</span></code></pre></div>
<h3 id="example-6-creating-a-dropdown-listbox">Example 6: Creating a
dropdown listbox</h3>
<div class="sourceCode" id="cb7"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>l.type = <span class="st">"choice"</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a>l.x = <span class="dv">120</span></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a>l.y = <span class="dv">120</span></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a>l.width = <span class="dv">100</span></span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a>l.value = <span class="st">"cats|dogs|fish|birds|insects"</span></span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a><span class="co">' alternative way is to pass an array:</span></span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a><span class="co">' l.value = ["cats", "dogs", "fish", "birds", "insects"]</span></span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true" tabindex="-1"></a>l.<span class="fu">color</span> = <span class="fu">rgb</span>(<span class="dv">255</span>, <span class="dv">255</span>, <span class="dv">255</span>)</span>
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true" tabindex="-1"></a>l.backgroundColor = <span class="fu">rgb</span>(<span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">100</span>)</span>
<span id="cb7-10"><a href="#cb7-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-11"><a href="#cb7-11" aria-hidden="true" tabindex="-1"></a>f.inputs << l</span>
<span id="cb7-12"><a href="#cb7-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-13"><a href="#cb7-13" aria-hidden="true" tabindex="-1"></a>f = <span class="fu">form</span>(f)</span>
<span id="cb7-14"><a href="#cb7-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-15"><a href="#cb7-15" aria-hidden="true" tabindex="-1"></a><span class="kw">while </span><span class="dv">1</span></span>
<span id="cb7-16"><a href="#cb7-16" aria-hidden="true" tabindex="-1"></a> f.doEvents()</span>
<span id="cb7-17"><a href="#cb7-17" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb7-18"><a href="#cb7-18" aria-hidden="true" tabindex="-1"></a> <span class="co">' Check for value of the active input field</span></span>
<span id="cb7-19"><a href="#cb7-19" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span>(<span class="fu">len</span>(f.value) > <span class="dv">0</span>) <span class="kw">then</span></span>
<span id="cb7-20"><a href="#cb7-20" aria-hidden="true" tabindex="-1"></a> <span class="fu">at</span> <span class="dv">0</span>,<span class="dv">0</span></span>
<span id="cb7-21"><a href="#cb7-21" aria-hidden="true" tabindex="-1"></a> <span class="kw">print</span> f.value; <span class="st">" "</span></span>
<span id="cb7-22"><a href="#cb7-22" aria-hidden="true" tabindex="-1"></a> <span class="kw">end if </span> </span>
<span id="cb7-23"><a href="#cb7-23" aria-hidden="true" tabindex="-1"></a><span class="kw">wend</span></span>
<span id="cb7-24"><a href="#cb7-24" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-25"><a href="#cb7-25" aria-hidden="true" tabindex="-1"></a>f.<span class="fu">close</span>()</span></code></pre></div>
<h3 id="example-7-creating-a-text-input-field">Example 7: Creating a
text input field</h3>
<div class="sourceCode" id="cb8"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>t.type = <span class="st">"text"</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a>t.x = <span class="dv">120</span></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a>t.y = <span class="dv">120</span></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a>t.width = <span class="dv">300</span></span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a>t.value = <span class="st">"Add more text"</span></span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a><span class="co">' t.height = 100 ' if hight is not defined, single line field</span></span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true" tabindex="-1"></a>t.<span class="fu">color</span> = <span class="fu">rgb</span>(<span class="dv">255</span>, <span class="dv">255</span>, <span class="dv">255</span>)</span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true" tabindex="-1"></a>t.backgroundColor = <span class="fu">rgb</span>(<span class="dv">100</span>, <span class="dv">100</span>, <span class="dv">100</span>)</span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true" tabindex="-1"></a>t.length = <span class="dv">50</span> <span class="co">' number of characters</span></span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-11"><a href="#cb8-11" aria-hidden="true" tabindex="-1"></a><span class="co">' create additionally an OK-Button to update the form object</span></span>
<span id="cb8-12"><a href="#cb8-12" aria-hidden="true" tabindex="-1"></a><span class="co">' otherwise the text field blocks loop</span></span>
<span id="cb8-13"><a href="#cb8-13" aria-hidden="true" tabindex="-1"></a>b.type = <span class="st">"button"</span></span>
<span id="cb8-14"><a href="#cb8-14" aria-hidden="true" tabindex="-1"></a>b.x = <span class="dv">120</span> + t.width + <span class="dv">10</span></span>
<span id="cb8-15"><a href="#cb8-15" aria-hidden="true" tabindex="-1"></a>b.y = <span class="dv">120</span> </span>
<span id="cb8-16"><a href="#cb8-16" aria-hidden="true" tabindex="-1"></a>b.<span class="kw">label</span> = <span class="st">"OK"</span></span>
<span id="cb8-17"><a href="#cb8-17" aria-hidden="true" tabindex="-1"></a>b.backgroundcolor = <span class="fu">rgb</span>(<span class="dv">60</span>, <span class="dv">60</span>, <span class="dv">60</span>)</span>
<span id="cb8-18"><a href="#cb8-18" aria-hidden="true" tabindex="-1"></a>b.onclick = @OKButtonClicked</span>
<span id="cb8-19"><a href="#cb8-19" aria-hidden="true" tabindex="-1"></a>f.inputs << t</span>
<span id="cb8-20"><a href="#cb8-20" aria-hidden="true" tabindex="-1"></a>f.inputs << b</span>
<span id="cb8-21"><a href="#cb8-21" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-22"><a href="#cb8-22" aria-hidden="true" tabindex="-1"></a>f = <span class="fu">form</span>(f)</span>
<span id="cb8-23"><a href="#cb8-23" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-24"><a href="#cb8-24" aria-hidden="true" tabindex="-1"></a><span class="kw">while </span><span class="dv">1</span></span>
<span id="cb8-25"><a href="#cb8-25" aria-hidden="true" tabindex="-1"></a> f.doEvents() </span>
<span id="cb8-26"><a href="#cb8-26" aria-hidden="true" tabindex="-1"></a><span class="kw">wend</span></span>
<span id="cb8-27"><a href="#cb8-27" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-28"><a href="#cb8-28" aria-hidden="true" tabindex="-1"></a>f.<span class="fu">close</span>()</span>
<span id="cb8-29"><a href="#cb8-29" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb8-30"><a href="#cb8-30" aria-hidden="true" tabindex="-1"></a><span class="kw">sub </span>OKButtonClicked()</span>
<span id="cb8-31"><a href="#cb8-31" aria-hidden="true" tabindex="-1"></a> f.refresh(<span class="dv">1</span>) <span class="co">' Update the form object</span></span>
<span id="cb8-32"><a href="#cb8-32" aria-hidden="true" tabindex="-1"></a> <span class="fu">at</span> <span class="dv">0</span>,<span class="dv">0</span></span>
<span id="cb8-33"><a href="#cb8-33" aria-hidden="true" tabindex="-1"></a> <span class="kw">print</span> f.inputs[<span class="dv">0</span>].value <span class="co">' Text field is the first element added to the formMAP</span></span>
<span id="cb8-34"><a href="#cb8-34" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span></span></code></pre></div>
<h3 id="example-8-image-button-using-callback-function">Example 8: Image
button using callback function</h3>
<p>In this example a callback function will be used. If you want to use
the doEvents result instead, have a look at example 2.</p>
<div class="sourceCode" id="cb9"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="co">' Create a simple button and save it as png</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a><span class="co">' If you have already an image for you button,</span></span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a><span class="co">' this part is not necessary.</span></span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true" tabindex="-1"></a><span class="fu">circle</span> <span class="dv">100</span>,<span class="dv">100</span>,<span class="dv">100</span> <span class="fu">color</span> <span class="dv">15</span> filled</span>
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true" tabindex="-1"></a>ButtonImage = <span class="fu">image</span>(<span class="dv">0</span>,<span class="dv">0</span>,<span class="dv">200</span>,<span class="dv">200</span>)</span>
<span id="cb9-6"><a href="#cb9-6" aria-hidden="true" tabindex="-1"></a>ButtonImage.save(<span class="st">"button.png"</span>)</span>
<span id="cb9-7"><a href="#cb9-7" aria-hidden="true" tabindex="-1"></a><span class="fu">cls</span></span>
<span id="cb9-8"><a href="#cb9-8" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb9-9"><a href="#cb9-9" aria-hidden="true" tabindex="-1"></a><span class="co">' Define image button</span></span>
<span id="cb9-10"><a href="#cb9-10" aria-hidden="true" tabindex="-1"></a>button.type = <span class="st">"image"</span></span>
<span id="cb9-11"><a href="#cb9-11" aria-hidden="true" tabindex="-1"></a>button.name = <span class="st">"button.png"</span></span>
<span id="cb9-12"><a href="#cb9-12" aria-hidden="true" tabindex="-1"></a>button.x = <span class="dv">120</span></span>
<span id="cb9-13"><a href="#cb9-13" aria-hidden="true" tabindex="-1"></a>button.y = <span class="dv">120</span></span>
<span id="cb9-14"><a href="#cb9-14" aria-hidden="true" tabindex="-1"></a>button.onclick = @ButtonClicked <span class="co">' Callback function, definition see below.</span></span>
<span id="cb9-15"><a href="#cb9-15" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb9-16"><a href="#cb9-16" aria-hidden="true" tabindex="-1"></a>formMAP.inputs << button</span>
<span id="cb9-17"><a href="#cb9-17" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb9-18"><a href="#cb9-18" aria-hidden="true" tabindex="-1"></a>f = <span class="fu">form</span>(formMAP)</span>
<span id="cb9-19"><a href="#cb9-19" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb9-20"><a href="#cb9-20" aria-hidden="true" tabindex="-1"></a><span class="kw">while </span><span class="dv">1</span></span>
<span id="cb9-21"><a href="#cb9-21" aria-hidden="true" tabindex="-1"></a> f.doEvents()</span>
<span id="cb9-22"><a href="#cb9-22" aria-hidden="true" tabindex="-1"></a><span class="kw">wend</span></span>
<span id="cb9-23"><a href="#cb9-23" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb9-24"><a href="#cb9-24" aria-hidden="true" tabindex="-1"></a>f.<span class="fu">close</span>()</span>
<span id="cb9-25"><a href="#cb9-25" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb9-26"><a href="#cb9-26" aria-hidden="true" tabindex="-1"></a><span class="kw">sub </span>ButtonClicked()</span>
<span id="cb9-27"><a href="#cb9-27" aria-hidden="true" tabindex="-1"></a> <span class="fu">at</span> <span class="dv">0</span>,<span class="dv">0</span></span>
<span id="cb9-28"><a href="#cb9-28" aria-hidden="true" tabindex="-1"></a> Clicked++</span>
<span id="cb9-29"><a href="#cb9-29" aria-hidden="true" tabindex="-1"></a> <span class="kw">print</span> <span class="st">"Button clicked "</span> + Clicked + <span class="st">" times"</span></span>
<span id="cb9-30"><a href="#cb9-30" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span></span></code></pre></div>
<h3 id="example-9-one-more-example">Example 9: One more example</h3>
<div class="sourceCode" id="cb10"><pre
class="sourceCode smallbasic"><code class="sourceCode smallbasic"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>f.handleKeys = <span class="dv">0</span></span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a><span class="co">' create some buttons</span></span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a>button1.y = <span class="dv">120</span></span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a>button1.<span class="kw">label</span> = <span class="st">"Button1"</span></span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a>button1.value = <span class="st">"valueofButton1"</span></span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true" tabindex="-1"></a>button1.backgroundcolor = <span class="fu">rgb</span>(<span class="dv">255</span>,<span class="dv">0</span>,<span class="dv">0</span>)</span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true" tabindex="-1"></a>button1.onclick = @HelloWorld <span class="co">'this prints on load</span></span>
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true" tabindex="-1"></a>button2.x = -<span class="dv">1</span></span>
<span id="cb10-9"><a href="#cb10-9" aria-hidden="true" tabindex="-1"></a>button2.y = <span class="dv">120</span></span>
<span id="cb10-10"><a href="#cb10-10" aria-hidden="true" tabindex="-1"></a>button2.<span class="kw">label</span> = <span class="st">"Button2"</span></span>
<span id="cb10-11"><a href="#cb10-11" aria-hidden="true" tabindex="-1"></a>button2.value = <span class="st">"valueofButton2"</span></span>
<span id="cb10-12"><a href="#cb10-12" aria-hidden="true" tabindex="-1"></a>button3.value = <span class="st">"cats"</span></span>
<span id="cb10-13"><a href="#cb10-13" aria-hidden="true" tabindex="-1"></a>button3.x = -<span class="dv">1</span></span>
<span id="cb10-14"><a href="#cb10-14" aria-hidden="true" tabindex="-1"></a>button3.y = <span class="dv">120</span></span>
<span id="cb10-15"><a href="#cb10-15" aria-hidden="true" tabindex="-1"></a>button3.background = <span class="dv">223344</span></span>
<span id="cb10-16"><a href="#cb10-16" aria-hidden="true" tabindex="-1"></a>b4.type = <span class="st">"choice"</span></span>
<span id="cb10-17"><a href="#cb10-17" aria-hidden="true" tabindex="-1"></a>b4.value = <span class="st">"cats|dogs|Fish|cats|dogs|Fish|cats|dogs|Fish|cats|dogs|Fish"</span></span>
<span id="cb10-18"><a href="#cb10-18" aria-hidden="true" tabindex="-1"></a>b4.selectedIndex = <span class="dv">2</span></span>
<span id="cb10-19"><a href="#cb10-19" aria-hidden="true" tabindex="-1"></a>b4.x = -<span class="dv">1</span></span>
<span id="cb10-20"><a href="#cb10-20" aria-hidden="true" tabindex="-1"></a>b4.y = <span class="dv">120</span></span>
<span id="cb10-21"><a href="#cb10-21" aria-hidden="true" tabindex="-1"></a>b5.type = <span class="st">"list"</span></span>
<span id="cb10-22"><a href="#cb10-22" aria-hidden="true" tabindex="-1"></a>b5.value = <span class="st">"cats|dogs|Fish|cats|dogs|Fish|cats|dogs|Fish|cats|dogs|Fish|end|lol"</span></span>
<span id="cb10-23"><a href="#cb10-23" aria-hidden="true" tabindex="-1"></a>b5.x = -<span class="dv">1</span></span>
<span id="cb10-24"><a href="#cb10-24" aria-hidden="true" tabindex="-1"></a>b5.y = <span class="dv">120</span></span>
<span id="cb10-25"><a href="#cb10-25" aria-hidden="true" tabindex="-1"></a>b5.height = <span class="dv">120</span></span>
<span id="cb10-26"><a href="#cb10-26" aria-hidden="true" tabindex="-1"></a>b6.type = <span class="st">"text"</span></span>
<span id="cb10-27"><a href="#cb10-27" aria-hidden="true" tabindex="-1"></a>b6.value = <span class="st">"cats"</span></span>
<span id="cb10-28"><a href="#cb10-28" aria-hidden="true" tabindex="-1"></a>b6.length=<span class="dv">30</span></span>
<span id="cb10-29"><a href="#cb10-29" aria-hidden="true" tabindex="-1"></a>b6.x = -<span class="dv">1</span></span>
<span id="cb10-30"><a href="#cb10-30" aria-hidden="true" tabindex="-1"></a>b6.y = <span class="dv">120</span></span>
<span id="cb10-31"><a href="#cb10-31" aria-hidden="true" tabindex="-1"></a>b6.width = <span class="dv">50</span></span>
<span id="cb10-32"><a href="#cb10-32" aria-hidden="true" tabindex="-1"></a>b6.noFocus = <span class="dv">0</span></span>
<span id="cb10-33"><a href="#cb10-33" aria-hidden="true" tabindex="-1"></a><span class="co">' add buttons to the form</span></span>
<span id="cb10-34"><a href="#cb10-34" aria-hidden="true" tabindex="-1"></a>f.inputs << button1</span>
<span id="cb10-35"><a href="#cb10-35" aria-hidden="true" tabindex="-1"></a>f.inputs << button2</span>
<span id="cb10-36"><a href="#cb10-36" aria-hidden="true" tabindex="-1"></a>f.inputs << button3</span>
<span id="cb10-37"><a href="#cb10-37" aria-hidden="true" tabindex="-1"></a>f.inputs << b4</span>
<span id="cb10-38"><a href="#cb10-38" aria-hidden="true" tabindex="-1"></a>f.inputs << b5</span>
<span id="cb10-39"><a href="#cb10-39" aria-hidden="true" tabindex="-1"></a>f.inputs << b6</span>
<span id="cb10-40"><a href="#cb10-40" aria-hidden="true" tabindex="-1"></a>f.backgroundcolor = <span class="st">"green"</span></span>
<span id="cb10-41"><a href="#cb10-41" aria-hidden="true" tabindex="-1"></a><span class="co">' at this stage 'f' is just a plain user defined structure (map)</span></span>
<span id="cb10-42"><a href="#cb10-42" aria-hidden="true" tabindex="-1"></a><span class="co">' after calling FORM, 'f' becomes a system form object with three special functions</span></span>
<span id="cb10-43"><a href="#cb10-43" aria-hidden="true" tabindex="-1"></a><span class="co">' doEvents, close and refresh (see sokoban.bas for refresh)</span></span>
<span id="cb10-44"><a href="#cb10-44" aria-hidden="true" tabindex="-1"></a>f = <span class="fu">form</span>(f)</span>
<span id="cb10-45"><a href="#cb10-45" aria-hidden="true" tabindex="-1"></a><span class="co">' the string version of the form is JSON (see https://en.wikipedia.org/wiki/JSON)</span></span>
<span id="cb10-46"><a href="#cb10-46" aria-hidden="true" tabindex="-1"></a><span class="fu">TSAVE</span> <span class="st">"f.frm"</span>, f</span>
<span id="cb10-47"><a href="#cb10-47" aria-hidden="true" tabindex="-1"></a><span class="kw">while </span><span class="dv">1</span></span>
<span id="cb10-48"><a href="#cb10-48" aria-hidden="true" tabindex="-1"></a> <span class="co">' pump the system event queue</span></span>
<span id="cb10-49"><a href="#cb10-49" aria-hidden="true" tabindex="-1"></a> f.doEvents()</span>
<span id="cb10-50"><a href="#cb10-50" aria-hidden="true" tabindex="-1"></a> <span class="co">' process the event</span></span>
<span id="cb10-51"><a href="#cb10-51" aria-hidden="true" tabindex="-1"></a> in$ = <span class="kw">inkey</span></span>
<span id="cb10-52"><a href="#cb10-52" aria-hidden="true" tabindex="-1"></a> <span class="fu">at</span> <span class="dv">0</span>,<span class="dv">0</span></span>
<span id="cb10-53"><a href="#cb10-53" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span><span class="fu">len</span>(in$)><span class="dv">1</span> <span class="kw">then</span></span>
<span id="cb10-54"><a href="#cb10-54" aria-hidden="true" tabindex="-1"></a> flag= <span class="fu">asc</span>(<span class="fu">left</span>(in$,<span class="dv">1</span>))</span>
<span id="cb10-55"><a href="#cb10-55" aria-hidden="true" tabindex="-1"></a> keychar =<span class="fu">right</span>(in$,<span class="dv">1</span>)</span>
<span id="cb10-56"><a href="#cb10-56" aria-hidden="true" tabindex="-1"></a> n= <span class="fu">asc</span>(keychar)</span>
<span id="cb10-57"><a href="#cb10-57" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span>(flag == <span class="dv">1</span>)</span>
<span id="cb10-58"><a href="#cb10-58" aria-hidden="true" tabindex="-1"></a> ? <span class="st">"Ctrl : "</span>;keychar ; <span class="st">" "</span></span>
<span id="cb10-59"><a href="#cb10-59" aria-hidden="true" tabindex="-1"></a> <span class="kw">else</span> <span class="kw">if </span>(flag == <span class="dv">2</span>)</span>
<span id="cb10-60"><a href="#cb10-60" aria-hidden="true" tabindex="-1"></a> ? <span class="st">"Alt : "</span>; keychar</span>
<span id="cb10-61"><a href="#cb10-61" aria-hidden="true" tabindex="-1"></a> <span class="kw">else</span> <span class="kw">if </span>(flag == <span class="dv">3</span>)</span>
<span id="cb10-62"><a href="#cb10-62" aria-hidden="true" tabindex="-1"></a> ? <span class="st">"Ctrl+Alt: "</span>; keychar ; <span class="st">" "</span></span>
<span id="cb10-63"><a href="#cb10-63" aria-hidden="true" tabindex="-1"></a> <span class="kw">else</span></span>
<span id="cb10-64"><a href="#cb10-64" aria-hidden="true" tabindex="-1"></a> ? <span class="st">"Arrow: "</span>; n ; <span class="st">" "</span></span>
<span id="cb10-65"><a href="#cb10-65" aria-hidden="true" tabindex="-1"></a> <span class="kw">end if</span></span>
<span id="cb10-66"><a href="#cb10-66" aria-hidden="true" tabindex="-1"></a> <span class="kw">else</span></span>
<span id="cb10-67"><a href="#cb10-67" aria-hidden="true" tabindex="-1"></a> vkey = <span class="fu">asc</span>(in$)</span>
<span id="cb10-68"><a href="#cb10-68" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span>(vkey == <span class="dv">8</span>) <span class="kw">then</span></span>
<span id="cb10-69"><a href="#cb10-69" aria-hidden="true" tabindex="-1"></a> ? <span class="st">"backspace!"</span></span>
<span id="cb10-70"><a href="#cb10-70" aria-hidden="true" tabindex="-1"></a> <span class="kw">else</span> <span class="kw">if </span>(vkey == <span class="dv">127</span>) <span class="kw">then</span></span>
<span id="cb10-71"><a href="#cb10-71" aria-hidden="true" tabindex="-1"></a> ? <span class="st">"delete !"</span></span>
<span id="cb10-72"><a href="#cb10-72" aria-hidden="true" tabindex="-1"></a> <span class="kw">else</span></span>
<span id="cb10-73"><a href="#cb10-73" aria-hidden="true" tabindex="-1"></a> ? <span class="st">" key= "</span>; in$; <span class="st">" "</span>; vkey</span>
<span id="cb10-74"><a href="#cb10-74" aria-hidden="true" tabindex="-1"></a> <span class="kw">endif</span></span>
<span id="cb10-75"><a href="#cb10-75" aria-hidden="true" tabindex="-1"></a><span class="kw">endif</span></span>
<span id="cb10-76"><a href="#cb10-76" aria-hidden="true" tabindex="-1"></a><span class="kw">if </span>b6.value <> <span class="st">"cats"</span> <span class="kw">then</span> ? b6.value</span>
<span id="cb10-77"><a href="#cb10-77" aria-hidden="true" tabindex="-1"></a> <span class="kw">if </span>(<span class="fu">len</span>(f.value) > <span class="dv">0</span>) <span class="kw">then</span></span>
<span id="cb10-78"><a href="#cb10-78" aria-hidden="true" tabindex="-1"></a> <span class="kw">print</span> f.value; <span class="st">" "</span></span>
<span id="cb10-79"><a href="#cb10-79" aria-hidden="true" tabindex="-1"></a> <span class="kw">end if</span></span>
<span id="cb10-80"><a href="#cb10-80" aria-hidden="true" tabindex="-1"></a><span class="kw">wend</span></span>
<span id="cb10-81"><a href="#cb10-81" aria-hidden="true" tabindex="-1"></a>f.<span class="fu">close</span>()</span>
<span id="cb10-82"><a href="#cb10-82" aria-hidden="true" tabindex="-1"></a><span class="kw">func </span>HelloWorld</span>
<span id="cb10-83"><a href="#cb10-83" aria-hidden="true" tabindex="-1"></a>? <span class="st">"hello world"</span></span>
<span id="cb10-84"><a href="#cb10-84" aria-hidden="true" tabindex="-1"></a><span class="kw">end</span></span></code></pre></div>
<div class="lavenderBox">
<div class="header">Code samples using FORM</div>
<div class="linklist">
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/getting started/002 numeric variables.bas">002 numeric variables.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/games 1/7gables.bas">7gables.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/misc/Misc Bpf/Another center finder.bas">Another center finder.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/mathematics/bairstow.bas">bairstow.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/units/base64.bas">base64.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/games 1/betrayal: crows ii.bas">betrayal: crows ii.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/graphics 1/biorythms.bas">biorythms.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/applications/calc.bas">calc.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/games 3/checkers.bas">checkers.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/games 3/chess.bas">chess.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/misc/Misc Bpf/circumscribe triangle.bas">circumscribe triangle.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/graphics 1/conrec-sb-v01.bas">conrec-sb-v01.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/games 1/dogstar5.bas">dogstar5.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/network/duckduckgo.bas">duckduckgo.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/applications/filemanager.bas">filemanager.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/mathematics/first factors mga.bas">first factors mga.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/graphics 4/fizzle2.bas">fizzle2.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/code demos/form demo.bas">form demo.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/gp utm package/gridareaplot.bas">gridareaplot.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/games 1/illuminati.bas">illuminati.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/index.bas">index.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/mathematics/leastq.bas">leastq.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/business/loancalc.bas">loancalc.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/graphics 2/mandelbrot explorer.bas">mandelbrot explorer.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/mathematics/matrix_solve.bas">matrix_solve.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/applications/memoryTest.bas">memoryTest.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/games 1/memorytest.bas">memorytest.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/geometry/middle finder.bas">middle finder.bas </a>
<a target="_github" href="https://raw.githubusercontent.com/smallbasic/smallbasic.samples/master/applications/navigation.bas">navigation.bas </a>
</div>
</div>
<div class="lavenderBox">
<div class="header">Console</div>
<div class="linklist">
<a href="/reference/521.html">AT </a>
<a href="/reference/522.html">BEEP </a>
<a href="/reference/538.html">CAT </a>
<a href="/reference/524.html">CLS </a>
<a href="/reference/1015.html">DEFINEKEY </a>
<a href="/reference/525.html"><strong>FORM</strong> </a>
<a href="/reference/539.html">INKEY </a>
<a href="/reference/527.html">INPUT </a>
<a href="/reference/528.html">LINEINPUT </a>
<a href="/reference/529.html">LINPUT </a>
<a href="/reference/530.html">LOCATE </a>
<a href="/reference/531.html">LOGPRINT </a>
<a href="/reference/532.html">NOSOUND </a>
<a href="/reference/533.html">PEN </a>
<a href="/reference/534.html">PLAY </a>
<a href="/reference/535.html">PRINT </a>
<a href="/reference/536.html">SOUND </a>
<a href="/reference/540.html">TAB </a>
</div>
</div>
</div>
<div class="pagefooter">
This page was last edited on Mon, 12 Feb 2024 21:25:54 +0100
|
<a href="https://en.wikipedia.org/wiki/Markdown" target="_blank" rel="nofollow">Markdown</a>
processed with
<a href="https://pandoc.org/MANUAL.html#pandocs-markdown" target="_blank" rel="nofollow">pandoc 3.1.12.1</a>
</div>
</div>
</div>
</body>
</html>