Windows Mobile

There is nothing for Windows Mobile.

Visual3D™ Graphics Library

NSBasicCE Tutorial

Lessons in NSBasicCE


vns_textmedium

Programming Using NSBasicCE

All content (c)1999-2007 Serg Koren and VisualNewt Software.

All rights reserved.

List of Articles:

  1. The Package and Installation.

    Discussion of the history of BASIC, and how it relates to MS VisualBasic and NSBasic. Steps needed to install NSBasic on a Casio-E105 are described.

  2. The Editor and Modes.

    A complete discussion and exploration of the NSBasic programming environment detailing every menu item. A description of Immediate and Programatic mode programming with examples.

  3. Objects, Properties, and Methods! Oh My!

    A beginner's explanation of Object-Oriented-Programming (OOP) with emphasis on NSBasic.

  4. CommandButtons.

    An explanation of how to use CommandButtons in NSBasic.

  5. MSGBOXes, SUB and FUNCTION

    What SUBroutines and FUNCTIONs are and how to use them, basic parameters, and the MSGBOX user-interface widget.

  6. CheckBox and Variables

    A discussion of variables, how they are stored in memory, how to use them, and the CheckBox widget.

  7. Strings and COMBOBOX

    We talk about what strings are, and how to use them and combine them. We also look at the ComboBox object.

  8. Dissecting Strings and the Date Object

    We follow up our discussion on strings and talk about taking them apart. We also look at the buggy and barely usable Date Object.

  9. Arrayed Things and the INPUTBOX

    This article deals with arrays, what they are, how to set them up, and use them. We also talk about the INPUTBOX and what it is good for.

  10. Decisions, the Label and ListBox

    Getting your program to decide things for itself, and how to put labels on your screen, along with the ListBox object.

  11. DejaVu Again

    Getting your program to loop, and the OptionButton object.

  12. FOR EACH, INSTR, and the PICTUREBOX object

    A powerful new kind of loop, searching for a string in a string, and graphics.
  13. PRINT, REDIM, and the TEXTBOX object

    Printing information to the screen, resizing arrays and text objects.

nsblogo2_textmedium

Sieve For PocketC & NSBasicCE


This source code is freeware. However, please do not distribute modified versions. Thanks.

This code should compile and run using PocketC .

This code should run using NSBasic.

If you download and run this program, please send me your timings and I'll post them here for comparison purposes.

The Source Code

NOTE: It appears that on WindowsCE the more memory you can give programs the faster this runs. The above timings are the fastest noted.

POCKET C

//----------------------------------------------
// Sieve
//
// Serg Koren
// VisualNewt Software
// http://www.VisualNewt.com
//
/ Serg@VisualNewt.com
//
// Ver 2.0
// Total rewrite to work under PocketC b1.30
//
//------------- //
/* Global defines */
#define WS_CHILD 0x40000000
#define WS_POPUP 0x80000000
#define WS_VISIBLE 0x10000000
#define SIZE 8193
#define TRUE 1
#define FALSE 0
/* Interface controls - menu */
#define MF_SEPARATOR 0x0800
#define MF_ENABLED 0x0000
#define MF_STRING 0x0000
/* Event types */
#define PM_BUTTONUP 5
#define PM_COMMAND 8
/* Our button */
#define SIEVE 100
 /* our sieve array */
#define SIZE 8193
int x[SIZE];
//---------------------------------------------- //
// ShowResults - update our labels
//---------------------------------------------- //
ShowResults(int start, int end, int elapsed)
{
   text(20,56, "Start: " + start);
   text(20,83,"End: " + end);
   text(20,108,"Elapsed:" + elapsed);
   text(20,140,"");
}
//---------------------------------------------- //
// DoIt
// The main sieve logic. Pass in the max.
// number of primes to search to.
//---------------------------------------------- //
DoIt(int n)
{
   int i, j, k, p, iter, start;
   text(20,140,"Working...");
   start = ticks();
   for (iter = 1; iter <= 10; iter++)
   {
      x[1] = 0;
      for (i = 2; i <= n; i++)
         x[i] = 1;
      p = 2;
     while (p * p <= n)
     {
         j = p;
        while (j <= n)
        {
	      x[j] = 0;
	      j = j + p;
	    }
	    do
	    {
		    p++;
		} while (x[p] != 1);
     }
   } // output details
   j = ticks();
   k = j - start;
   ShowResults(start,j,k);
   // display an alert with results
   alert("Done! In: " + k + " ticks.");
}
//---------------------------------------------- //
// draw_form
// Setup our GUI
//---------------------------------------------- //
draw_form()
{
   menu_on();
   menuins(0,0,MF_SEPARATOR,200,"");
   menuins(0,0,MF_ENABLED|MF_STRING,201,"PalmOS (5120)");
   menuins(0,0,MF_ENABLED|MF_STRING,202,"Full (8192)");
   text(20,56,"Start:");
   text(20,83,"End:");
   text(20,108,"Elapsed:");
   text(20,140,"");
   createctrl("BUTTON","Sieve",WS_CHILD|WS_VISIBLE,0,82,150,75,25,100);
}
//----------------------------------------------
// SetupAbout
// Build our about box
//---------------------------------------------- //
SetupAbout()
{
	about("SieveCE - PocketC by Serg Koren. VisualNewt Software http://www.VisualNewt.com/ Ver. 2.0");
}
//---------------------------------------------- //
// MAIN
// our main routine
//---------------------------------------------- //
main()
{
	int e,g,m,k;
	int NotDone;
	NotDone = TRUE;
	draw_form();
	SetupAbout();
	while (NotDone)
	{
		e=event(0);
		k=key();
		if (e == PM_BUTTONUP)
		{
			g=guiid();
			if (g==SIEVE) DoIt(5120);
			m=menu();
		}
		if (e == PM_COMMAND)
		{
			g = guiid();
			if (g == 201)
			   DoIt(5120); // PalmOS
			else if (g == 202)
			   DoIt(8192); // Full
			m=menu();
		}
	}
}
//-------------------END------------------------


WIndowsCE


'----------------------------------------------------
' Sieve
'
'   Serg Koren
'   VisualNewt Software
'   http://www.VisualNewt.com/
'   Serg@VisualNewt.com
'
' 03/19/99
'    Ver 1.0
'
'------------------------------------------------------
'
OPTION EXPLICIT
DIM Version  ' version string
Version = "Ver. 1.0"
'------------------------------------------------------
' DoIt
'
' The actual sieve logic.
'------------------------------------------------------
'
SUB DoIt(size)
 Feedback.Caption = "Working..."
 UPDATESCREEN ' allow menus to refresh, etc.
 DIM i, j, k, p, iter, howlong
 DIM x(8193)
 howlong = NOW
 FOR iter = 1 To 10
  x(1) = 0
  FOR i = 2 TO size
   x(i) = 1
  NEXT
  p = 2
  WHILE p^2 <= size
   j = p
   WHILE j <= size
	x(j) = 0
	j = j + p
   WEND
   DO
	p = p + 1
   LOOP WHILE x(p) <> 1
  WEND
 NEXT
 j = NOW
 ' display results
 Feedback.Caption = ""
 Start.Caption = "Start: " & howlong
 EndL.Caption = "End:  " & j
 Elap.caption = "Elap.: " & DATEDIFF("s",howlong,j) & " sec."
END SUB
'------------------------------------------------------
' About menu item
'------------------------------------------------------
'
SUB About_click
 DIM T
 DIM CRLF
 CRLF = CHR(13) & CHR(10)
 T = "SieveCE - NSBasic" & CRLF & "by Serg Koren" & CRLF & CRLF & "VisualNewt Software"
 T = T & CRLF & CRLF & "http://www.VisualNewt.com/" & CRLF & CRLF & Version
 MSGBOX T,vbOKOnly,"About Sieve"
END SUB
'------------------------------------------------------
' Exit menu item
'------------------------------------------------------
'
SUB Exit_click
 BYE
END SUB
'------------------------------------------------------
' PalmOS sieve request
'------------------------------------------------------
'
SUB PalmOS_click
 DoIt(5120)
END SUB
'------------------------------------------------------
' Full sieve request
'------------------------------------------------------
'
SUB Full_click
 DoIt(8192)
END SUB
'------------------------------------------------------
' Sieve button clicked
'------------------------------------------------------
'
SUB Sieve_click
  DoIt(5120)
END SUB
'------------------------------------------------------
' SetupMenus
'------------------------------------------------------
'
SUB SetupMenus
 DIM titlebar
 titlebar = ARRAY("&File","&Command")
 SETMENU "titlebar",titlebar
 DIM fileMenu
 fileMenu=array("About||About","-","E&xit||Exit")
 SETMENU "&File",fileMenu
 DIM commandMenu
 commandMenu=array("Full (8192)||Full","PalmOS (5120)||PalmOS")
 SETMENU "&Command",commandMenu
END SUB
'------------------------------------------------------
' SetupLabels
'  for user feedback
'------------------------------------------------------
'
SUB SetupLabels
 ADDOBJECT "Label", "Start", 10, 10, 200,20
 Start.Caption = "Start:"
 Start.BackColor = Output.BackColor
 ADDOBJECT "Label","EndL",10, 30, 200, 20
 EndL.Caption = "End:"
 EndL.BackColor = Output.BackColor
 ADDOBJECT "Label","Elap", 10, 50, 200,20
 Elap.Caption = "Elap.:"
 Elap.BackColor = Output.BackColor
 ADDOBJECT "Label","Feedback", 10,70,200,20
 Feedback.Caption = ""
 Feedback.BackColor = Output.BackColor
END SUB
'------------------------------------------------------
' SetupButton
'------------------------------------------------------
'
SUB SetupButton
 ADDOBJECT "CommandButton","Sieve", 50, 130, 50,20
END SUB
'------------------------------------------------------
' SetupGUI
' Build our user interface
'------------------------------------------------------
'
SUB SetupGUI
 SetupMenus
 SetupLabels
 SetupButton
END SUB
'------------------------------------------------------
' MAIN
'------------------------------------------------------
'
SUB Main
 SetupGUI ' and wait for events
END SUB
'------------------------------------------------------
'------------------------------------------------------
' run the program
Main
'------------------------------------------------------
'------------------------------------------------------
'----------------------END-----------------------------
©2008, 2009, 2010 Serg Koren & VisualNewt Software.  All rights reserved.