<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss">
 	<channel>
		<title>NSBasicCE Tutorial | VisualNewt Software | Serg Koren</title>
		<link>http://www.visualnewt.com/Products/windows_mobile/nsbasicce_tutorial/</link>
		<description></description>
		<language>en</language>
		<lastBuildDate>Sat, 16 Feb 2008 20:18:27 -0500</lastBuildDate>
		<docs>http://blogs.law.harvard.edu/tech/rss</docs>
		<generator>Sandvox Pro 1.2.6</generator>
		<image>
			<url>http://www.visualnewt.com/_Media/vns_rss.jpeg</url>
			<title>VisualNewt Software Logo</title>
			<link>http://www.visualnewt.com/Products/windows_mobile/nsbasicce_tutorial/</link>
			<width>144</width>
			<height>56</height>
		</image>
		<item>
			<title>ARTICLE 13-PRINT, REDIM, and the TEXTBOX</title>
			<link>http://www.visualnewt.com/Products/windows_mobile/nsbasicce_tutorial/article_13-print_redim_and_.html</link>
			<description>
&lt;p&gt;&lt;span style=&quot;font-family: Times; font-size: 16px;&quot;&gt;&lt;span style=&quot;font-family: 'Trebuchet MS';&quot;&gt;&lt;b&gt;Programming Using NSBasicCE&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;span style=&quot;font-family: Times; font-size: 16px;&quot;&gt;&lt;blockquote&gt;&lt;br /&gt;
&lt;h4&gt;ARTICLE 13-PRINT, REDIM, and the TEXTBOX&lt;/h4&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;font size=&quot;-2&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;All content (c)1999 Serg Koren.&lt;/span&gt;&lt;br style=&quot;font-size: 12px;&quot; /&gt;
&lt;span style=&quot;font-size: 12px;&quot;&gt;All rights reserved.&lt;/span&gt;&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
Welcome to the thirteenth installment of NSBasicCE. &lt;br /&gt;
&lt;br /&gt;
This time around we discuss the PRINT and REDIM statements, and the TEXTBOX object a hodgepodge of miscellaneous commands.&lt;/p&gt;
&lt;p&gt;If this article is a bit disjoint, please excuse me since I'm trying to figure out where I left off ;-)&lt;br /&gt;
  &lt;br /&gt;
&lt;strong&gt;Leftovers from Last Time&lt;/strong&gt; &lt;br /&gt;
  &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
I asked you to modify the Colors program from last time to:&lt;br /&gt;
- Add a PictureBox object and draw a filled box of the given color whenever the user Adds a color to the list. (Just have one colored box in the PictureBox at any given time. Draw the last added color.)&lt;br /&gt;
- When the user taps a key on the keyboard. Draw the letter inside the picturebox.&lt;br /&gt;
- When the user taps on the colored box, display a message box showing the name of the color&lt;br /&gt;
&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;' I won't reproduce the entire program (check the archives if you missed it),
'  but just give you the changes.
' Add another global array to hold actual colors instead of color names...
DIM vbColors(7) ' will be loaded with color values
DIM TheColorText ' the color to draw box&lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;' Sub to create our PictureBox object
SUB CreateMyPictureBox
     ADDOBJECT &quot;PictureBox&quot;,&quot;MyPictureBox&quot;,10,100,110,200
END SUB&lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;' Sub to draw a filled box of a given color inside the picturebox
' Note that to draw a box you use the DrawLine method of the PictureBox (see manual)
SUB DrawFilledBox(WhichColor)
     MyPictureBox.Cls ' clear the old stuff out of the picture box
     MyPictureBox.DrawLine 110,110,400,400, Which, True, True       ' The last two parameters determine that a box is drawn and that it is filled
END SUB&lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;
' Subroutine to draw a character in our PictureBox
' This is how you would draw a character (or any string) in the picture box, but NOT when you tap a character on the keyboard.
SUB DrawCharacter(Which)
     MyPictureBox.Cls 'clear the old stuff in the picture box
     MyPictureBox.DrawText Which
END SUB&lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;
' Modify SETUPCOLORS to create our vbColor array
SUB SETUPCOLORS
&amp;lt;... leave the original code in here&amp;gt;
     ' Note that you have to create some colors yourself since they are not defined...see manual
     vbColors(1) = vbRed
     vbColors(2) = 256 + (128 * 256) + (64 * 65536)) ' orange RGB values
     vbColors(3) = vbYellow
     vbColors(4) = vbGreen
     vbColors(5) = vbBlue
     vbColors(6) = 128 + (0 * 256) + (128 * 65536)) ' indigo RGB values
     vbColors(7) = 128 + (0 * 256) + (255 * 65536)) ' violet RGB values
END SUB &lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;' Modify our Add handler to read...
SUB Add_Click
     DIM TheColor ' color value to draw the box in
     ' add the selected listbox item to the end of the listbox list
     TheColorText = MyListBox.List(MyListBox.ListIndex) ' MyListBox.List() returns the text in the list
     MyListBox.AddItem TheColorText
     TheColor = vbColors(MyList.ListIndex) ' get the color values to use in drawing the box
     DrawFilledBox(TheColor)
END SUB &lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;' Our handler when the user taps a key...
' NOTE: You have to tap the picturebox first to make it the active control before typing.
SUB MyPictureBox_KeyPress(Key)
     DrawCharacter(CHR(Key)) ' Key is a key value which must be converted to a character via the CHR function
END SUB &lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;' Our handler to display the name of the drawn color when the user taps on the PictureBox
SUB MyPictureBox_MouseDown
     MSGBOX TheColorText ' draw the saved name of the last color drawn (even if we've erased the PictureBox)
END SUB
 &lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;PRINT&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
The PRINT statement is mildly useful in displaying text on the main output screen and it will write on top of everything else in your program. Unfortunately, there's no way to specify where to put the text it writes. The PRINT system is a holdover from old-style BASICs. It's syntax is straight-forward. Just follow the PRINT statement with a comma sepated list of things to display:&lt;br /&gt;
 &lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt; PRINT 1, &quot;test&quot;, Colors(1)&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
You're probably better off using other controls or using the MSGBOX.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;REDIM&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
REDIM is a useful statement when you don't know the size of an array when the program starts. It's also useful if you need to reclaim space used by an array because you're done with it and your program is running out of memory. To use it you declare a variable that you want to use as an array, but you declare it normally (not as an array).&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt; DIM MyFutureArray&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
Now lets say you've figured out that you need an array that is 200 items in size. You use the REDIM command to resize the variable...&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;REDIM MyFutureArray(200)&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
Later if you find out your actually needed 2000 you can do a:&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;REDIM MyFutureArray(2000)&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
in your program.&lt;br /&gt;
To free up the memory used by the array (assuming you don't need it anymore) you can use REDIM as follows:&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;REDIM MyFutureArray(0)&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
You can also do things like:&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
REDIM MyFutureArray(100,100)&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
You probably won't use REDIM often, but it's useful in your NSBasic bag of tricks.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;strong&gt;TEXTBOX&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
The TEXTBOX object is used to display an editable text field on a form. Up until now we've been using INPUTBOX to get user input, but the TEXTBOX is much more natural. Creating a TEXTBOX object is identical to other objects, so we won't go over that. The TEXTBOX object has a few new properties that deal with what text is selected.&lt;br /&gt;
selLength is a property that returns the length in characters of the selected text.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
selStart returns the position of the first selected character.&lt;br /&gt;
selText returns the actual selected text.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
The only other new property you have to worry about is MutliLine which is a Boolean (TRUE or FALSE). If it's set to TRUE, the TEXTBOX will allow the user to enter carriage returns and multiple lines of text. Otherwise, the TEXTBOX will only allow a single line of text.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
That's it for this time around. Next time we'll go over TIME, Time, TIMEVALUE and TIMESERIAL In other words, we'll deal with statements, functions, and objects dealing with time.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
 For next time&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
Something simple! Write a program with a TEXTBOX and CommandButton. When tapped the button should display the selected text, and its length.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Cheers!&lt;/p&gt;
&lt;/span&gt;
			</description>
			<pubDate>Wed, 11 Apr 2007 21:34:22 -0400</pubDate>
			<guid>http://www.visualnewt.com/Products/windows_mobile/nsbasicce_tutorial/article_13-print_redim_and_.html</guid>
		</item>
		<item>
			<title>ARTICLE 12--FOR EACH, INSTR, AND THE PICTUREBOX OBJECT</title>
			<link>http://www.visualnewt.com/Products/windows_mobile/nsbasicce_tutorial/article_12--for_each_instr_.html</link>
			<description>
&lt;p&gt;&lt;span style=&quot;font-family: Times; font-size: 16px;&quot;&gt;&lt;blockquote&gt;&lt;p&gt;&lt;span style=&quot;font-family: 'Trebuchet MS';&quot;&gt;&lt;b&gt;Programming Using NSBasicCE&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;br /&gt;
&lt;h4&gt;ARTICLE 12--FOR EACH, INSTR, AND THE PICTUREBOX OBJECT&lt;/h4&gt;
&lt;/blockquote&gt;
&lt;font size=&quot;-2&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;All content (c)1999 Serg Koren.&lt;/span&gt;&lt;br style=&quot;font-size: 12px;&quot; /&gt;
&lt;span style=&quot;font-size: 12px;&quot;&gt;All rights reserved.&lt;/span&gt;&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
Welcome to the &quot;dozenth&quot; installment of NSBasicCE. &lt;br /&gt;
This time around we discuss the &quot;EACH&quot; version of the FOR NEXT loop, the PRINT statement and the PictureBox object.&lt;br /&gt;
  &lt;br /&gt;
&lt;strong&gt;Leftovers from Last Time&lt;/strong&gt; &lt;br /&gt;
  &lt;br /&gt;
 &lt;br /&gt;
Last time around we talked about getting loops and asked you to modify the answer to the last problem to use loops. Here is the code from last time that you had to start with:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;'-------------code starts here&lt;/p&gt;
&lt;p&gt;'&lt;/p&gt;
&lt;p&gt;' Article 10&lt;/p&gt;
&lt;p&gt;'&lt;/p&gt;
&lt;p&gt;OPTION EXPLICIT&lt;/p&gt;
&lt;p&gt;DIM Colors(7)&lt;/p&gt;
&lt;p&gt;' our color array&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;'-------------- create our UI&lt;/p&gt;
&lt;p&gt;' create a listbox&lt;/p&gt;
&lt;p&gt;SUB CreateMyListbox&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;ADDOBJECT &quot;ListBox&quot;,&quot;MyListBox&quot;,120,10,100,120 ' leave room for label&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;' load the colors into the listbox...assumes you've set up the array first&lt;/p&gt;
&lt;p&gt;MyListBox.AddItem Colors(1)&lt;/p&gt;
&lt;p&gt;MyListBox.AddItem Colors(2)&lt;/p&gt;
&lt;p&gt;MyListBox.AddItem Colors(3)&lt;/p&gt;
&lt;p&gt;MyListBox.AddItem Colors(4)&lt;/p&gt;
&lt;p&gt;MyListBox.AddItem Colors(5)&lt;/p&gt;
&lt;p&gt;MyListBox.AddItem Colors(6)&lt;/p&gt;
&lt;p&gt;MyListBox.AddItem Colors(7)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;END SUB&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;' create a label&lt;/p&gt;
&lt;p&gt;SUB CreateMyLabel&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;ADDOBJECT &quot;Label&quot;,&quot;MyLabel&quot;,35,5,80,20 ' to the right of the listbox&lt;/p&gt;
&lt;p&gt;MyLabel.Caption = &quot;Colors&quot;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;END SUB&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;' create our Remove commandbutton&lt;/p&gt;
&lt;p&gt;SUB CreateRemoveCommandButton&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;ADDOBJECT &quot;CommandButton&quot;,&quot;Remove&quot;,10,35,100,20&lt;/p&gt;
&lt;p&gt;Remove.Caption = &quot;Remove&quot;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;END SUB&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;' create our Add commandbutton&lt;/p&gt;
&lt;p&gt;SUB CreateAddCommandButton&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;ADDOBJECT &quot;CommandButton&quot;,&quot;Add&quot;,10,65,100,20&lt;/p&gt;
&lt;p&gt;Add.Caption = &quot;Add&quot;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;END SUB&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;' create FindMissing commandbutton&lt;/p&gt;
&lt;p&gt;SUB CreateFindMissingCommandButton&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;ADDOBJECT &quot;CommandButton&quot;,&quot;FindMissing&quot;,10,95,100,20&lt;/p&gt;
&lt;p&gt;FindMissing.Caption = &quot;Find Missing&quot;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;END SUB&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;' create FindDuplicates commandbutton&lt;/p&gt;
&lt;p&gt;SUB CreateFindDuplicatesCommandButton&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;ADDOBJECT &quot;CommandButton&quot;,&quot;FindDuplicates&quot;,10,125,100,20&lt;/p&gt;
&lt;p&gt;FindDuplicates.Caption = &quot;Find Duplicates&quot;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;END SUB&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;'----------------event handlers&lt;/p&gt;
&lt;p&gt;' Our Remove handler&lt;/p&gt;
&lt;p&gt;SUB Remove_click&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;' remove the selected listbox item&lt;/p&gt;
&lt;p&gt;MyListBox.RemoveItem MyListBox.ListIndex&lt;/p&gt;
&lt;p&gt;' MyListBox.ListIndex returns the number (array index) of the selected item&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;END SUB&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;' Our Add handler&lt;/p&gt;
&lt;p&gt;SUB Add_click&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;' add the selected listbox item to the end of the listbox list&lt;/p&gt;
&lt;p&gt;MyListBox.AddItem MyListBox.List(MyListBox.ListIndex)&lt;/p&gt;
&lt;p&gt;' MyListBox.List( ) returns the text in the list&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;END SUB&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;' Find missing event handler&lt;/p&gt;
&lt;p&gt;SUB FindMissing_click&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;' you probably got stuck trying to figure out how to do this... don't worry this was a trick problem.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;END SUB&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;' Find duplicates event handler&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;SUB FindDuplicates_click&lt;/p&gt;
&lt;p&gt;' you probably got stuck trying to figure out how to do this... don't worry this was a trick problem.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;END SUB&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;'----------------main routines here&lt;/p&gt;
&lt;p&gt;' set up our color array&lt;/p&gt;
&lt;p&gt;SUB SETUPCOLORS&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Colors(1) = &quot;Red&quot;&lt;/p&gt;
&lt;p&gt;Colors(2) = &quot;Orange&quot;&lt;/p&gt;
&lt;p&gt;Colors(3) = &quot;Yellow&quot;&lt;/p&gt;
&lt;p&gt;Colors(4) = &quot;Green&quot;&lt;/p&gt;
&lt;p&gt;Colors(5) = &quot;Blue&quot;&lt;/p&gt;
&lt;p&gt;Colors(6) = &quot;Indigo&quot;&lt;/p&gt;
&lt;p&gt;Colors(7) = &quot;Violet&quot;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;END SUB&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;' set up our user interface&lt;/p&gt;
&lt;p&gt;SUB SETUPUI&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;CreateMyListBox&lt;/p&gt;
&lt;p&gt;CreateRemoveCommandButton&lt;/p&gt;
&lt;p&gt;CreateAddCommandButton&lt;/p&gt;
&lt;p&gt;CreateFindMissingCommandButton&lt;/p&gt;
&lt;p&gt;CreateFindDuplicatesCommandButton&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;END SUB&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;SUB INITIALIZE&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;SETUPCOLORS ' this has to be done first because its used by CreateMyListBox&lt;/p&gt;
&lt;p&gt;SETUPUI&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;END SUB&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;SUB MAIN&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;INITIALIZE&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;END SUB&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;MAIN ' our normal kickstart&lt;/p&gt;
&lt;p&gt;'-------------code ends here&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;A hint that you need a loop are sequences of lines that are identical apart from the index into an array. In this example there are two subroutines that are ripe for loops: CreateMyListBox and SETUPCOLORS.&lt;br /&gt;
For CreateMyListBox replace the existing one with:&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;     ' create a listbox
     SUB CreateMyListbox   &lt;/tt&gt;&lt;/pre&gt;
&lt;blockquote&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;       DIM I ' our index for our FOR loop
       ADDOBJECT &quot;ListBox&quot;,&quot;MyListBox&quot;,120,10,100,120 ' leave        room for label
       ' load the colors into the listbox...assumes you've set up the array first
       FOR I = 1 TO 7 ' loop through all of our colors
       MyListBox.AddItem Colors(I) ' add a row with the proper color
       NEXT I&lt;/tt&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;     END SUB    &lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;SETUPCOLORS is harder to figure out. That is because we need to figure out how to get the hardcoded colors into an indexable list. But it seems by hardcoding it we already have, so do we need to put it into a loop?&lt;br /&gt;
No, not really. The existing code is good enough for most purposes. Personally, (a style thing) I still don't like the fact that the colors are actually hidden somewhere in the code, which makes it harder to find if say we want to add a color &quot;Gray&quot; for instance.&lt;br /&gt;
What I would do is extract the actual colors into a global string:&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;     DIM MasterColors
     DIM MaxColors
     MaxColors = 7 'number of colors
     MasterColors = &quot;Red,Orange,Yellow,Green,Blue,Indigo,Violet,&quot; ' note the comma at the end...we need this&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
and then in the SETUPCOLORS subroutine I'd pull the appropriate substring out and assign it to the array. But to do this we need to know about another string function. We talked earlier about LEFT, RIGHT, and MID, now we need to learn about something called:&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;INSTR and INSTRREV&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;INSTR and INSTRREV are often used in combination with LEFT, RIGHT, and MID. INSTR lets you find where a certain substring starts, starting from the left end, INSTRREV does the same, but starts from the right end of the string (last character). How do they find a substring?&lt;br /&gt;
If you refer to the manual you see, that INSTR and INSTRREV are functions that are called using:&lt;br /&gt;
INSTR([start],&amp;lt;main string&amp;gt;,&amp;lt;delimiter)&lt;br /&gt;
[start] is an optional chaaracter position where to start searcing (say start at character 3). &amp;lt;main string&amp;gt; is the string we are searching through (in our case MasterColors), and &amp;lt;delimiter&amp;gt; is a string that we are looking for.&lt;br /&gt;
For example, the following code:&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;     DIM A
     DIM I
     A = &quot;ABCDEFABCDEF&quot;
     I = INSTR(A,&quot;B&quot;) ' assume [start] is 0, find B
     MSGBOX I
     I = INSTR(I+1,&quot;B&quot;) ' find the next occurance of B
     MSGBOX I&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
would return 2, and 8 In our assignment, MasterColors has colors separated by commas, so &quot;,&quot; would be a natural delimiter. So to find the end of a string we search for a comma. That's why we need the comma at the end in MasterColors, it makes finding the last element easier. How do we find the start of the next string? It's the location of the last comma plus one.&lt;br /&gt;
So our code becomes:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;SUB SETUPCOLORS
     DIM I ' Index into our array and FOR loop
     DIM J ' Index into our MasterColors string
     DIM J1 ' last occurance of a comma
     DIM TempColor ' a string that holds an actual color once we parse it from MasterColors
     J = 0 ' Initialize our index
     J1 = 0
     FOR I = 1 TO MaxColors ' process each color
     	J = INSTR(J1 + 1,MasterColors,&quot;,&quot;) ' find the next occurance of the , separator
    	 	Temp = MID(MasterColors,,J,J1 - J) ' extract the actual color between commas (starting at J and for length J1 -J)
    	 	Colors(I) = Temp ' assign the actual color to our array now.
     NEXT
END SUB&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
It looks more complicated than the original (and it is), but if you need to add more colors (or subtract colors) all you have to do is change the value of MaxColors and our MasterColors string, and everything continues to work properly!&lt;br /&gt;
The lines:&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;     J = INSTR(J1 + 1,x,&quot;,&quot;)
     Temp = MID(x,,J,J1 - J)
     y(I) = Temp &lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
are what are known as a &quot;pattern&quot; in computer jargon. A &quot;pattern&quot; is merely a programming idiom (like an English idiom...if you don't know what &quot;idiom&quot; means, look it up.) or a way of programming a common task. Something you'll do again and again. And what this tells me (and should you at this point) is that it belongs in its own subroutine or function...I'll leave writing this function as an exercise for you to solve. I have one that I use all the time to parse a string delimited by commas. It's a very useful routine, and you should have one in your own bag of tricks!&lt;br /&gt;
On to our next topic:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;FOR EACH..NEXT&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
The FOR EACH statement is a very useful way of going through an array and doing something for each (hence the name) element in the array. It's syntax is easy:&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;     FOR EACH &lt;thing&gt; IN &lt;array&gt;
     ....do stuff
     NEXT&lt;/array&gt;&lt;/thing&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;     &lt;thing&gt; is the item at a given index into the array. Usually you give it a more descriptive name than I, or J (which is typical for a normal FOR      NEXT). &lt;array&gt; is the array you want to do things to. For example lets      say you want to have an array of 100 numbers where the value of the element      is the index value. That is, element 33 has the number 33 in it, the element      56 has 56, etc.
     DIM NumberArray(100) ' our array
     DIM I ' a number
     I = 0
     FOR EACH Number IN NumberArray ' Number automatically becomes the element at a given index.
    	 	Number = I
     	I = I + 1
     NEXT
     Yes:
     FOR I = 0 TO 100
     	NumberArray(I) = I
     NEXT
&lt;/array&gt;&lt;/thing&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;br /&gt;
is better, I just made up the example to show you the differences. The FOR EACH doesn't require you to DIM the index., the normal FOR does. The FOR EACH is a bit more readable (understandable) than the normal FOR. Here's another example. The FOR EACH doesn't use a subscribe (index) into the array to get an element, the FOR does. Let's print out our Colors array from the code above:&lt;br /&gt;
 &lt;br /&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;     FOR EACH Color in Colors
          PRINT Color
     NEXT
      &lt;/tt&gt;&lt;/pre&gt;
&lt;br /&gt;
is a lot easier to program and understand than:&lt;br /&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;     FOR I = 1 TO MaxColors
          PRINT Colors(I)
     NEXT&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
 &lt;br /&gt;
That's the FOR EACH loop. Once you get used to using it you'll like it. Now to our object of the day.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;strong&gt;PICTUREBOX&lt;/strong&gt;&lt;/p&gt;
&lt;br /&gt;
A PictureBox is one of the most complex objects you'll deal with. It's complexity lies in the different properties, events, and methods it allows you to manipulate. At its core, a PictureBox allows you to draw text and graphics in a contained area on the screen.&lt;br /&gt;
You already know how to create one:&lt;br /&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;     ADDOBJECT &quot;PictureBox&quot;,&quot;MyPictureBox,&quot;10,10,200,200&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
I suggest first reading the manual to get a feel for the different things you can do with a PictureBox. Then try to write a program that uses them. Here's a quick run through of the things a PictureBox has:&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
Properties:&lt;br /&gt;
• BorderStyle - 0, blends with the window, 1, has a border.&lt;br /&gt;
• DrawWidth - a number specifying how thick lines will draw.&lt;br /&gt;
• FillColor - enclosed polygons (circles, rectangles, etc. can be drawn with a single command) can be filled with a color&lt;br /&gt;
• FillStyle - 0 solid, 1 transparent&lt;br /&gt;
• FontTransparent - True/False (no I don't know why this isn't 0,1)&lt;br /&gt;
• Picture - you can pass in the name of a graphics file (it has to be a *.bmp) and the picture will automatically draw itself into your picturebox.&lt;br /&gt;
• Scaleheight/Width - you can specify how things get scaled in the picturebox&lt;br /&gt;
• ScaleLeft/Top - left and top edges of the object&lt;br /&gt;
• ScaleMode - this is a MS thingy. Most of the time you want to set this to 3 (pixels) otherwise you'll wonder why things don't draw the way you expect. For more info, find some MS documentation online.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
Methods:&lt;br /&gt;
• Cls - Erases the picturebox contents&lt;br /&gt;
• DrawCircle - Draws a circle, or ellipse. You can specify the radius, color, etc.&lt;br /&gt;
• DrawLine - This lets you specify a line or set of lines. You can also set a flag to specify you want to draw a box (rectangle or square).&lt;br /&gt;
• DrawPicture - lets you draw and manipulate a bitmap image file (*.bmp)&lt;br /&gt;
• DrawPoint - just what it says. Turn on a single pixel.&lt;br /&gt;
• DrawText - pretty useless since it doesn't let you specify WHERE in the box you want to draw the text. Might be useful for debugging.&lt;br /&gt;
• Refresh - redraw the contents of the PictureBox (if something needs to be redone because something covered the PictureBox say.)&lt;br /&gt;
• ScaleX, ScaleY,SetScale - lets you convert scale values&lt;br /&gt;
• TextHeight, TextWidth - Returns the height and width of the heighest or widest lines of text. Used with DrawText.&lt;br /&gt;
Events:&lt;br /&gt;
• KeyDown - key is pressed&lt;br /&gt;
• KeyUp - key is released&lt;br /&gt;
• KeyPress - KeyDown followed by KeyUp&lt;br /&gt;
• MouseDown, MouseUp - mouse clicks&lt;br /&gt;
• MouseMove - MouseDown and then you move the mouse (like a drag).&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
Yes the number of Properties, Methods, and Events is large, but taken individually, they aren't too confusing. The best way to learn about the PictureBox is to use it. So...&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
 For next time&lt;/p&gt;
&lt;p&gt;Using the Colors program,&lt;br /&gt;
- Add a PictureBox object and draw a filled box of the given color whenever the user Adds a color to the list. (Just have one colored box in the PictureBox at any given time. Draw the last added color.)&lt;br /&gt;
- When the user taps a key on the keyboard. Draw the letter inside the picturebox.&lt;br /&gt;
- When the user taps on the colored box, display a message with the name of the color being tapped.&lt;br /&gt;
 &lt;br /&gt;
We'll also go over the PRINT statement, the REDIM statement, and the TextBox object!&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Cheers!&lt;/p&gt;
&lt;p /&gt;
			</description>
			<pubDate>Wed, 11 Apr 2007 21:33:33 -0400</pubDate>
			<guid>http://www.visualnewt.com/Products/windows_mobile/nsbasicce_tutorial/article_12--for_each_instr_.html</guid>
		</item>
		<item>
			<title>ARTICLE 11-DEJA-VU AGAIN</title>
			<link>http://www.visualnewt.com/Products/windows_mobile/nsbasicce_tutorial/article_11-deja-vu_again.html</link>
			<description>
&lt;p&gt;&lt;span style=&quot;font-family: Times; font-size: 16px;&quot;&gt;&lt;span style=&quot;font-family: 'Trebuchet MS';&quot;&gt;&lt;b&gt;Programming Using NSBasicCE&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;span style=&quot;font-family: Times; font-size: 16px;&quot;&gt;&lt;blockquote&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;ARTICLE 11-DEJA-VU AGAIN&lt;/h4&gt;
&lt;/blockquote&gt;
&lt;font size=&quot;-2&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;All content (c)1999 Serg Koren.&lt;/span&gt;&lt;br style=&quot;font-size: 12px;&quot; /&gt;
&lt;span style=&quot;font-size: 12px;&quot;&gt;All rights reserved.&lt;/span&gt;&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
  &lt;br /&gt;
Welcome to the eleventh installment of NSBasicCE.&lt;br /&gt;
This time around we talk about getting your programs to repeat commands, and we talk about our widget, the option button. &lt;br /&gt;
  &lt;br /&gt;
&lt;strong&gt;Leftovers from Last Time&lt;/strong&gt; &lt;br /&gt;
  &lt;br /&gt;
Last time around we talked about getting your program to make decisions and I asked you to write a program, &lt;br /&gt;
  &lt;br /&gt;
That has: &lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;A Listbox&lt;/li&gt;
&lt;li&gt;A Label next to the listbox labelling it &quot;Colors&quot;&lt;/li&gt;
&lt;li&gt;An array of colors: &quot;Red&quot;, &quot;Orange&quot;, &quot;Yellow&quot;, &quot;Green&quot;, &quot;Blue&quot;, &quot;Indigo&quot;, &quot;Violet&quot;&lt;/li&gt;
&lt;li&gt;A CommandButton labelled &quot;Remove&quot;&lt;/li&gt;
&lt;li&gt;A CommandButton labelled &quot;Add&quot;&lt;/li&gt;
&lt;li&gt;A CommandButton labelled &quot;Find Missing&quot;&lt;/li&gt;
&lt;li&gt;A CommandButton labelled &quot;Find Duplicates&quot;&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;br /&gt;
The program should:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Load the colors into the listbox&lt;/li&gt;
&lt;li&gt;When the user clicks on the &quot;Remove&quot; button , the selected color in the listbox is removed from the list.&lt;/li&gt;
&lt;li&gt;When the user clicks on the &quot;Add&quot; button, the selected color is added to the end (bottom) of the listbox.&lt;/li&gt;
&lt;li&gt;When the user clicks on the &quot;Find Missing&quot; button, the program should list all the missing colors in the listbox from the master set.&lt;/li&gt;
&lt;li&gt;When the user clicks on the &quot;Find Duplicates&quot; button, the program should list all the colors in the listbox that occur more than once.&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;p&gt;  &lt;br /&gt;
Here's my take on the solution: &lt;br /&gt;
&lt;br /&gt;
&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;div&gt;'-------------code starts here
'
' Article 10
'
OPTION EXPLICIT
DIM Colors(7)' our color array
'-------------- create our UI
' create a listbo
SUB CreateMyListbox
   ADDOBJECT &quot;ListBox&quot;,&quot;MyListBox&quot;,120,10,100,120 ' leave        room for label
   ' load the colors into the listbox...assumes you've set up the array first
   MyListBox.AddItem Colors(1)
   MyListBox.AddItem Colors(2)
   MyListBox.AddItem Colors(3)
   MyListBox.AddItem Colors(4)
   MyListBox.AddItem Colors(5)
   MyListBox.AddItem Colors(6)
   MyListBox.AddItem Colors(7)
END SUB&lt;/div&gt;
&lt;div&gt;
' create a label
SUB CreateMyLabel
   ADDOBJECT &quot;Label&quot;,&quot;MyLabel&quot;,35,5,80,20 ' to the right        of the listbox
   MyLabel.Caption = &quot;Colors&quot;
END SUB&lt;/div&gt;
&lt;div&gt;
' create our Remove commandbutton
SUB CreateRemoveCommandButton
   ADDOBJECT &quot;CommandButton&quot;,&quot;Remove&quot;,10,35,100,20
   Remove.Caption = &quot;Remove&quot;
END SUB&lt;/div&gt;
&lt;div&gt;
' create our Add commandbutton
SUB CreateAddCommandButton
   ADDOBJECT &quot;CommandButton&quot;,&quot;Add&quot;,10,65,100,20
   Add.Caption = &quot;Add&quot;
END SUB &lt;/div&gt;
&lt;div&gt;&lt;br class=&quot;webkit-block-placeholder&quot; /&gt;
&lt;/div&gt;
&lt;div&gt;' create FindMissing commandbutton
SUB CreateFindMissingCommandButton
   ADDOBJECT &quot;CommandButton&quot;,&quot;FindMissing&quot;,10,95,100,20
   FindMissing.Caption = &quot;Find Missing&quot;
END SUB &lt;/div&gt;
&lt;div&gt;&lt;br class=&quot;webkit-block-placeholder&quot; /&gt;
&lt;/div&gt;
&lt;div&gt;' create FindDuplicates commandbutton
SUB CreateFindDuplicatesCommandButton
   ADDOBJECT &quot;CommandButton&quot;,&quot;FindDuplicates&quot;,10,125,100,20
   FindDuplicates.Caption = &quot;Find Duplicates&quot;
END SUB &lt;/div&gt;
&lt;div&gt;&lt;br class=&quot;webkit-block-placeholder&quot; /&gt;
&lt;/div&gt;
&lt;div&gt;'----------------event handlers
' Our Remove handler
SUB Remove_click
   ' remove the selected listbox item
   MyListBox.RemoveItem MyListBox.ListIndex
   ' MyListBox.ListIndex returns the number (array index) of the selected        item
END SUB &lt;/div&gt;
&lt;div&gt;&lt;br class=&quot;webkit-block-placeholder&quot; /&gt;
&lt;/div&gt;
&lt;div&gt;' Our Add handler
SUB Add_click
   ' add the selected listbox item to the end of the listbox list
   MyListBox.AddItem MyListBox.List(MyListBox.ListIndex)
   ' MyListBox.List( ) returns the text in the list
END SUB &lt;/div&gt;
&lt;div&gt;&lt;br class=&quot;webkit-block-placeholder&quot; /&gt;
&lt;/div&gt;
&lt;div&gt;' Find missing event handler
SUB FindMissing_click
   ' you probably got stuck trying to figure out how to do this... don't worry this was a trick problem.
END SUB &lt;/div&gt;
&lt;div&gt;&lt;br class=&quot;webkit-block-placeholder&quot; /&gt;
&lt;/div&gt;
&lt;div&gt;' Find duplicates event handler
SUB FindDuplicates_click
   ' you probably got stuck trying to figure out how to do this... don't worry this was a trick problem.
END SUB &lt;/div&gt;
&lt;div&gt;&lt;br class=&quot;webkit-block-placeholder&quot; /&gt;
&lt;/div&gt;
&lt;div&gt;'----------------main routines here
' set up our color array
SUB SETUPCOLORS
   Colors(1) = &quot;Red&quot;
   Colors(2) = &quot;Orange&quot;
   Colors(3) = &quot;Yellow&quot;
   Colors(4) = &quot;Green&quot;
   Colors(5) = &quot;Blue&quot;
   Colors(6) = &quot;Indigo&quot;
   Colors(7) = &quot;Violet&quot;
END SUB &lt;/div&gt;
&lt;div&gt;&lt;br class=&quot;webkit-block-placeholder&quot; /&gt;
&lt;/div&gt;
&lt;div&gt;' set up our user interface
SUB SETUPUI
   CreateMyListBox
   CreateRemoveCommandButton
   CreateAddCommandButton
   CreateFindMissingCommandButton
   CreateFindDuplicatesCommandButton
END SUB &lt;/div&gt;
&lt;div&gt;&lt;br class=&quot;webkit-block-placeholder&quot; /&gt;
&lt;/div&gt;
&lt;div&gt;SUB INITIALIZE
   SETUPCOLORS ' this has to be done first because its used by CreateMyListBox
   SETUPUI
END SUB &lt;/div&gt;
&lt;div&gt;&lt;br class=&quot;webkit-block-placeholder&quot; /&gt;
&lt;/div&gt;
&lt;div&gt;SUB MAIN
   INITIALIZE
END SUB &lt;/div&gt;
&lt;div&gt;&lt;br class=&quot;webkit-block-placeholder&quot; /&gt;
&lt;/div&gt;
&lt;div&gt;MAIN ' our normal kickstart
'-------------code ends here
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Times; font-size: 16px; text-align: left; white-space: normal;&quot;&gt;&lt;span style=&quot;background-color: transparent; white-space: pre;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;text-align: left; white-space: normal;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;Ok! I've left a couple of handlers empty because I think you would have a  hard time completing this exercise without having the benefit of this lesson.   Also, you'll notice that SETUPCOLORS and CreateMyListBox have code that's  repetitive. You load a bunch of stuff into an array or list. Wouldn't it be  nice to be able to simplify this? Well we can, and we do so using...&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;&lt;/span&gt;&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;LOOPS&lt;/span&gt;&lt;/strong&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;&lt;span&gt;&lt;b&gt;   &lt;/b&gt;&lt;/span&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;     Your programs can not only make decisions, but they can do certain things      over and over again--sort of like deja vu. There are three basic types of  loops that you'll have to learn. One type is a &quot;determinate&quot; type.  This just means you always know how many times to repeat the loop. In NSBasic,  this loop is programmed using the FOR/NEXT statement. (There is also a nifty  other FOR EACH/NEXT command we'll go over next time.) &lt;br /&gt;
     The syntax for a FOR/NEXT command is: &lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;    FOR counter = start TO end [STEP increment]
      ...your stuff....
    NEXT [counter] &lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;      &lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;The loop is bracketed by the FOR and NEXT statements. And where &quot;counter&quot;  is a variable that keeps track of how many time you are about to go thru  the loop. &quot;start&quot; is the first value of &quot;counter&quot; when  the loop starts. The loop ends when &quot;counter&quot; executes the &quot;end&quot;th  iteration of the loop. Each time through the loop, &quot;counter&quot; is  incremented (or decremented) by &quot;increment&quot;. Yup this seems confusing without an example. Here is a simple one: &lt;/span&gt;&lt;/pre&gt;
&lt;blockquote&gt;&lt;pre&gt;&lt;br class=&quot;webkit-block-placeholder&quot; /&gt;
&lt;/pre&gt;
&lt;pre&gt; FOR I = 1 TO 3
      MSGBOX I
 NEXT I &lt;/pre&gt;
 &lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px;&quot;&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px;&quot;&gt;This loop will show the MSGBOX 3 times (start = 1 end = 3) and each time  in the loop MSGBOX will show you the value of &quot;counter&quot;. Now how  about counting from 1 to 10 but only displaying the odd numbers? Easy: &lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote&gt;&lt;span style=&quot;font-family: Times; font-size: 16px;&quot;&gt;&lt;br class=&quot;webkit-block-placeholder&quot; /&gt;
&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote&gt;&lt;pre&gt;FOR I = 1 TO 10 STEP 2
      MSGBOX I
NEXT &lt;/pre&gt;
&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px;&quot;&gt;Each time through the loop, the &quot;counter&quot; value of I will get 2 (the &quot;increment&quot;) added to it, so the loop only executes 5 times instead of 10, and only with the odd values from 1 to 10! Cool! Also, note that we didn't specify the &quot;counter&quot; in the NEXT statment. NEXT instead of NEXT I. Either is fine, but explicitly stating it is better style (documentation again). &lt;/span&gt;&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;       Now how about counting downward by 2s? &lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-family: Times; font-size: 16px;&quot;&gt;&lt;br class=&quot;webkit-block-placeholder&quot; /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt; FOR I = 10 TO 1 STEP - 2
      MSGBOX I
 NEXT I &lt;/pre&gt;
&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;
 Always remember that &quot;start&quot; is always where you start, whether      you go up or down. Now you can also next loops (have one inside another. Try this: &lt;br /&gt;
    &lt;/span&gt; &lt;pre&gt; FOR I = 1 TO 3
      FOR J = 1 TO 3
     	 MSGBOX &quot;I=&quot; &amp;amp; I &amp;amp; &quot; J=&quot; &amp;amp; J
      NEXT J
 NEXT I &lt;/pre&gt;
&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;&lt;blockquote&gt;&lt;span style=&quot;font-family: Courier; font-size: 13px;&quot;&gt;&lt;br class=&quot;webkit-block-placeholder&quot; /&gt;
&lt;/span&gt;&lt;/blockquote&gt;
 That's all there is really to FOR statements, but they are powrerful when you know &quot;start&quot; and &quot;end&quot;. But what happens when you  don't know? A good example is our last assignment.&lt;br /&gt;
We don't know how many colors the user deleted or how many duplicates exist. In that case, we use something known as an &quot;indeterminate&quot; loop. NSBasic has two types of indeterminate loops; the WHILE/WEND and the DO/LOOP.      &lt;br /&gt;
     The two loops are very similar, but they have two important differences. The      DO/LOOP always executes at least once, whereas the WHILE/WEND may not execute      at all. This is due to the other difference. The DO/LOOP executes at least      once because the check for whether the loop should loop is done at the end      of the loop,&lt;br /&gt;
     whereas the WHILE/WEND check is done at the beginning of the loop. &lt;br /&gt;
     The syntax of a DO/LOOP is:      &lt;/span&gt;&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;pre&gt; DO
      ...your stuff inside the loop
 LOOP [WHILE|UNTIL condition]
     &lt;/pre&gt;
 &lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;and the WHILE/WEND&lt;/span&gt;      &lt;pre&gt; WHILE condition
      ...your stuff inside the loop
 WEND &lt;/pre&gt;
 &lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px;&quot;&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px;&quot;&gt;Let's take the example of counting from 1 to 10 again, but this time lets use indeterminate loops. &lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote&gt;&lt;pre&gt; I = 1
 DO
      MSGBOX I
      I = I + 1
 LOOP UNTIL I = 10 &lt;/pre&gt;
     &lt;p&gt;Note that you have to handle the &quot;counter&quot; and the incrementing        of the counter. It doesn't happen like in the FOR/NEXT because NSBASIC doesn't        know the start or end points. In our assignment we could do something like:      &lt;/p&gt;
     &lt;pre&gt; I = 1
 DO
      Colors(I) = ...
      I = I + 1
 LOOP UNTIL I = 7   &lt;/pre&gt;
&lt;br /&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;We could also write this using the other variation of the DO/LOOP: &lt;/span&gt;&lt;/p&gt;
&lt;pre&gt; I =1
 DO
      Colors(I) = ...
      I = I + 1
 LOOP WHILE I &amp;lt; 8 &lt;/pre&gt;
&lt;p&gt;&lt;span style=&quot;font-family: Times; font-size: 16px;&quot;&gt;&lt;br class=&quot;webkit-block-placeholder&quot; /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;Which one you use is really up to you, you can accomplish tasks either   way. Now the same thing using the WHILE/WEND: I = 1&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;pre&gt;WHILE I &amp;lt;= 7
      Colors(I) = ...
      I = I + 1
WEND &lt;/pre&gt;
 &lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px;&quot;&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px;&quot;&gt;Now I mentioned that DO/LOOPS always execute at least once and WHILE/WENDs  may note even execute. Here is an example: &lt;/span&gt;&lt;pre&gt;&lt;br class=&quot;webkit-block-placeholder&quot; /&gt;
&lt;/pre&gt;
&lt;pre&gt; I = 2
 DO
      MSGBOX I
      I = I + 1
 LOOP UNTIL I = 3
 I = 1&lt;br /&gt;
 WHILE I = 3
      MSGBOX I
      I = I + 1
 WEND &lt;p&gt;     &lt;/p&gt;
&lt;/pre&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;True, this is a forced example, but it shows the point! Option Buttons Now for our widget of the day! The option button is like a checkbox. It  lets us toggle a value on and off, but unlike a checkbox, an option button  usually occurs in groups, and only one option button can be on at a time.  That is, turning one on, turns the others off. &lt;br /&gt;
There is nothing new about an OptionButton. You already know all the methods,  events, properties, and how to create one! The only problem we have to deal with is the exclusive nature of the button. If you create two buttons: &lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&lt;br class=&quot;webkit-block-placeholder&quot; /&gt;
&lt;/pre&gt;
&lt;pre&gt; ADDOBJECT &quot;OptionButton&quot;,&quot;B1&quot;,10,10,100,20
 ADDOBJECT &quot;OptionButton&quot;,&quot;B2&quot;,10,30,100,20
 ADDOBJECT &quot;OptionButton&quot;,&quot;B3&quot;,10,50,100,20
 B1.Caption = &quot;B1&quot;
 B2.Caption = &quot;B2&quot;&lt;br /&gt;
 B3.Caption = &quot;B3&quot; &lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px;&quot;&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;br class=&quot;webkit-block-placeholder&quot; /&gt;
&lt;/pre&gt;
&lt;pre&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;and run it, you'll see that there is nothing inherently exclusive about the buttons! You can toggle them both on! This is a shortcoming in NSBasic,  since VisualBasic and other environments handle the exclusivitiy automatically. So what do we do? We have to write our own code to  handle option buttons. This is how: &lt;/span&gt;&lt;/pre&gt;
&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;
&lt;/span&gt;&lt;pre&gt;SUB B1_Click
      ' we know that B1 is now on, so we turn the others off...
      B2.Value = FALSE
      B3.Value = FALSE
END SUB&lt;br /&gt;
SUB B2_Click
      B1.Value = FALSE
      B3.Value = FALSE
END SUB&lt;br /&gt;
SUB B3_Click
      B1.Value = FALSE
      B2.Value = FALSE
END SUB &lt;p&gt;&lt;br class=&quot;webkit-block-placeholder&quot; /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px;&quot;&gt;That's it for option buttons really. &lt;/span&gt;&lt;/p&gt;
&lt;/pre&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;     &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;&lt;span&gt;&lt;b&gt;For next time &lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-family: Times; font-size: 16px;&quot;&gt;&lt;br class=&quot;webkit-block-placeholder&quot; /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;For next time, rewrite the colors exercise to use loops to initialize the colors and the listbox. Next time we'll go over the FOR EACH/NEXT statement  and the PictureBox widget! Stay tuned!  Cheers!   &lt;/span&gt;&lt;br /&gt;
         &lt;br /&gt;
         &lt;br /&gt;
         &lt;br /&gt;
         &lt;br /&gt;
         &lt;/p&gt;
&lt;/blockquote&gt;
 &lt;!--    RichTextElement    --&gt;
&lt;!--    /Rich Text Element    --&gt;
	 &lt;!--    article-content    --&gt;
	&lt;/div&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;/span&gt;
			</description>
			<pubDate>Wed, 11 Apr 2007 21:32:17 -0400</pubDate>
			<guid>http://www.visualnewt.com/Products/windows_mobile/nsbasicce_tutorial/article_11-deja-vu_again.html</guid>
		</item>
		<item>
			<title>ARTICLE 10-DECISION, THE LABEL AND LISTBOX</title>
			<link>http://www.visualnewt.com/Products/windows_mobile/nsbasicce_tutorial/article_10-decision_the_lab.html</link>
			<description>
&lt;p&gt;&lt;span style=&quot;font-family: Times; font-size: 16px;&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-family: Times; font-size: 16px;&quot;&gt;&lt;span style=&quot;font-family: 'Trebuchet MS';&quot;&gt;&lt;b&gt;&lt;b&gt;Programming Using NSBasicCE&lt;/b&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h4&gt;ARTICLE 10-DECISION, THE LABEL AND LISTBOX&lt;/h4&gt;
&lt;p&gt;&lt;font size=&quot;-2&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;All content (c)1999 Serg Koren.&lt;/span&gt;&lt;br style=&quot;font-size: 12px;&quot; /&gt;
&lt;span style=&quot;font-size: 12px;&quot;&gt;All rights reserved.&lt;/span&gt;&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
 &lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt; Welcome to the 10th installment of NSBasicCE. This time around we talk about getting your programs to make decisions, and we talk about two widgets: the label, and the listbox. &lt;/span&gt;&lt;strong&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; font-weight: normal; color: black;&quot;&gt; &lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;Leftovers from Last Time&lt;/span&gt;&lt;/strong&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;&lt;b&gt;  &lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;Last time around we talked about arrays and how they simplify coding. I also asked you to write a simple program that uses arrays.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;The program should have:&lt;/span&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;3 CommandButtons labeled &quot;A&quot;,&quot;B&quot;, and &quot;C&quot;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;A CommandButton labeled &quot;Do it!&quot;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;The program should:&lt;/span&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;Tally the numbers of times each of the three CommandButtons has been tapped. (Hint: This is what the array is for).&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;Prompt the user for his name when he taps the &quot;Do it!&quot; button, and then display a message in the format: &quot; Hi &amp;lt;name here&amp;gt;, you've tapped button A x times, B y times, and button C z times.&quot;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;Here's my code.  &lt;/span&gt;&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;strong&gt;&lt;b&gt;       '-------------------code starts &lt;/b&gt;&lt;/strong&gt;&lt;b&gt;here&lt;/b&gt;
       ' Assignment number 9
       '
       OPTION EXPLICIT
       DIM TapCount(3) ' we won't use element 0 for anything. Used to store the count of taps for a given button.
       DIM AButton, BButton, CButton ' used to index into TapCount array
       &lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;       '--------------------create our objects
       ' Create our Command buttons
       SUB CreateMyCommandButtonA
      	  ADDOBJECT &quot;CommandButton&quot;,&quot;A&quot;,10,10,100,30
      	  A.Caption = &quot;A&quot;
       END SUB
       &lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;       SUB CreateMyCommandButtonB
      	  ADDOBJECT &quot;CommandButton&quot;,&quot;B&quot;,10,50,100,30
      	  B.Caption = &quot;B&quot;
       END SUB
        &lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;       SUB CreateMyCommandButtonC
      	  ADDOBJECT &quot;CommandButton&quot;,&quot;C&quot;,10,90,100,30
      	  C.Caption = &quot;C&quot;
       END SUB
       &lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;       ' Create our DoIt button
       SUB CreateMyCommandButtonDoIt
          ADDOBJECT &quot;CommandButton&quot;,&quot;DoIt&quot;,10,130,100,30
       	  DoIt.Caption = &quot;Do It!&quot;
       END SUB
       &lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;       '----------------- our event handlers
       SUB A_click
      	  TapCount(AButton) = TapCount(AButton) + 1
       END SUB
       &lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;       SUB B_Click
      	  TapCount(BButton) = TapCount(BButton) + 1
       END SUB
       &lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;       SUB C_Click
      	  TapCount(CButton) = TapCount(CButton) + 1
       END SUB
       &lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;       SUB DoIt_Click
      	  DIM MyName ' this is local because it's not used anywhere else!
      	  MyName = INPUTBOX(&quot;Please enter your name&quot;,vbOKOnly,&quot;PROMPT&quot;) ' ask user for name
      	 ' now display the message: &quot;Hi &lt;name here=&quot;&quot;&gt;, you've tapped button A x times, B y times, and button C z times.&quot;
      	 MSGBOX &quot;Hi &quot; &amp;amp; MyName &amp;amp; &quot;, you've tapped button A&quot; &amp;amp; TapCount(AButton) &amp;amp; &quot; times, B &quot; &amp;amp; TapCount(BButton) &amp;amp; &quot;,times and button C&quot; &amp;amp; TapCount(CButton) &amp;amp; &quot; time.&quot;
       END SUB
       &lt;/name&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;name here=&quot;&quot;&gt;       '----------------------------------Setup routines
       SUB SetupUI
      	  CreateMyCommandButtonA
      	  CreateMyCommandButtonB
      	  CreateMyCommandButtonC
      	  CreateMyCommandButtonDoIt
       END SUB
       &lt;/name&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;name here=&quot;&quot;&gt;       ' Initialize global variables
       SUB Iniaialization
      	  AButton = 1 ' point to first element of TapCount array for button A
      	  BButton = 2 ' point to second element of TapCount array for button B
      	  CButton = 3 ' point to third element of TapCount array for button C
      	  TapCount(AButton) = 0 ' set count to 0 for first element
       	  TapCount(BButton) = 0 ' ...and so on
      	  TapCount(CButton) = 0
       END SUB
       &lt;/name&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;name here=&quot;&quot;&gt;       ' Our main routine
       SUB Main
       	  Initialization
      	  SetupUI
       END SUB
       &lt;/name&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;name here=&quot;&quot;&gt;       Main ' our IMMEDIATE command to start everything
      &lt;strong&gt;&lt;b&gt; '--------------------code ends here &lt;/b&gt;&lt;/strong&gt;
       &lt;/name&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;Not too bad! Now look at our Initialization routine in the above code. Seems like there should be an easier way of doing this....and there is! We'll talk about how later in this article, but first, we'll get your programs to make some decisions on their own!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; font-weight: normal; color: black;&quot;&gt;&lt;br /&gt;
&lt;b&gt;
IF THEN...ELSEIF....END IF (DECISIONS) &lt;/b&gt;&lt;/span&gt;&lt;/strong&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;So far we've just dealt with programs that execute line by line by line by line...top to bottom. Now we'll talk a bit about altering the execution flow. That is, how to get your program to skip some code and execute other code. To do this, your program has to decide somehow that it should execute some portions of code while avoiding others. NSBasic has one statement that allows this: The IF/END IF statemennt. If you look in the manual under IF...THEN...ELSE you can see the hoary details. I'll break it down to simplify it and work up. In it's simplest form, the IF/END IF statement looks like: &lt;/span&gt;&lt;br /&gt;
 &lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;      IF &lt;something&gt; THEN
         ....execute this code here, if &lt;something&gt; is TRUE
      END IF &lt;br /&gt;
 &lt;/something&gt;&lt;/something&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;&lt;br /&gt;
This variation, just lets your program decide &amp;lt;something&amp;gt; and if the result is TRUE your program will execute everything between the IF...THEN and END IF statements. What happens if &amp;lt;something&amp;gt; is FALSE? NSBasic ignores everything betweent he IF...THEN and END IF statements and starts executing at the line after the END IF. Let's take at a more concret example. &lt;/span&gt;&lt;br /&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;   DIM TonsOfConcrete
   TonsOfConcrete = 3
   IF TonsOfConcrete &amp;lt; 5 THEN
      MSGBOX &quot;You don't have enough concrete!&quot;
   END IF &lt;br /&gt;
   TonsOfConcrete = TonsOfConcrete + 3 ' buy more concrete
   IF TonsOfConcrete &amp;lt; 5 THEN
      MSGBOX &quot;You still don't have enough concrete&quot;
   END IF &lt;/tt&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
  &lt;br /&gt;
&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;
In this example, the first IF statement returns TRUE (TonsOfConcrete IS less than 5), so you see the first MSGBOX. Once you add 3 to TonsOfConcrete the second IF statement returns FALSE (TonOfConcrete is now 6 which is not less than 5 (FALSE)), so you don't see the second MSGBOX. One thing to note here is that &amp;lt;something&amp;gt; returns a value. So you can use a FUNCTION there... &lt;/span&gt;&lt;br /&gt;
  &lt;br /&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;br /&gt;
     IF INPUTBOX(&quot;Enter a number 1..10&quot;) &amp;lt; 5 THEN
        MSGBOX &quot;Less than 5!&quot;
     END IF &lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;&lt;br /&gt;
That's fairly easy to understand if you're following everything we've done so far! Ok now what happens if you want to display one message if the number entered is less than 5 and another if its greater than or equal to 5? Well you could do: &lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;      Num = INPUTBOX(&quot;Enter a number 1..10&quot;) &lt;br /&gt;
      IF Num &amp;lt; 5 THEN
          MSGBOX &quot;Less than 5!&quot;
      END IF &lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
 &lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;      IF Num &amp;gt;= 5 THEN
          MSGBOX &quot;Greater than equal 5!&quot;
      END IF &lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
  &lt;br /&gt;
&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;
This is fine unless someone goes in and adds the line &quot;Num = 3&quot; between the first END IF and the next IF! NSBasic has a form that lets you execute one set of code under one condition and another if the condition is false... &lt;/span&gt;&lt;br /&gt;
  &lt;br /&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;	IF &lt;something is=&quot;&quot; true=&quot;&quot;&gt; THEN
	   &amp;lt; do this&amp;gt;
 	ELSE
	   &amp;lt; do this if &lt;something is=&quot;&quot; true=&quot;&quot;&gt; is false
 	END IF &lt;br /&gt;
&lt;/something&gt;&lt;/something&gt;&lt;/tt&gt;&lt;/pre&gt;
  &lt;br /&gt;
L&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;et's get concrete again.. &lt;/span&gt;&lt;br /&gt;
  &lt;br /&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt; 	IF TonsOfConcrete &amp;gt;= 5 THEN
	   MSGBOX &quot;Lots of concrete!&quot;
 	ELSE
     	   MSGBOX &quot;Warning, you have less than 5 tons of concrete!&quot;
 	END IF &lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
  &lt;br /&gt;
&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;
And what if we want a special message for 2 tons? Well we use the form: &lt;/span&gt;&lt;br /&gt;
  &lt;br /&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt; 	IF &lt;something&gt; THEN
	   &amp;lt; do stuff here&amp;gt;
	ELSEIF &lt;something else=&quot;&quot;&gt; THEN
	   &amp;lt; do other stuff here&amp;gt;
  	ELSE
           &amp;lt; do something different if none of the above is true&amp;gt;
  	END IF
	IF TonsOfConcrete = 2 THEN
      	   MSGBOX &quot;2!&quot;
        ELSEIF TonsOfConcrete &amp;lt; 5 THEN
       	   MSGBOX &quot;Buy more!&quot;
        ELSE
       	   MSGBOX &quot;Enough!&quot;
        END IF &lt;/something&gt;&lt;/something&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;  &lt;br /&gt;
&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;
And you can have as many ELSEIF...THEN statements in your IF statement as you need! One thing you should be careful of is that the order of the tests is important. The first one that evaulates to true gets done! The others are ignored. For example compare what happens with the prior IF and this one...&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;	IF TonsOfConcrete &amp;lt; 5 THEN
       	   MSGBOX &quot;Buy more!&quot;
        ELSEIF TonsOfConcrete = 2 THEN
           MSGBOX &quot;2!&quot;
        ELSE
           MSGBOX &quot;Enough!&quot;
        END IF &lt;/tt&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;
  &lt;br /&gt;
If you can understand what happens and why, you have IF/END IF statements down! Think about it. &lt;br /&gt;
Time to look at our UI widgets for this week..we handle two!&lt;/span&gt;&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;LABEL&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;
The label widget places a line of text on your program's main window. You already know how to create a label, and what most of the Properties, Events and Methods do. You should still check out Label in the manual. There really isn't much new with this widget apart from the Alignment property. The alignment property lets you specify whether the text in the label lines up on the left, the right or in the center of the label. You use a number to determine alignment: 0 = left, 1 = right, 2 = center. For example: &lt;br /&gt;
  &lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;      ADDOBJECT &quot;Label&quot;,&quot;MyLabel&quot;,10,10,100,30
      MyLabel.Caption = &quot;Hi!&quot;
      MyLabel.Alignment = 2 ' center &lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;&lt;br /&gt;
Again, if your label isn't wide enough, the Alignment property won't have any visible effect. &lt;br /&gt;
  &lt;br /&gt;
And now onto something slightly similar...&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; font-weight: normal; color: black;&quot;&gt;&lt;br /&gt;
&lt;b&gt;
LISTBOX&lt;/b&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;&lt;br /&gt;
The Listbox is very similar to the ComboBox. Both present you with a list and let the user choose one of the items in the list. When would you use a ListBox, and when a ComboBox? Typically, I choose a ComboBox when the user needs to type a new item into the list (add an item to the list). I use a ListBox whenever the list items are fixed and the list items have to be visible (A ComboBox's list items are only visible when the user taps on the ComboBox to drop the list down.) Other than that the two serve identical purposes. Because of that the ListBox has similar Properties, Methods, and Events. The exceptions being, that there is no DropDown event in a ListBox. A ListBox also has a Property called ScrollBars. This is because a ListBox can have more items than will fit in the displayed size of the box. The manual implies you can have horizontal, vertical or both types of scrollbars. Actually, only vertical (2), is supported. Just like a ComboBox, you can add, remove items in the list, as well as clearing the entire ListBox. Play with the ListBox's scrollbar propery! But be aware, that you have to set the ScrollBars property immediately after you create the listbox. &lt;br /&gt;
  &lt;/span&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;      ADDOBECT &quot;ListBox&quot;,&quot;MyListBox&quot;,10,10,100,100
      MyListBox.ScrollBars = 2 ' vertical
      MyListBox.AddItem &quot;AAAAAAAAAAAAAAAA&quot;
      MyListBox.AddItem &quot;AAAAAAAAAAAAAAAA&quot;
      MyListBox.AddItem &quot;AAAAAAAAAAAAAAAA&quot;
      MyListBox.AddItem &quot;AAAAAAAAAAAAAAAA&quot;
      MyListBox.AddItem &quot;AAAAAAAAAAAAAAAA&quot;
      MyListBox.AddItem &quot;AAAAAAAAAAAAAAAA&quot;
      MyListBox.AddItem &quot;AAAAAAAAAAAAAAAA&quot;
      MyListBox.AddItem &quot;AAAAAAAAAAAAAAAA&quot;
      MyListBox.AddItem &quot;AAAAAAAAAAAAAAAA&quot; &lt;br /&gt;
&lt;/tt&gt;&lt;/pre&gt;
  &lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;&lt;br /&gt;
Nothing too complicated there, apart from having to set the Scrollbars property right after the ADDOBJECT statement. (This is indicated by a + sign in the manual on the page dealing with Properties).&lt;/span&gt;&lt;p&gt;
&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;strong&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;For Next Time&lt;/span&gt;&lt;/strong&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;The assignment for this time will test everything we've gone over so far. Write a program, &lt;br /&gt;
  &lt;br /&gt;
That has:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;A Listbox&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;A Label next to the listbox labelling it &quot;Colors&quot;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;An array of colors: &quot;Red&quot;, &quot;Orange&quot;, &quot;Yellow&quot;, &quot;Green&quot;, &quot;Blue&quot;, &quot;Indigo&quot;, &quot;Violet&quot;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;A CommandButton labelled &quot;Remove&quot;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;A CommandButton labelled &quot;Add&quot;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;A CommandButton labelled &quot;Find Missing&quot;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;A CommandButton labelled &quot;Find Duplicates&quot;&lt;/span&gt;&lt;p&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;
The program should:&lt;/span&gt;&lt;p&gt;
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;Load the colors into the listbox&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;When the user clicks on the &quot;Remove&quot; button , the selected color in the listbox is removed from the list.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;When the user clicks on the &quot;Add&quot; button, the selected color is added to the end (bottom) of the listbox.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;When the user clicks on the &quot;Find Missing&quot; button, the program should list all the missing colors in the listbox from the master set.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;When the user clicks on the &quot;Find Duplicates&quot; button, the program should list all the colors in the listbox that occur more than once.&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;&lt;br /&gt;
  &lt;br /&gt;
Next time we'll go over getting your program to do things more than once (loops) as well as the OptionButton and PictureBox objects! &lt;br /&gt;
If you get stuck or have a question about anything we've gone over, feel free to e-mail me at Serg@VisualNewt.com &lt;br /&gt;
  &lt;br /&gt;
Cheers! &lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
			</description>
			<pubDate>Wed, 11 Apr 2007 21:31:38 -0400</pubDate>
			<guid>http://www.visualnewt.com/Products/windows_mobile/nsbasicce_tutorial/article_10-decision_the_lab.html</guid>
		</item>
		<item>
			<title>ARTICLE 9 -- ARRAYED THINGS AND INPUTBOX</title>
			<link>http://www.visualnewt.com/Products/windows_mobile/nsbasicce_tutorial/article_9_--_arrayed_things.html</link>
			<description>
&lt;p&gt;&lt;span style=&quot;font-family: Times; font-size: 16px;&quot;&gt;&lt;span style=&quot;font-family: 'Trebuchet MS';&quot;&gt;&lt;b&gt;Programming Using NSBasicCE&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;span style=&quot;font-family: Times; font-size: 16px;&quot;&gt;&lt;h4&gt;&lt;br /&gt;
ARTICLE 9 -- ARRAYED THINGS AND INPUTBOX&lt;/h4&gt;
&lt;p&gt;&lt;font size=&quot;-2&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;All content (c)1999 Serg Koren.&lt;/span&gt;&lt;br style=&quot;font-size: 12px;&quot; /&gt;
&lt;span style=&quot;font-size: 12px;&quot;&gt;All rights reserved.&lt;/span&gt;&lt;/font&gt;&lt;br /&gt;
 &lt;br /&gt;
Welcome to the ninth installment of NSBasicCE. &lt;br /&gt;
Here we discuss arrays, and the INPUTBOX widget.&lt;br /&gt;
&lt;strong&gt; &lt;br /&gt;
Leftovers from Last Time&lt;/strong&gt;&lt;br /&gt;
 &lt;br /&gt;
In our last article we discussed how to take a string and extract substrings from it. I then asked you to write a simple app that has:&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;a date object&lt;/li&gt;
&lt;li&gt;a command button&lt;br /&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;It should:&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Save the date the user taps on in a variable called TheDate&lt;/li&gt;
&lt;li&gt;Display the message: &quot;This is the i-th day of the j-th month.&quot; whenever the user taps the command button.&lt;br /&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Note that i and j above are numbers you can get from TheDate.&lt;br /&gt;
Here is my solution:&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;       '--------begin code here--------------
       '
       ' Aricle 8 exercize
       '
       '
       '---------- Create our objects routines
       OPTION EXPLICIT ' force DIMensions
       DIM FullDate ' global variable to store the date string returned by Date        object
       DIM Day ' the part of the date string containing the Day (i-th day)
       DIM Month ' the part of the date string containing the Month (j-th month)
		&lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;       ' Create a date object
       SUB CreateMyDateObject
       	  ADDOBJECT &quot;Date&quot;,&quot;MyDateObject&quot;,10,10,100,30
       END SUB
	&lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;       ' Create our command button
       SUB CreateMyCommandButton
       	  ADDOBJECT &quot;CommandButton&quot;,&quot;MyCommandButton&quot;,10,50,100,30
       END SUB
	&lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;       '----------- Set up our event handlers
       ' Date object event handler
       SUB MyDateObject_Change
          FullDate = MyDateObject.Text ' get the selected date and store it in our variable
       END SUB
		&lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;       ' CommandButton event handler
       SUB MyCommandButton_click
         Day = MID(FullDate,4,2) ' extract the dd portion of mm/dd/yyyy
       	 Month = LEFT(FullDate,2) ' extract the mm portion of mm/dd/yyyy
       	 MSGBOX &quot;This is the &quot; &amp;amp; Day &amp;amp; &quot;th day of the &quot;        &amp;amp; Month &amp;amp; &quot;th month.&quot;
       END SUB
	&lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;       '------------- Our setup routines
       SUB SetupUI
       	  CreateMyDateObject
       	  CreateMyCommandButton
       END SUB
	&lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;       SUB Main
       	  SetupUI
       END SUB
       	&lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;       Main ' our IMMEDIATE command to get things running
       '--------- end code here&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
That's basically it. However, you'll notice that if you choose the 1st day or month, your message is grammatically incorrect! You don't know enough at this point to fix it, but you will next time!&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;strong&gt;ARRAYS&lt;/strong&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; font-size: 16px; color: black;&quot;&gt;Simply put, arrays are collections of things. In programming, arrays are  a powerful tool that lets you simplify your code by grouping collections of variables together under one name. An example would be the best way to understand this. For instance, assume you have to program a game having ten boxes and you need to put something into the third. You could set up variables for each box thusly:&lt;/span&gt;
     &lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;DIM Box1
DIM Box2
DIM Box3
       ...
DIM Box10
Box3 = Something
     &lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt; &lt;br /&gt;
This would work fine, but it's a lot of typing isn't it? Wouldn't it be simpler saying &quot;here is a bunch of boxes, and I want the 3rd one.&quot;? In NSBasic you can do this by creating an array of variables and giving them a single name. In this example lets call our collection of boxes &quot;Box&quot;. We specify the maximum number of things (boxes) in our collection by putting the number inside parentheses after the name in our DIMension statement! So if we want to have 10 boxes we would have a DIM statement:&lt;br /&gt;
 &lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;DIM Box(10)&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt; &lt;br /&gt;
Now if you're just getting into programming and have been following these articles you may be thinking...&quot;doesn't the parentheses mean that this is a function?&quot; Well not in this case. You don't have the FUNCTION keyword. But actually in some languages (Smalltalk, etc.) This indeed would be a function-like object. But in NSBasic, this is just how you specify an array of variables. Ok, so back to our example...how do we put stuff into our third box?&lt;br /&gt;
&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt; Box(3) = Something&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt; &lt;br /&gt;
Easy! So how do we see what is in the third box instead? Just as you would expect...&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;X = Box(3)&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
And likewise you can do things like...&lt;br /&gt;
&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;Box(3) = Box(3) * 2
     &lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;...which would multiply the value in array element 3 by 2. No, the number isn't 6. It depends on what is stored in Box(3). If we did:&lt;br /&gt;
 &lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;Box(3) = 12
Box(3) = Box(3) * 2
     &lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;...then Box(3) = 24! Can we do...&lt;br /&gt;
&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;Box = Box(3) + 2
     &lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;white-space: pre;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; color: black;&quot;&gt;...no! You can't do something to the entire array. You have to specify which element in the array you want to operate on (again this is a limitation  of NSBasic, since other languages allow you to operate on the array as a whole).
       &lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;white-space: pre;&quot;&gt;&lt;tt&gt;&lt;span style=&quot;background-color: transparent; font-family: Times; color: black;&quot;&gt;So far we've been assuming arrays hold numbers, but arrays can hold any data type!
     &lt;/span&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;Box(4) = &quot;Hello&quot;
Box(5) = &quot;There&quot;
Box(6) = 12 * 2
        &lt;/tt&gt;&lt;/pre&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;MSGBOX Box(4) &amp;amp; Box(5) &amp;amp; &quot; array element 6 has &quot; &amp;amp; Box(6) &amp;amp; &quot; in it.&quot;
     &lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;You can't however put objects into arrays!&lt;br /&gt;
&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;Box(7) = MyDateObject ' a Date object you create elsewhere
     &lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;will give you a runtime error (an error that you get when you run the program) of &quot;Object doesn't support this property or method.&quot; However, there are ways of creating arrays of objects (which we'll talk about in a future article.)&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
A couple of important things to note about arrays. The first element in the array is actually element 0! That means that in our box example our boxes are numbered 0 through 10, an d not 1 through 10! So what happens when we try:&lt;br /&gt;
&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;Box(11) = 1
        &lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;Try it!&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;Can we get the 3rd through the 5th box in our array? No, again you need to deal with each element in an array singly.&lt;br /&gt;
 &lt;br /&gt;
Arrays are very straightforward once you get past knowing how to DIM and reference (use) them. However, we've only been discussing one-dimensional arrays. That is arrays of things we can line up in a single line. But lets say you need to program a Bingo game board for your Auntie Ethel who is addicted to bingo! A bingo board consists of a two-dimensional array (a grid) Or a spreadsheet? In this case we use a two-dimensional array set up by a DIM statement that specifies the maximum number of elements in each axis (vertically and horizontally). So if we are building a mini-spreadsheet that has 10 rows and 30 columns we would use the DIMension statement:&lt;br /&gt;
 &lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;DIM Sheet(10,30)
     &lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;DIM Sheet(30,10)
        &lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;Huh??? Well programming languages don't know anything about the concepts of &quot;vertical&quot; and &quot;horizontal&quot;, so the order in which you declare them in the DIM statement is totally arbitrary. By convention, however we tend to think of row-column instead of column-row, so the first is more accepted. However, you can use the second and it will work fine, but you personally as the programmer have to remember which is the row and which is the column. So it's a good idea to put in a comment to remind you...&lt;br /&gt;
 &lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;DIM Sheet (30,10) ' column, row
     &lt;br /&gt;
or better yet....
&lt;br /&gt;
DIM MaxRow&lt;br /&gt;
DIM MaxColumn&lt;br /&gt;
MaxRow = 10&lt;br /&gt;
MaxColumn = 30&lt;br /&gt;
DIM Sheet (MaxColumn,MaxRow)
&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
We explained before why this version is better programming style, although the single DIM statement is faster to type.&lt;br /&gt;
 &lt;br /&gt;
Also, note that in the above example we didn't DIM Sheet(29,9) (because of the 0th element in each dimension). This wastes a bit of space, but usually isn't critical, and it simplifies our programs so that we don't have to subtract one each time. You may be scratching your head here again...say we want to load cell 5,3 with a 2 if we had DIMmed the array as&lt;br /&gt;
&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;DIM Sheet(29,9) ' because our sheet starts at Sheet(0,0) and not Sheet(1,1)
Sheet(4,2) = 2 ' would actually be cell (5,3) because our array starts at Sheet(0,0) and goes to (29,9)&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
but because we dimensioned&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;DIM Sheet(30,10) ' and not use cell (0,0) for anything
Sheet(5,3) = 2 ' is easier to deal with although it's actually (6,4), but we just ignore the (0,0) element to simplify our lives
        &lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;
Read that through a couple of times so you understand it. Draw it out on some graph paper too if you need to. It's not hard to understand, just a bit clumsy to explain.&lt;br /&gt;
That's basically it for arrays. Oh, how many dimensions can an array in NSBasic have? We've only discussed two. NSBasic arrays can have up to 60! dimensions. So you could have a DIM statement:&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;DIM Wow(20,340,1,40,...bunch more...,3) ' for 60 dimensions separated by commas
     &lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;Don't ask why you would ever want to deal with this...&lt;br /&gt;
 &lt;br /&gt;
&lt;strong&gt;INPUTBOX&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
So far we've been dealing with programs that don't let the user type something in. The INPUTBOX is a widget that lets you do just that! It's similar to MSGBOX in that it displays a separate mini-window and display a message. It's different in that the window it displays also has a single text field that lets the user type something in. Refer to the manual page on INPUTBOX.&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;INPUTBOX (prompt[,title[,default[,xpox,ypos]]])
        &lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;As you can see INPUTBOX is a function and it returns whatever string the user typed in. As you can also see from the manual, the only required parameter is the prompt. The prompt is the message to display to the user. The INPUTBOX is very easy to use. You don't have to create it or set up event handlers, you just use it.&lt;br /&gt;
 &lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;A = INPUTBOX (&quot;Type something please&quot;,&quot;My Input Box Title&quot;,&quot;Gee I can preload an answer&quot;,10,10)
     &lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;Try that. The &quot;default&quot; parameter (the 3rd one), lets you set a default string in the input field to save the user some typing.&lt;/p&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;B = INPUTBOX (&quot;What is your name?&quot;,&quot;My Name Input&quot;,&quot;enter your name here&quot;,10,10)
     &lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt;or it can be used to tell your user where to input stuff. (Yes I've seen this done, and I assume its for the computer-challenged among us, but I think this is bad design. Just leave it out!)&lt;br /&gt;
There is one really important thing you'll soon discover if you try to use INPUTBOX on a CasioE-105 and other PPC handhelds. INPUTBOX doesn't scale properly to the size of the screen. It doesn't fit! This is a Microsoft bug! To get around this problem, you can use the replacement INPUBOX routine I've written in NSBasic, and can be found at http://www.VisualNewt.com/CE/NSB/ Make sure you read the accompanying documentation, since it works a little differently from the normal INPUTBOX.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;strong&gt;For Next Time&lt;/strong&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;Write a simple program that uses arrays. The program should have:&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;3 CommandButtons labeled &quot;A&quot;,&quot;B&quot;, and &quot;C&amp;amp;quotl&lt;/li&gt;
&lt;li&gt;A CommandButton labeled &quot;Do it!&quot;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The program should:&lt;br /&gt;
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Tally the numbers of times each of the three CommandButtons has been tapped. (Hint: This is what the array is for).&lt;/li&gt;
&lt;li&gt;Prompt the user for his name when he taps the &quot;Do it!&quot; button, and then display a message in the format:&lt;/li&gt;
&lt;/ol&gt;
&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&quot;Hi &lt;name here=&quot;&quot;&gt;, you've tapped button A x times, B y times, and button C z times.&quot;&lt;/name&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt; &lt;br /&gt;
 &lt;br /&gt;
That's it for this week. Next week we'll get into a very powerful programming concept. We'll discuss how your programs can make decisions and repeat things over and over and over and over and... And our widgets of the week will be the Label, and the ListBox. We're doing two because there's not a lot to the label. See you then!&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
If you get stuck or have a question about anything we've gone over, feel free to e-mail me at Serg@VisualNewt.com&lt;br /&gt;
 &lt;br /&gt;
Cheers!&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;/span&gt;
			</description>
			<pubDate>Wed, 11 Apr 2007 21:30:48 -0400</pubDate>
			<guid>http://www.visualnewt.com/Products/windows_mobile/nsbasicce_tutorial/article_9_--_arrayed_things.html</guid>
		</item>
		<item>
			<title>ARTICLE 8--DISSECTING STRINGS AND THE DATE OBJECT</title>
			<link>http://www.visualnewt.com/Products/windows_mobile/nsbasicce_tutorial/article_8--dissecting_strin.html</link>
			<description>
&lt;p&gt;&lt;span style=&quot;font-family: Times; font-size: 16px;&quot;&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;div align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: 'Trebuchet MS';&quot;&gt;&lt;b&gt;Programming Using NSBasicCE&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;h4&gt;ARTICLE 8--DISSECTING STRINGS AND THE DATE OBJECT&lt;/h4&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;font size=&quot;-1&quot;&gt;All content (c)1999, 2002 Serg Koren.&lt;/font&gt;&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;p&gt;&lt;font size=&quot;-1&quot;&gt;All rights eserved.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;Welcome to the eight installment of NSBasicCE.&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;p&gt;In this article follow up on the last article and talk about how to break long strings into shorter strings, and we look at a new object in NSBasic, the Date Object.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;b&gt;Leftovers from Last Time&lt;/b&gt;&lt;p&gt;&lt;b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;Last time we talked about concatenating strings and the ComboBox. I asked you to write a program that has:&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;&lt;div class=&quot;Section1&quot;&gt;Five checkboxes.Each labeled with a number “1”, “2”, “3”,”4”, “5&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div class=&quot;Section1&quot;&gt;A ComboBox&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div class=&quot;Section1&quot;&gt;A CommandButton labeled “+”&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div class=&quot;Section1&quot;&gt;A CommandButton labeled “-“&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div class=&quot;Section1&quot;&gt;A CommandButton labeled “Total”&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div class=&quot;Section1&quot;&gt;A CommandButton labeled “Clear”&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&quot;Section1&quot;&gt;The program should:&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;&lt;div class=&quot;Section1&quot;&gt;Each time the user checks a number checkbox put the number the user tapped at the end of the ComboBox list.&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div class=&quot;Section1&quot;&gt;If the user taps the + or –command button, put a “+” or a “-“ at the end of the ComboBox list.&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div class=&quot;Section1&quot;&gt;If the user taps the “Total” command button, display the result of the items in the ComboBox using the message:   “There are x items in the ComboBox.”&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div class=&quot;Section1&quot;&gt;If the user selects an item from the ComboBox, display the message: “The user chose: x.”(Note the period after the ‘x’.)&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div class=&quot;Section1&quot;&gt;If the user taps on the “Clear” command button, remove all entries from the ComboBox, and deselect (uncheck) all the checkboxes.&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;o:p class=&quot;Section1&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt; &lt;/o:p&gt;&lt;div class=&quot;Section1&quot;&gt;This seems complex, but you should take it a piece at a time and build it up. A good strategy would be to take steps 1-5 in the &quot;has&quot; section and get them working one at a time. Then work on the &quot;should&quot; section. Any such &quot;break it up&quot; strategy would work. Here's my version of the program for your reference:&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;b&gt;&lt;b&gt;&lt;code&gt;'----------code starts here&lt;/code&gt;&lt;/b&gt;&lt;/b&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;'&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;' Article 7 assignment&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;'&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;'----------Routines to create the UI&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;' set up our 5 checkboxes&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;SUB CreateCheckbox1&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;ADDOBJECT &quot;CheckBox&quot;,&quot;Ch1&quot;,10,10,30,20&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;Ch1.Caption = &quot;1&quot;&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;END SUB&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;SUB CreateCheckbox1&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;ADDOBJECT &quot;CheckBox&quot;,&quot;Ch2&quot;,10,30,30,20&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;Ch2.Caption = &quot;2&quot;&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;END SUB&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;SUB CreateCheckbox2&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;ADDOBJECT &quot;CheckBox&quot;,&quot;Ch3&quot;,10,50,30,20&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;Ch3.Caption = &quot;3&quot;&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;END SUB&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;SUB CreateCheckbox3&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;ADDOBJECT &quot;CheckBox&quot;,&quot;Ch4&quot;,10,70,30,20&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;Ch4.Caption = &quot;4&quot;&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;END SUB&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;SUB CreateCheckbox4&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;ADDOBJECT &quot;CheckBox&quot;,&quot;Ch5&quot;,10,90,30,20&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;Ch5.Caption = &quot;5&quot;&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;END SUB&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;'----------setup our combo box&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;SUB CreateComboBox&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;ADDOBJECT &quot;ComboBox&quot;,&quot;Cmb&quot;,10,110,60,80&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;END SUB&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;'----------set up our command buttons&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;SUB CreatePlusButton &lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;ADDOBJECT &quot;CommandButton&quot;,&quot;Plus&quot;,10,140,20,20&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;Plus.Caption = &quot;+&quot;&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;END SUB&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;SUB CreateMinusButton &lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;ADDOBJECT &quot;CommandButton&quot;,&quot;Minus&quot;,10,170,20,20&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;Minus.Caption = &quot;-&quot;&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;END SUB&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;SUB CreateClearButton &lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;ADDOBJECT &quot;CommandButton&quot;,&quot;Clear&quot;,10,200,50,20&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;Clear.Caption = &quot;Clear&quot;&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;END SUB&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;SUB CreateTotalButton &lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;ADDOBJECT &quot;CommandButton&quot;,&quot;Total&quot;,10,230,50,20&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;Total.Caption = &quot;Total&quot;&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;END SUB&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt; &lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;'----------event handler for checkboxes...&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;' just put the number (which is the caption) into combobox&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;SUB Ch1_Click&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;Cmb.AddItem Ch1.Caption ' just move the caption of this checkbox into the last slot in the Combobox&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;END SUB &lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;SUB Ch2_Click&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;Cmb.AddItem Ch2.Caption&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;END SUB &lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;SUB Ch3_Click&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;Cmb.AddItem Ch3.Caption&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;END SUB &lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;SUB Ch4_Click&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;Cmb.AddItem Ch4.Caption&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;END SUB &lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;SUB Ch5_Click&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;Cmb.AddItem Ch5.Caption&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;END SUB &lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;'----------event handlers for buttons&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;SUB Plus_Click&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;Cmb,AddItem Plus.Caption ' just move the caption of this button into the last slot of the Combobox&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;END SUB&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;SUB Minus_Click&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;Cmb,AddItem Minus.Caption &lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;END SUB&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;SUB Clear_Click&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;Cmb.Clear ' just clear all the items in the ComboBox out&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;END SUB&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;SUB Total_Click&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;MSGBOX &quot;There are &quot; &amp;amp; Cmb.ListCount &amp;amp; &quot; items in the Combobox.&quot; ' see explanation below&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;END SUB&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;SUB Cmb_Change ' our ComboBox event handler...see explanation below&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;MSGBOX &quot;You chose &quot; &amp;amp; cmb.ListIndex &amp;amp; &quot;.&quot;        ' note the period at the end&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;END SUB&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;'----------main routines&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;' set up our user interface widgets&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;SUB SetupUI&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;CreateCheckbox1&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;CreateCheckbox2&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;CreateCheckbox3&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;CreateCheckbox4&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;CreateCheckbox5&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;CreateComboBox&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;CreatePlustButton&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;CreateMinusButton&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;CreateClearButton&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;CreateTotalButton&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;END SUB&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt; &lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;' our main routine that runs everything&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;SUB Main&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;SetupUI ' create the user interface&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;END SUB&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;code&gt;Main ' our only IMMEDIATE command&lt;/code&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;b&gt;&lt;b&gt;&lt;code&gt;'----------code ends here&lt;/code&gt;&lt;/b&gt;&lt;/b&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt; &lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;That's it. It looks like a lot, but it's not bad! We'll show you how to make it simpler and shorter next time. This is also known as &quot;brute force&quot; code. You force everything to happen one by one. There are more efficient ways of doing the above! Now then, everything should make sense apart from maybe the event handlers. Most of the event handlers just copy the caption of the widget clicked into the ComboBox:&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;p&gt;cmb.AddItem &amp;lt;widget name&amp;gt;.caption&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;p&gt;This is a shortcut for something you probably did (if you're just starting out):&lt;/p&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt; &lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;font size=&quot;-1&quot;&gt;&lt;span style=&quot;font-size: 13px;&quot;&gt;DIM X&lt;/span&gt;&lt;/font&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;font size=&quot;-1&quot;&gt;&lt;span style=&quot;font-size: 13px;&quot;&gt;X = &amp;lt;widget name&amp;gt;.caption&lt;/span&gt;&lt;/font&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;font size=&quot;-1&quot;&gt;&lt;span style=&quot;font-size: 13px;&quot;&gt;cmb.AddItem X&lt;/span&gt;&lt;/font&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;p&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;would do the same thing. But my version takes less typing and once you get used to it, is easier to understand. This is a programmatic &quot;idiom&quot; (also known as a &quot;pattern&quot;.) The Total button event handler just displays a MSGBOX:&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;p&gt; &lt;/p&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;font size=&quot;-1&quot;&gt;&lt;span style=&quot;font-size: 13px;&quot;&gt;MSGBOX &quot;There are &quot; &amp;amp; Cmb.ListCount &amp;amp; &quot; items in the Combobox.&quot;&lt;/span&gt;&lt;/font&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;p&gt; &lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;Again, you may have done it by DIMensioning individual strings and then concatenating them (as described in the last article) and finally passing the concatenated string to MSGBOX. That's fine too! The tricky bit is the &quot;Cmb.ListCount&quot; which returns he number of items currently in the ComboBox. This is a number that gets coerced into a string which is then concatenated into the rest of it. Nothing too hard.&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;p&gt;The ComboBox event handler uses the same technique to display the item number of the item in the list that the user chose: cmb.ListIndex&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;Note that this doesn't show the &lt;b&gt;value &lt;/b&gt;of the item chosen, just the ordinal location in the list of the item chosen. We'll talk about how to get the actual number chosen next time!&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;p&gt; &lt;/p&gt;
&lt;p&gt;If you don't realize it, the above sample can be used as a basis for a simple calculator. We'll come back to this example from time to time as we learn more!&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;Onward to dissecting strings!&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;b&gt;Dissecting Strings&lt;/b&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;p&gt; &lt;/p&gt;
&lt;p&gt;We described how to set up strings via a DIM statement and how to assign them to variable and how to concatenate strings using &amp;amp; into longer strings last time. This time we talk about how to chop a string into pieces!&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;p&gt;Let's say you have a string that someone typed in. A first name, a space, and a last name, and you want to make your program friendlier and just use the person's first name when you display a message:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;p&gt;Serg&amp;lt;space&amp;gt;Koren&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;and you want to do a MSGBOX FirstName&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;p&gt; &lt;/p&gt;
&lt;p&gt;You could have them enter just their first name in a field, and have a separate field for the last name. But sometimes this is too much work for the user. So lets say we get the full string somehow.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;font size=&quot;-1&quot;&gt;&lt;span style=&quot;font-size: 13px;&quot;&gt;DIM FirstLast&lt;/span&gt;&lt;/font&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;font size=&quot;-1&quot;&gt;&lt;span style=&quot;font-size: 13px;&quot;&gt;FirstLast = &quot;Serg Koren&quot; &lt;/span&gt;&lt;/font&gt;&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;We have a string! We know how to add stuff to it such as&lt;/tt&gt;&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;Prompt = FirstLast &amp;amp; &quot; how are you?&quot;
&lt;/tt&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;p&gt;But how do you just get the first name? Or just the last name? Or maybe the space in the middle? It's not very hard, since NSBasic provides a rich set of Functions that let you do just that. Let's start simply and assume you &lt;b&gt;know the length of the substring you want to extract, and that the substring starts at the very left of our parent string. &lt;/b&gt;Just use the LEFT function. LEFT takes two parameters, the string you want to chop up, and the number of characters from the left you want to take. What you get is a substring with those restrictions. So if we know the first name is 4 characters long:&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;Section1&quot;&gt;&lt;/div&gt;
&lt;blockquote&gt;&lt;div class=&quot;Section1&quot;&gt;&lt;pre style=&quot;font-family: Courier; font-size: 13px; white-space: pre;&quot;&gt;&lt;tt&gt;&lt;font size=&quot;-1&quot;&gt;&lt;span style=&quot;font-size: 13px;&quot;&gt;DIM First, FirstLast,FirstLength&lt;/span&gt;&lt;/font&gt;&lt;/tt&g