Programming

Homepage  tutorials About me Programming Screenshots Distros Links Realbasic programs 1 Rb programs 2

Basic shell programming introduction

we're going to start off by writing our first shell script. First of all fire up your favourite text editor.If you're not sure what a text editor is or what text editor you should use,then take a look at these ones.By default if you're running the gnome desktop you should have pre-installed version of gedit.Other well known text editors include...kwrite, emacs, vi,tea, kedit, to name but a few.

Ok type this into your text editor..........................................

#!/bin/bash

# test script

echo "running my first test script"

*Now save your file as testscript.

The first line of the program tells us which program will interpret this script.So for this case it'll be /bin/bash The second line is just a comment and everything that appears after # is ignored.

In the last line you'll see the echo command, this simply is just a print command. And it will print out the words "running my first test script"

Setting permisions 

The next thing we need to do is to give the shell permision to execute the script.We can acheive this by using the chmod command.

Simply type this into your terminal................. chmod 755 testscript.

Then press enter, next type into your terminal this.........   ./testscript  "and hit enter"

The output you should see in your terminal should be this........ running test script

Congratulations, you've just written and executed your first shell script!

A further note on permisions,  755 = gives read write and execute permissions

If you want your script to be private, which means only you can read and execute it. Then type in 700 instead. 

Mark. 

Basic shell commands

We're going to start off with a few easy shell commands.So open your favourite terminal program and let's begin.
 
last = will show you the person that last logged in, and if they're still logged in.
echo = is the print command.
date = date and time and year.
Who = Who is logged in
w = similiar to who but with more information given. 
cal = shows a calendar
df =  shows how much free space there is on your disks.
tty = identify your workstation
 
Files and commands 
 
ls                will print out a list of files in a particular directory
sort            sort the contents of a file
more          use to page on large text files
less            similar to the more command
cp               copy a file
rm              will remove / delete a file
mv              will move a file
wc              will retur a word count + characters and lines
pwd            prints your working directory
cd              changes to a new directory
mv              move a directory
mkdir          make a new directory
rmdir          remove a directory 
 
How to create a new directory 
 
1. Open up a terminal window
 
2.Type in mkdir "mydirectory"      "this example the new directory is called mydirectory" 
 
3. Hit enter and view your new directory in your home folder.
 
 
How to remove a directory 
 
1.open a terminal window
 
2. type in...........rmdir "mydirectory"
 
3. Hit enter
 
4. Another command you can use to remove directories is  rm -r "directories name" this is handy for removing directories that require root user privileges.You might need to be logged in as root to remove these directories. 
 
Mark. 
 
 
Looping with real basic 
 
We're going to create a simple application that will show us how loos work. First of we're going to use the   for / next loop 
 
So start up realbasic and on your new form / window put a listbox onto it, you'll find the listbox in the toolbox on the left. Then put a pushbutton on your window as well.
 
double click on the window to bring up the code section, and in the code section add this line.
 
self.title = "loops" (this will appear as the name on the top of your program)
 
Now change the pushbuttons name to "button1"  and it's caption to "enter" then double click on the pushbutton and type this code in.
 
dim numberarray(2) as string
dim x as integer
 
for x = 2 to listbox1.listcount- 1
numberarray(x) = listbox1.list(x)
next
 
msgbox "mark"
msgbox "dave"
msgbox "paul"
 
Now double click on the window to bring up the code area. In it type the following.......
 
listbox1.addrow "mark"
listbox1.addrow "dave"
listbox1.addrow "paul"
 
Now go back to your program and run it. When it runs you'll be able to see the names in the list box. Click on one and press enter. A message box will come up, then just ok it, and another one will come up. Your program will loop through the names until they're finished.
When you create an array as above the computer always starts counting at zero. Our array goes up to 2, and we have three names, so the array works like this.
mark 0  dave 1  paul 2        Something you should always remember when your working with arrays.
Mark. 
 
Creating a simple password program 
 
Fire up realbasic and in the gui select project-add-window. You'll see that it adds a new form/window if you click on the project tab on the top left hand side. Put a text box onto your window name it text one and in the properties window put a tick in the box called "password" this will make the letters show up as small round black circles when you type your password into the text box. Next add a pushbutton onto your window and name it "button1" and it's caption "enter password".  Double click on the button and enter the code below.
 
dim password as string         (string means it's a letters and not numerical) 
 
password = text2.text
 
if password = "mark" then
window2.show                    
else                                   
msgbox "Try again"            
end if                                  
text2.text = ""                     
text2.setfocus                     
 
Now when you enter the correct password into the box, window 2 will appear, or if you enter the wrong password, you'll get a message box telling you so.
Mark. 
 
 

 

RealBasic

REALbasic is a rapid application development (RAD) environment that provides developers a marked increase in productivity over other cross-platform development tools. REALbasic includes drag-and-drop capability to enable you to quickly create a user interface design, then incorporate the code behind it to add power and functionality.

Migrate Visual Basic applications to Linux and Mac OS X

REALbasic is highly compatible with Visual Basic, so Visual Basic developers are productive very quickly with REALbasic. REALbasic also comes with a utility to help convert Visual Basic projects to REALbasic where they can be compiled for Windows, Mac, even Linux -- with the click of a checkbox.

Create native cross-platform software

REALbasic 2007 runs on and creates software for Windows 98, NT, ME, 2000 and XP, Mac OS X and Linux, all from a single set of source code. REALbasic incorporates platform-specific intelligence, like user interface widgets, so software created with REALbasic looks and feels native, regardless of the development platform you created it on.

Create powerful database applications

Build powerful database applications with REALbasic's built-in REAL SQL Database, based on the SQLite public domain database engine. Connect to external multi-user database engines using REALbasic Professional Edition.

Create graphics for multimedia applications or games

Use REALbasic's support for standard image formats for vector graphics, (such as those commonly created with Adobe Illustrator). Use REALbasic's Real-time 3D Engine to add interactive real-time rendered three-dimensional graphics with built-in tools. Also, use REALbasic's Sprite Animation Engine to develop interactive sprite surfaces with collision detection already built-in.

From realbasic.com

 

 

 


Realbasic programming tutorials

Ok in these tutorials we're going to be looking at creating a few basic programs.First off get your ass over to realbasic. com and download realbasic for your particular platform! You can write applications for Linux, mac and windows using this suite, pretty neat heh?

Tutorial 1 what's my name? 

1. open up the real basic  and double click on window1 which you should see, this will take you through into another window. You'll see a form/window ready for you to start work on.To the left you'll see a toolbox, with various widgets in it, pushbutton, editfield, etc. These can either be double clicked on or dragged on to your window.

2.First off , drag or double click on editfield in your toolbox, then the same with pushbutton,  statictext. Now you should be able to see a pushbutton, statictext box + an editfield all on your window.

3Arrange these any way you want. If you check the properties window on the right hand side you'll see that all of these have their own properties which you can altar.

4. Start with editfield.............. single click on it and change it's name property to "text1"

ok next......... single click on the pushbutton and change it's name property to "button1"

and finally........single click on the statictext box and change it's name to "sttext1"

5. No  single click on your button1 and look in your properties window.Scroll down until you see it's caption property. Change it's caption property to "Enter" and then click on run to run your program. You'll be able to see your what your program looks like at runtime.

6. Go back to your form and double click on button1, this'll bring up a code window where you can put your code into. Type the following code into it...............................

dim name as string

 

 name = text1.text

 

 sttext1.text = text1.text

7. Ok run the program and type your name into the text box then click enter, you'll then see your name displayed in the sttext1 box :-) Pretty good for just a few lines of code heh? 

Mark. 

Let's take our program a step forward 

We've seen what we can do with a few objects and a couple of lines of code. Now open your project, which I hope you saved from last time.

Ok when we click our button we see the name appear in the static text box below right? So have a look at the text box above. Do you notice anything? Yes the name is still in the box, and we don't want that do we? So we're going to insert a line of code which will remedy this problem!

In your pushbutton just insert this line of code below the sttext1 line.

text1.text = ""

What does this line of code do? Well it'll clear anything that was previously in the text box!

We have another minor problem now, can you spot it? Well if you said the colour on my form is pink, then you deserve a poke up the bum with a red hot iron! If however you spotted that there is no focus in the text box, you'd be correct! So how do we get the focus back?  Under your text1.text = "" line, insert this line of code..............

text1.setfocus

Now run your program again! Voila the focus should be in the text box!

Mark. 

Clearing our name from the static text box 

So how do you get rid of the text that has appeared in the static text box below? First put a new pushbutton onto your window, then in the properties window, change it's name to button2 and it's apperance caption to clear text.

Then double click on the button and add this code into the window.

sttext1.text = ""   

yes you should remember the code from the last part. This code will clear any text from the box. Go ahead try it!

Now add another pushbutton to your form, place it at the bottom right hand side. Then name it button3 and it's caption property to Exit!Double click on the button and in the code window type in this code.............................................

window1.close

Now run the program, and click on the exit button, what happens? wow it closes the program! With just that one line of code.

Nearly forgot, we need to call our program something, so double click on the form / window and it'll bring you to the windows code section. Now type this in..................

self.title = " my program"

Now run your program and look at it's name "my program :-)  

If.....then.....else  

How does a computer make a decision? Well one method is to use the if/then/else clause. We're going to modify our previous program to incorporate this new language.

Open your previously saved program and double click on the enter button to bring up the code window. Then enter the new code, when all is finished your code window should look like this.

dim name as string

 

name = text1.text

sttext1.text = text1.text

 

if name = "mark" then 

sttext1.text = ""

msgbox "hi mark"

else

sttext1.text = ""

msgbox "who are you"?

end if

text1.text = ""

text1.setfocus

Now lets take a closer look at the code we've just used.

if name = "mark" then....(if the name is equal to mark then)

sttext1.text = "" (statictextbox is empty)

msgbox "hi mark" (message box says hi mark)

end if   (end the block of code)

text1.text = "" (text1 box is clear)

text1.setfocus (focus is set back to text1)

Mark.