Yab(asic) for newbies

Hey there! :slight_smile:

Being interested in PHP&MySQL development and having just discovered Yab, I thought about making a simple Haiku program to manage and monitor the HTTP and MySQL servers.

Now PHP is not yet supported, so obviously there’s no rush for me to have this little program completed, but Yab still looks great for such small tasks and I went into its documentation to learn a few things and play with it. However, my first brief contact with BASIC was about 25 years ago, then I learned a little more in high-school, just 2 years later, on a ZX Spectrum clone. Back then, we used GOTO line_number. :smiley:

Anyway, back to Yab. I ran into two problems.

1. No system tray reference in the documentation
Although I searched quite extensively, even in the online C API, I couldn’t find this kind of info. Can Yab handle this? I would need a status icon in the tray, that would also help to quickly manage the servers from a menu.

2. yab-IDE’s documentation could be more intuitive
Considering my BASIC days are way back in the past, with another dialect, every little bit of help to get back on track with it would be great to save time learning, which is useful even for people completely new to programming (I know the reader is assumed to have some experience with programming). I’ll go through a few examples.

Name
dim - create an array prior to its use
Synopsis
dim array(x,y)
dim array$(x,y)

The name section could at least mention this: “create a simple or 2-dimensional array prior to its first use”. And here’s the thing: there’s no other mention if dim can be used to create arrays of 3 or more dimensions, which should be clarified.

The synopsis section could look like this:

1-dimensional arrays
dim numericArrayName(size)
dim stringArrayName$(size)

2-dimensional arrays
dim numericArrayName(xSize, ySize)
dim stringArrayName$(xSize, ySize)

Here’s why:

  • “array” is a keyword in multiple languages, so this synopsis can mislead programmers into thinking it should be used as such. It’s only the examples section that reveals the fact that “array” is not a keyword in Yab.
  • The “$” usage should be properly clarified somewhere in the beginning of the documentation, so people know why and where it’s supposed to be used. But considering people can simply jump to some keyword and miss that explanation, tweaking the variable names can help the readers make the difference between the numeric and string arrays.
  • In other programming languages the array dimensions are not defined, or not as in Yab. So array(x,y) could easily be mistaken for a 1-dimensional array with two values: x and y.

Name
token() - split a string into multiple strings
Synopsis
dim w$(10)
…
num=token(a$,w$())
num=token(a$,w$(),s$)

Unless you read the description very carefully, and also look at the example, you have no idea what $a stands for. Here’s a better synopsis:

dim tokens$(10)
…
num=token(input$,tokens$())
num=token(input$,tokensArray$(),delimiters$)

And considering the tokens$ array automatically expands if needed, it would be a good idea to suggest the “cheapest” array definition (RAM-wise): dim tokens$(1)

Naming variables is obviously a thing that could be improved in most places in the documentation. I could sit down and suggest replacements for everything, but it would take me more time not to screw up and suggest something wrong, considering I’m still unfamiliar with the language. Still, if help is welcome, I will pitch in here and there - based on what I bump into while learning some yab. :smiley:

Adding some info about arrays in chapter 4 would be great. The most popular languages are quite advanced at working with arrays, so not having any reference about them makes people wonder about their support in yab - like appending, prepending, searching, etc. I don’t know if I’m barking at the right tree here, considering I have no idea if the yabasic developers hang around here, but I’ll do more research as I move on, if and when. In the meantime I thought it would do good if I posted this here. :slight_smile:

I have to say that Michel’s note about arrays was splendid, but it still doesn’t reveal yabasic’s level of support for arrays, and that would be welcome.

3 Likes

Take a look on our knowledge base besly:

Http://www.besly.de

And some more on the old side:

Http://www.old.besly.de

Tutorial and many helping stuff.

I think you should just start up learning yab and stop leave so much time into the sense of yab functions. If you are a beginner in development and have interest in learning yab you does not compare anything with other languages :).

Take it simple is most better for beginners. Also things like array or variable names.

Thanks, I looked on besly.de as well and I still couldn’t find what I wanted the most: a way to make a yab program with a tray icon.

As for the documentation suggestions, I’m a Zend Certified PHP Engineer and I am probably spoiled by the way PHP is documented online (sample). But while I think the existing yabasic documentation is decent, I’m sure we can agree some improvements would better serve its purpose. I even offered a bit of help.

That example of the PHP documentation is pretty nice. I like how they show multiple examples.

What do you mean with tray icon, can you explain it a little bit better

Hello Kneekoo,

you are welcome and you can help with the documentation with YAB.

I think the problem is that Yab has yabasic as the basis and so only the documentation has been taken over and additionally only new commands have been added. Lelldorin and I have tried to make a joint documentation.
In German I have already written a book about it and there is also an English book, if I remember correctly. Maybe you should implement the books in the YAB package.

Your problem with the status icon in the system tray. Maybe you can make a simple sketch. I’m not sure if I understand it correctly, maybe there is a solution to this

I think he means a Deskbar replicant

The system tray icons are the little icons next to the clock, which can show you some status information and offer an action menu.

In the case of the program I’d like to do, the icon could have 3 statuses: red, yellow and green, and the menu would allow the user to start each server: HTTP and MySQL (and possibly others, why not).

This is not possible with yab, sorry.

I’m not convinced that yab cannot do this. Let me play with it for a few minutes to see.

4 Likes

Since I cannot attatch a zip file here, I posted the example Deskbar tray indicator at http://yab.orgfree.com/forum/showthread.php?tid=104

4 Likes

Thanks for giving this a shot! There seemed to be an issue with the code. I got this error -> line x: syntax error at "0xff", where “x” was every line that has indentation.

I didn’t download the zip file because I don’t have an account on that forum, and it turned out that copying (select->copy) from the forum includes some weird white-space characters that yab can’t handle. I initially thought Yab-IDE has a problem with the copy/paste, but then I tried StyleEdit, Pe and even mcedit (Midnight Commaner’s text editor) in the terminal - all with the same result. Either the forum has some strange text formatting, or WebPositive does something to the text.

Curiously, though, the problem only occurred with white-space on the outside of the text on each line of code - both leading and trailing space. Yab didn’t complain about the white-space inside the lines of code, go figure.

So after I cleaned up the white-space I ran the program and without the downloaded files of course I ended up with some “No such file or directory” errors. I can test them later, if you manage to upload the files elsewhere.

In the meantime I checked the copy/paste and the reformatted files with MCs hex viewer, and this is how the white-spaces are displayed in HEX in:

  • the copy/paste file: C2 A0 (succession of these)
  • the reformatted file: 20 (one or more) - ASCII 32 (space)
  • the reformatted file: 09 (one or more) - ASCII 9 (TAB)

this is a copy paste error. The zip file has the source code and should run from there.the zip is available here: coquilletkd.com/jim/on-off.zip

1 Like

Sweet! :smiley: It works, thank you! Now I’ll have to understand what does what, then work on the program’s logic.

  1. How do I hide the window while allowing the tray icon to stay there so I can show the window again?
  2. How can I check if the window is already displayed, so I don’t display another instance of it? (as it currently does)

// Later edit

  1. After going through the whole program and understanding what it does, it’s obvious I don’t have to hide anything, but simply quit the program. The desklink (tray icon) is a standalone process, so it won’t be affected by quitting my program - unless I want to remove the desklink as well.

Although it’s a nice trick, I hoped there was a way to work with the system tray from the same program/process, so I can toggle the program’s window, and handle the tray icon in a similar way to the ProcessController deskbar item, which updates itself instead of using copyattr to change the executable’s icon. But I can work this, no problem. :smiley:

  1. There are several ways to make sure my program is active. I’ll investigate my options and come up with a solution.

Thanks again for your program! It helped a lot. :+1:

1 Like

This is expected, HTML is often formated with non-breakable spaces, because multiple “normal” spaces will just be merged together when parsing HTML. Web+ just copies the text as it is rendered.

It might be expected for WebPositive, but not from any other browser I used since 2000. I copied the same text from Chrome and Firefox under Linux and I got multiple space characters, as they should be. So Web+'s renderer is obviously wrong in converting the white-space into something else.

1 Like

Otter, Qupzilla and BeZilla all copy the text to the clipboard properly, Only WebPositive causes these issues.

2 Likes

Is this a discussion about yab or web browsers? :slight_smile:

2 Likes

While trying to crop up a small program, I run into a documentation issue. By documentation I mean the one included in the Help tab (left side of the IDE), not yabasic.html. I tried to get unstuck by exploring it a little more, without success. I know I could hunt for examples online, but you’ll understand why it was better to report the issues here.

I wanted to add some tabs in a window, so I used TABVIEW. The Help mentions this synopsis:
TABVIEW x1,y1 TO x2,y2, ID$, Option$, View$

Problem #1: the TABVIEW description doesn’t tell anything about View$, which forces you to guess what to do about this run-time error:
"viewType" is not of type VIEW

I assumed I would have to make a VIEW, as mentioned in the Help’s synopsis:
VIEW x1,y1 TO x2,y2, ID$, View$

Problem #2: The VIEW description only says “Adds a view” and leaves you guess whose ID$ is that, and what should go for View$ to stop getting the same error:
"viewType" is not of type VIEW

Knowing that the variables ending in “$” are strings, I named that parameter “viewType” - just so you know -, so the interpreter can at least see it as a string. But it clearly expects a special type of data, which I can’t find by using yab-IDE.

Of course, this raises the question: what other data and variable types are there in Yab? A page dedicated to these types would be great. But the least that is necessary is to make sure the commands’ arguments are explained well enough so we don’t get stuck like this.

The documentation is pretty big, and I’m sure it’s not easy to keep everything in order. Would it be OK to mention similar issues here? If not, where else?

TABVIEW x1,y1 TO x2,y2, ID$, Option$, View$

Opens a tabview from x1 ,y1 to x2,y2 namde ID$ with the Option$ selected on View$

screenWidth = peek(“desktopwidth”)
screenHeight = peek(“desktopheight”)
window open screenWidth/2-200, screenHeight/2-200 to screenWidth/2+200, screenHeight/2+200, “MainWindow”, “Test”
VIEW 0,0 TO 400,320, "BackgroundView","MainWindow"
TABVIEW 5,2 TO 395,300, "Test", "top", "BackgroundView"
TABVIEW ADD "Test",  "Tab1"
TABVIEW ADD "Test",  "Another tab"

This opens a Window, adds a view named “BackgroundView”, adds a tebview named “Test”, and adds two tabs, “Tab1” and “Another tab”.

To place items on “Tab1”, one would use “Test1” for the view name as it is tab 1 on the tabview named “Test.”

To place items on “Another tab”, one would use “Test2” for the view name as it is tab 2 on the tabview named “Test.”

2 Likes