|
Buttons and Pictures as Buttons A Button is a switching surface, over which one you can call a function in the program. For example: this can be a text input, or it can be open a new window. How to create a Button: |
||
|
button 50, 30 to 150, 60, "Name of the Buttons", "displayed Name of the Buttons", "View" |
||
|
With button 50,30 to 150, 60, you set the positionen and size of the Button. The Button will placed at 50 Pixel from the left site of the Programwindow and 30 Pixel from the opper site of the View. The Button size is 100 to 30, so you need to add this numbers to the position numbers, so you get 150 and 60. At "Name of Button" you set a name for the Button. With this name you can declaire a function intern of the programcode. At "displayed Name of the Buttons" you set the displayed name of the Button. This one see the user of your application. With "View" you set the View on that the Button are displayed. If the name of your View is MainView or Peter you need to use this name. Buttons and Pictures as Button You also can use Pictures as Buttons: |
||
|
button image 50,100, "Name of the Button", "Picture 2", " Picture 1", " ", "View" |
||
|
We also setting with button 50, 100 the postition of the Button, starting from the left and opper site of the View. We dont need to set the size of the Button, this is automatic the size of the picture. At "Name of Button" you set a name for the Button. With this name you can declaire a function intern of the programcode. At "Picture 2" you set the path to the second Picture of your Button and at "Picture 1" the first one. Why we need two pictures? You can set here at both places the same Picture, but you dont see that you have used it, then you use two Pictures, you can show two Button positions, like "used" or "not used". With "View" you set the View on that the Button are displayed. Using a Button for a function (Example: case) To include a Button into the programcode place following code into the Mailloop: |
||
|
case "Name of the Button|":
|
||
|
At "Name of the Button|" you write the name of the Button, you declaired for using into the programcode. At here the programcode you include the programcode, you want to run then the Button used. With break we close the case. back to Table of Content Back to Index |
||
|
Create and use an Array An Array is a collection of various value from a Variable. The value you can include into aa Array can be Variables. Creating a Stringarray (Strings are series of signs): |
||
|
dim Name_of_Arrays$(2) |
||
|
First we need to dimension the Array with the command dim Name_of_Arrays$(2) . The Array get the Name Name_of_Arrays$. The $ sign set this Array to collect only Strings (series of signs). With a Number between the clamps (2) you set the size of the Array, and the maximum size for including data into the Array. To include Data or a Variable into the Array, you need to do this: |
||
|
Name_of_Arrays$(0)="contents1" |
||
|
First you write the name of the Arrays Name_of_Arrays$. Behind that, you write the clamps and the number of the first, second... (0) entry. The characteristic with the counting is, that you begin with the 0 and not with the 1. With the equality sign (=) you deliver the data to the Array. If you want to deliver Strings to the Array, you need to set the Strings between inverted comma "contents1". If you want to deliver Variables to the Array, you only need to write the Variable behind the equality sign (=).
You can do the same with number Variables. This are Variables without the Dollar sign. Into a number Variable you only can write numbers. If you try to write text into a number Variable, you get errors into your programcode. |
||
|
How to read the content of a Array (for exampel): |
||
|
draw text 5, 38, ""+Name_of_Arrays$(0), "View1" |
||
|
With the command draw text you place a text on a declaired position on the screen (5, 38). Behind the position setting comes the text between the inverted comma. If the Array is the complete Text itself, you only need to place here the Arrayname. If you want to add some text to the Array, you need to write them between inverted comma and add the Array in front, behind or booth with a plus (+) sign. At this example we wont do display the first Entry (0) of the Array. If you have dimention the Array to 10 and you want do display the fifth Entry, change the number to 4 Name_des_Arrays(4). back to Table of Content Back to Index |
||
|
Create a Window Menu To include a menu into the window is easy. Use following code after your window settings: |
||
|
menu "File", "Open", "O", "View" |
||
|
With the command "menu" you include the menubar into the window. The first name ("File"") is the name showing menu name. The second name ("Open") ist the menuitem ( "File"). With the third entry ("O"") you can set a shortcut fort his menuitem. The shortcut is every time "Alt + Third menuentry ("O"). If you dont want to set a shortcut, only write "". The last entry ( "View"), you set the view on the window on that the menu is included. Then the menu needs free space of the view from 0 to 20. If you now set a View in the MainView that has a 0 point at the left and upper side, you have to set the menu in the View so it can be shown ... otherwise you want see it. Create an Submenu You can always create submenus: |
||
|
submenu "Datei", "Save", "Save As", "SA", "View" |
||
|
You include the submenu like the menu command, but you set one menupart more. At that position you want to include a submenu, you write the first menupart, then the second and then the submenupart. Behind that the shortcut and then the view. In our tutorial you create an menuitem with the name "Save" in the view "View" and then the submenu "Save As". |
||
|
Executing a menuitem
To run a function, you always use the menu (here "Save As"), use the name of the menuitem to run it. Here a "case" function to run that function: |
||
|
case "Name of the menupoint|":
|
||
|
back to Table of Content Back to Index |
||
|
Deactivate the window option "Zoom" Every window has the standard option to resize the window to full screen or normal screen. If your program window needs a fixed size you can deactivate this option. window open 175,250 to 525,450 , "internal view name", "viewable view name" window set *** |
||
|
window set "View", "flags", "not-zoomable" |
||
|
With window set we change the settings of a window. With "View" we define the name of the window we want to change. With "flags" we change a window option and the following option is the result we want to have. To make the window not zoom able we add the option "not-zoomable". This deactivates the zoom button in the TAB of the window. |
||
| width=600>
If you want to change more window option at the same time, you can add them behind one other separated by a comma. For example: the "Resize" option. |
||
|
back to Table of Content Back to Index |
||
|
Deactivate the window option "Resize" Every window has the standard option to resize the window to full screen or normal screen. If your program window needs a fixed size you can deactivate this option. window open 175,250 to 525,450 , "internal view name", "viewable view name" window set *** |
||
|
window set "View", "flags", "not-resizable"" |
||
|
With window set we change the settings of a window. With "View" we define the name of the window we want to change. With "flags" we change a window option and the following option is the result we want to have. To make the window not resizable able we add the option "not-resizable"". |
||
| width=600>
If you want to change more window option at the same time, you can add them behind one other separated by a comma. For example: the "Zoom" option. |
||
|
back to Table of Content Back to Index |
||
|
Delete blanks from a string output Should after the output of a file blanks before and/or behind an expenditure of a file to be, you can remove these with yab internal commands. To do this we use following commands: trim$(), ltrim$(), rtrim$() trim$() removes all blanks before and behind (left and right site) the String entry: |
||
|
trim$(Stringname$) |
||
|
ltrim$() removes all blanks before (left site) the String entry: |
||
|
ltrim$(Stringname$) |
||
|
rtrim$() removes all blanks behind (right site) the String entry: |
||
|
rltrim$(Stringname$) |
||
|
Example: |
||
|
Stringname$=" Hello Haiku "
|
||
|
Output="Hello Haiku " back to Table of Content Back to Index |
||
|
Display a Picture To display a picture is an easy thing: |
||
|
err = draw image 10,20 to 100, 120,"path and name of the picture", "View" |
||
|
We draw a picture with err = draw image left, upper to right, bottom. With the values behind this command you can set up the position of the picture on the view. We draw in the example a picture on the view 10 pixels from the left and 20 pixels from the upper edge of the picture to 100 pixels to the right and 120 pixels to the bottom edge of the picture. You don't need to setup the right and bottom position of the picture. If you use here a -1 or you leaf this information's away, the picture will be written automatically. |
||
|
err = draw image 10,20 to -1,-1,"path and name of the picture", "View" |
||
|
back to Table of Content Back to Index |
||
|
Display window without TAB Sometimes it looks better to show a window without the TAB. Example: -The window don't need a displayed name. - You don'tt want to give the option to close the window without quit by pressing an button to close the window. You can do this with following code: window open 175,250 to 525,450 , "Viewname", "Displayed name of the window" window set *** |
||
|
window set "Look", "modal", "View" |
||
|
With window set you set up a window option. With "Look" we tell the window, that we want to make something with the display of the window. With modal we tell the window to display the window without the TAB and View is the name of the Window. back to Table of Content Back to Index |
||
|
Edit Strings in YAB There are some commands to edit strings in yab. Someone of them change a string and other check them with another string. We want to explain some of there commands: left$() (no tranlsation available) mid$() (no tranlsation available) right$() (no tranlsation available) str$() (no tranlsation available) token() (no tranlsation available) val() (no tranlsation available) back to Table of Content |
||
|
left$() The command left$() returns delivery the left part of a String. The command needs two informations, the String you want to edit and a value. The Value setup the number of indications you want to get returned of the String. Example: |
||
|
print left$("This is a muster String",7) |
||
|
Over this exampe we give out a part of a String using the print command: This is a muster |
||
|
a$="This is a muster String"
|
||
|
The second example make the same like the first example, but we use a variable a$ to get the information. We give out the informations using the print command too. back to Table of Content Back to Index |
||
|
mid$() The command mid$() returns delivery a part of a String. The command needs three informations, the String we want to edit and two values. The first Value setup the number of indication we want to start from the left. The second Value setup the number of indications you want to get returned of the String beginning from that indication we setup with the first value. Example: We have a String called "Testing" and we want to get "ts" of it.: mid$(Testing,3,3). |
||
|
print mid$("This is a muster String",5,11) |
||
|
Over this exampe we give out a part of a String using the print command: is a muster |
||
|
a$="This is a muster String"
|
||
|
The second example make the same like the first example, but we use a variable a$ to get the information. We give out the informations using the print command too. back to Table of Content Back to Index |
||
|
right$() The command right$() returns delivery the right part of a String. The command needs two informations, the String you want to edit and a value. The Value setup the number of indications you want to get returned of the String. Example: |
||
|
print right$("This is a muster String",6) |
||
|
Over this exampe we give out a part of a String using the print command: String |
||
|
a$="This is a muster String"
|
||
|
The second example make the same like the first example, but we use a variable a$ to get the information. We give out the informations using the print command too. back to Table of Content Back to Index |
||
|
str$() With the command str$() you can convert a Value into a String. Example: |
||
|
a=5
|
||
|
We create a number-variable with value 5. We give out the converted number-variable using the print command. back to Table of Content Back to Index |
||
|
token() The command token() split a String with a definieten indication (delimiters). The command needs three informations. The String we want to edit, an Array to collect the splittet informations and a Separator (delimiter). The informations for the token() command are placed between the clasp ( )) and separated through a comma. Example: |
||
|
b$ = "1 Test Tree"
|
||
|
We create a string-variable b$ with the string "1 Test Tree". We want to split the string using the blank indication to get all parts of the string. To do this we create an Array d$ with the size "1". With n= token(b$,d$(), " " ), we get the number of parts of the splitted string. After this we create a for loop and include the parts of the string into the Array d$ using the value n. The for loop runs from the value i = 1 to i = n. To see the splitted parts the using the command print to give out the collected informations. back to Table of Content Back to Index |
||
|
val() With the command val() you can convert a string-variable into a number-varialbe. The function check if it is a floating point number. Example: |
||
|
a$="5"
|
||
|
We create a stringvariable with string "5". We give out the converted string-variable using the print<7i> command. back to Table of Content Back to Index |
||
|
Get actual Date and use it To get the actual date is an easy thing, because yab have a fixed variable for it. The name of the variable is date$ and can be used like every other variable. Display of the date: Month-Day-Year If you only want to display a part of the date or another sequence of it you can use an Array. Then you can split the information’s of the Array and display it as you like: |
||
|
im CurrentDate$(1) time = split(date$, CurrentDate$(), "-") Month$ = CurrentDate$(2) Day$ = CurrentDate$(3) Year$ = CurrentDate$(4) |
||
|
We create the Array CurrentDate$(1) with the a minimum size of 1. Then we split the variable date$ at every (-) sign and save them into the Array CurrentDate$(). After this we save the informations out of the Array into new variables. The month into the variable Month$ then the Day into the variable Day$ and the Year into the variable Year$. back to Table of Content Back to Index |
||
|
Get the position of the program folder in the system To get the position of the program folder in the system, installed by the user, you can use the shell tool "pwd" (print working directory). We save the path and the name of the program folder into the variable "WorkDir$". This variable you can use on every position in your application to integrate the position of the program folder (for example: displaying a picture). Add following code in the beginning of your program source: |
||
|
if (peek("isbound")) then
|
||
|
Here an Example how to use this variable. You have a folder for your programs graphics named "graphic" and a graphic file named "Logo.png". To display this graphic file using the variable enter the code as you know ("/graphic/logo.png"), but use for the path to the file the Variable (WorkDir$+"/Logo.png"). |
||
|
err = draw image 90,35, WorkDir$+"/graphic/Logo.png", "MainView" |
||
|
|
||
|
back to Table of Content Back to Index |
||
|
Make lines of the Source code not useable. Make lines not useable is a very practical thing. You can use it to make notes into the Source code or if you have problem with a source part you can deactivate him. There are two commands to deactivate lines. |
||
|
# Text or Program code |
||
|
The command # can only be use out of a loop. If you want to use this command in the loop too, you need to add a REM in front of it. back to Table of Content Back to Index |
||
|
Place Window on center of the Screen In order to find out how to place you're ProgramWindow in the center of the screen you need to found out how big the screen resolution is. To do this you need to place this code in the upper part of you're source (before the loop). Why in the upper part? Well with this way you can use the code on all positions in your program to get the values for the screen. |
||
|
ScreenWidth = peek("desktopwidth")
|
||
|
With peek("desktopwidth") you get the size of your screen (width) and save that into the variable ScreenWidth. With peek("desktopheight") you get the size of your screen (height) and save that into the variable ScreenHeight. With this information you can include the info into the Window size settings of your program. |
||
|
window open ((ScreenWidth/2)-300), ((ScreenHeight/2)-300) to (( ScreenWidth /2)+300), (( ScreenHeight/2)+300), "displayed name of the view", "View" |
||
|
We create a new window with the window open command. The position for the windows is here not only the number for the left, right, upper and top of the window, we also need to divide the of ScreenWidth and ScreenHeight with 2 and then we need to take half of the value we need to place the window to the left/right and top/bottom ((ScreenWidth/2) -300 and ((ScreenWidth/2) +300), ((ScreenHeight/2) +250) and ((ScreenHeight/2) +250). So we now get a window of 600 x 500 Pixels. After this you need to set the displayed name of the window as shown in the WindowTitle and the name of the window (View) to be used inside the source. back to Table of Content Back to Index |
||
|
Reading an CSV File The entrys of the File that needs to be be read should be split with the ";" sign. You don't need to set this sign behind the last entry of the line. The source for reading an CSV File is: |
||
|
d=0 |
||
|
We call a subroutine (load) and add a variable (d) to it with the value 0. Adding this variable is important, because when you don't do this every time you call the subroutine, you will add the value to the array and it wont get the actual value0. You need to start calling the subroutine with the value 0. Next step, we create a variable fileload$ and include into it the path to the csv file. After this we create a variable to collect the value of the readed entrys of the csv file. We name this variable readout. So we can load the csv file with the command open(fileload$, "r"). We open the csv file (fileload$) and tell him to read ("r") this file. After this we create a variable "x" with the value 0. Next step we open a while loop, and tell it to read the file from the first to the last entry (EOF = End of file). With the line input #readout b$ we read the entries of the file and collect them into the variable b$. After this we create an Array elements$ with the size 1.
We split the entry of the Array elements$ with numElements = split(b$, elements$();";")
and collect the value of lines into the varialbe numElements.
|
||
|
Read File line by line The entrys of the File you want to read need to writen one beneath the other. The code to read this file line by line is: |
||
|
fileload$="/boot/home/textfile.txt"
|
||
|
First we create a Variable fileload$ and write the path to the textfile into it. Since the program does not know momentarily, how the file is called, we must assign a further variable for these. We call this variable readfile. We open this file with the command open(fileload$, "r"), the "r" ist the command for "read". After this we open a while loop with the function to read the file from beginning to the end (EOF = End of File). With x=x+1 we ascertain the size of the Array. Everytime the loop runs through, the value x will be raise +1. You can understand this as an ascertainment how many line the file have. We create with dim d$(x) an Array in order to save the collected data into it. We read with line input #readfile b$ all entrys of the File and save them into the variable b$. Next we include the variable b$ into the Array d$(x). After this you have the Linenumber and the Lineentry into one Array (d$). With wend the loop gets back to the beginning. Now you can spend the created Array and include it into an draw text or other outputs. With "Entry 1: "+d$(1) you draw behind the text "Entry 1: " the word or complete text of the first line of the Array d$. back to Table of Content Back to Index |
||
|
Translate with LocalKit (Zeta) If you want to give other people the option translate your application, using the LocalKit of ZETA, insert following command into your source (place this command in the opper part of your source): |
||
|
Localize |
||
|
With the command Localize , yab translate many words, using the ZETA LocalKit automaticly (Example: Beenden to Quit or Hilfe to Help). To translate all words and all textparts in your application you need to create dictionary files. This are textdocuments with the original and translated words (text) into it. Example: |
||
|
"Datei" "File"
|
||
|
Importand is that you have the right words and text into your dictionary file. Then you change anything of a Text or use an other word for something, the LocalKit dont translate them. To use the dictionary files you need to create a folder into your programfolder. Don't place them on another place because localize don't work. Name this folder Language and create then another folder into this folder named Dictionaries. Place all dictionary file into this folder. |
||
|
|
||
|
Example for your application dictionaryfile: MyApp.enUK back to Table of Content Back to Index |
||
|
Using Shell Tools You can easy use shell tools with yab. Many people using the shell tools to run there program options. Examples: -copy a file -rename a file -create a folder -play a sound -open a other application And much more... Example to run a shell tool: Output$=System$(" open /boot/home") With the yab variables Output$ and System$() you run something out of yab. Here in the example we run the shell tool open and give them the option /boot/home. With this example we open the folder home. Between the () signs you type in the original shell tool command with there options. You can run not only shell tools with these variables you can run all applications you call. Example: Using NetPositive to run a HTML documentation |
||
|
Output$=System$(" /boot/beos/apps/NetPositive docs.html") |
||
|
back to Table of Content Back to Index |
|
Stichwortverzeichnis
|
|
Made available by BeSly, the BeOS, Haiku and Zeta knowledge base. |