Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Code Samples & Tips > Tutorials
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Tutorials Basic4ppc tutorials


My first application


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-17-2007, 04:47 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 2,561
Default My first application

Welcome to Basic4ppc community!
In this tutorial we will take you step by step as you build your first (simple) application.
The screen shots are taken from the desktop IDE but it is basically the same as building it on the device IDE.
The code is attached to this post.
Lets start:
Open Basic4ppc.


Start with building the GUI.
Choose Designer - Create New Form



Using the Controls menu, add one Button, one TextBox and one Label.
Move and resize the controls by dragging them with the mouse.
Important controls should have a meaningful name, so change Button1 name to btnGuess and TextBox1 name to txtNumber.
Change the controls' text to match the above screen shot.

Basic4ppc is an event driven language, which means that the application waits for the user to do something and then executes the relevant code.
Add a button click event to btnGuess by choosing the button and selecting Events - Click.



This will create a sub named btnGuess_Click in your code.
Note that you could also manually create a sub with the same signature and it will handle the event.

Now it's time to write the code.

Variables could be either global or local.
Local variables could only be used inside their sub and they are recreated in each call.
Global variables could be used anywhere. Global variables should be declared inside Sub Globals.
It is not required to use the Dim keyword with regular variables (not arrays / structures). You could just write number = 0 or number = 23 instead of Dim number.
Note that regular variables are variant variables, they can hold both numbers and strings.



Back to our code. We declare a global variable named number.
The first sub that always run is Sub App_Start.
We do two things in this sub, we show Form1 and we set number value to be a random number between 1 to 100 (actually 99).

Now we handle the btnGuess click event.
First we check that the user text is a number using the IsNumber method.
If it is not we show a msgbox and return.
If it is a number it is compared to our number.
You could now run your code by pressing F5 or choosing Debug - Run.

We now improve our game by allowing the user to play another game and by returning the focus to txtNumber after each guess.



Using the fact that Msgbox returns a value based on what the user chose, we check if the user pressed on the Yes button (cYes is a constant).
Another important constant that is used here is crlf which adds the newline characters to the string.
If the user pressed on the No button we close the application using AppClose.
AppClose closes the main form (exactly the same as Form1.Close in our case).

A little bit about debugging (only on the desktop):
You could add breakpoints to your code, breakpoints are lines that will stop the execution and will allow you to check any important values.
Adding a breakpoint is done by pressing on the left bar.



Now when we press on btnGuess the execution will stop.
It is not clear in the screen shot, but the mouse hovers over the number variable and it shows 42.
By hovering over any variable you could see its value.
More complicated values could be seen using the Watches at the bottom of the screen.
To continue running your code you can press F5, if you want to continue step by step press F8 (F9 also continues step by step without getting into deeper subs, F10 continues step by step but only after getting out of the current sub).

Attached Files
File Type: sbp GuessMyNumber.sbp (1.4 KB, 138 views)
Reply With Quote
  #2 (permalink)  
Old 09-17-2007, 04:54 PM
Junior Member
 
Join Date: Sep 2007
Location: Silicone Valley
Posts: 26
Thumbs up THANK YOU, Erel!!!

Erel,

A BIG 'THANK YOU' from this code noob for taking the time to put this tutorial together!!



It really helps noobs like me to literally see how to use your IDE to put together a program in order to get started using it.

If possible, over time if you can add one or two more tutorials that illustrate some other concepts I think that this would be a big plus too....

THANKS,

Mark
__________________
Silicone Valley Digerati/Code Noob
HTC Advantage X7501/WM6
Kohjinsha SH6/Vista HP (For Sale, PM me...)
MacBook C2D
Reply With Quote
  #3 (permalink)  
Old 09-17-2007, 05:43 PM
Junior Member
 
Join Date: Sep 2007
Location: Silicone Valley
Posts: 26
Question

Tried tutorial and first part works OK.

However, getting error message after I added in the code for the last part where you update program to improve game.

I get the error message:

Missing Keyword 'End Sub'

It refers me to the second line of 'End If' below:

"Else
AppClose
End If
End If"

Any suggestions?

Thanks,

Mark
__________________
Silicone Valley Digerati/Code Noob
HTC Advantage X7501/WM6
Kohjinsha SH6/Vista HP (For Sale, PM me...)
MacBook C2D
Reply With Quote
  #4 (permalink)  
Old 09-17-2007, 05:46 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 2,561
Default

You are probably missing an End If or a Then.
Download the code file (attached in the first post) and try to compare it to your code.
Reply With Quote
  #5 (permalink)  
Old 09-17-2007, 11:27 PM
Junior Member
 
Join Date: Sep 2007
Location: Silicone Valley
Posts: 26
Default

Quote:
Originally Posted by Erel View Post
You are probably missing an End If or a Then.
Download the code file (attached in the first post) and try to compare it to your code.
Did that Erel, but my code is the same as yours...very strange....

Tested your and it runs OK but I still get error message.....so I must have something different.....

Thanks,

Mark
__________________
Silicone Valley Digerati/Code Noob
HTC Advantage X7501/WM6
Kohjinsha SH6/Vista HP (For Sale, PM me...)
MacBook C2D
Reply With Quote
  #6 (permalink)  
Old 09-18-2007, 02:05 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 2,561
Default

Please create a new thread in the Questions sub forum and upload your code file.
Reply With Quote
  #7 (permalink)  
Old 09-18-2007, 02:58 AM
Junior Member
 
Join Date: Sep 2007
Location: Silicone Valley
Posts: 26
Lightbulb

Quote:
Originally Posted by Erel View Post
Please create a new thread in the Questions sub forum and upload your code file.
OK, will do soon....

In the meantime, thanks again for providing the tutorial....

Mark
__________________
Silicone Valley Digerati/Code Noob
HTC Advantage X7501/WM6
Kohjinsha SH6/Vista HP (For Sale, PM me...)
MacBook C2D
Reply With Quote
  #8 (permalink)  
Old 09-18-2007, 06:56 AM
Junior Member
 
Join Date: Aug 2007
Location: México.
Posts: 27
Smile Thank you.

Thanks for providing this tutorial, very didactic, and it will be quite useful for us the beginners.
Reply With Quote
  #9 (permalink)  
Old 10-16-2007, 01:00 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 2,561
Default

You should post your question here: http://www.basic4ppc.com/forum/forumdisplay.php?f=2
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
GPS application - Part I Erel Tutorials 4 02-13-2008 06:39 AM
GPS application - Part II Erel Tutorials 1 11-28-2007 05:07 PM
Minimize Application akr Questions & Help Needed 4 10-18-2007 07:51 PM
execute , run , another application giannimaione Questions & Help Needed 3 05-04-2007 09:04 PM
DB Application scott93727 Share Your Creations 0 05-02-2007 05:24 AM


All times are GMT. The time now is 09:57 AM.


Powered by vBulletin® Version 3.6.10
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0