My first application

Erel

Administrator
Staff member
Licensed User
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).

 

Attachments

ArchiMark

Member
Licensed User
THANK YOU, Erel!!!

Erel,

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

:sign0060:

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
 

ArchiMark

Member
Licensed User
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
 

ArchiMark

Member
Licensed User
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..... :rolleyes:

Thanks,

Mark
 

ArchiMark

Member
Licensed User
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
 

kyto

Member
Licensed User
Thank you.

Thanks for providing this tutorial, very didactic, and it will be quite useful for us the beginners.
:sign0098:
 

chengjunzh

Member
Licensed User
how to make the .exe file can install from pc?

or how to make the exe file can be installed to the ppc OS?

i mean after install , it can be seen from the menu in os not from the path copy to.

i am new and not very good at english, so if have any answers already, please notice me,thans!
 

RacingDog

Active Member
Licensed User
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.
Er, no, actually it is the extended example that is wrong. An extra End If has been included, possibly because the layout made it look like one was needed. The final If is attached to the Else, being on a new line doesn't change that, so only one End If is needed.

If there were an ElseIf (or similar) keyword, then using Else If would start a new If statement, but there isn't.

Hope this helps.
 

RacingDog

Active Member
Licensed User
Sorry, my mistake. I was looking for an explanation of what the previous poster was suffering from, and in my haste I left out the new line. Dang! I'm sorry. But in that case, add me to the ranks of those mystified by his problem!
 

roki

Member
I Am An Electriction And I Want A Hand Book About This
I Think If I Khnow This Software To Make Several Information In My Pda It Help My Allso I Use Ecxle Mobile And Make Hand Book But It Is Difficult
 

adex1

Member
Licensed User
Yep, I know anyway thanks. I am just checking if Erzel is still planning to support Windows Phone.
 
Top