Computer languages from A-Z: Vala & Visual Basic

by Gary L. Ratliff Sr. (eronstuc)

As we approach the tail end of the alphabet we notice that the number of languages which are available specifically for PCLinuxOS are rapidly decreasing, or even reaching the vanishing point. For that reason, this article will present two languages. One is a new language which is designed to only function on the Gnome desktop of Linux. The other is the language which made creating GUI applications in Windows an easy task: the venerable language Visual Basic. The version of this language selected has the redeeming feature of being available at no cost.

As an example, under a list of languages beginning with the letter X, I found the language Xi. It is a computer language that was available for the Univac computer. I have a picture taken many years ago of my now 28 year old son (Gary II — he never liked being called Junior) wearing diapers and typing away at the keyboard of the Commodore PET, which I purchased in 1978. Meanwhile I am in this same picture, typing on the Super-PET which was purchased in 1981, just a few months before he was born. I doubt that Gary II, who has been dealing with computers ever since the first months of his life, would be able to tell you just what a Univac might be.

I vaguely recall that the Univac was a very early computer, and it may have been the one used in the show the $64,000 Question, which created a scandal as the producers of the show were giving the answers to one player in favor over the other. It was this very show which brought Dr. Joyce Brothers into much fame as being one of the high money winners on that show.

Now those who actually remember the Univac would have spent some time punching in their program into Hollerith cards using an IBM keypunch, and then taking this deck of cards and merging it with a deck of cards containing the Job Control language for the system, and then having the system compiled and executed. One of my FORTRAN IV programs contained what I later learned to be a missing comma, and my program was stopped after too much CPU time was spent on the main frame. My flawed output from the program was pages and pages of neatly formatted zeros, instead of the amortization schedule which I expected.

However, most of the current generation would be like my son and have no idea of just what Univac might be.

The Vala Computer language

The Vala computer language is a new programming language, developed by Jorg Billeter and Raffaele Sandrini. The object is to create a language which will bring modern language features to the C language. This system will compile its code into the C language, which will then be compiled using a standard C compiler. This language is specifically for the Gnome desktop. If you enter the word vala into Synaptic, you will find it listed. However, as I am using the very newest KDE version on my main computer, this will not produce any useful output, as it will not have the Valac compiler, nor will KDE have the required Glib and Gobject libriaries, which are a part of the standard Gnome desktop.

For the purpose of testing the language, I used my partition which is devoted to version 10.04 of Ubuntu. I asked for the full system and the documentation for Vala. You can find the documentation for Vala, as well as a great tutorial for the language, on the main web site: http://live.gnome.org/Vala.

pic

By clicking the link on the above page, you will be directed to the tutorial, which will cover the features of the language, along with details of its use.

pic
/* hello.c generated by valac, the Vala compiler
  * generated from hello.vala, do not modify */
 
 
 #include 
 #include 
 #include 
 #include 
 #include 
 
 
 #define DEMO_TYPE_HELLO_WORLD (demo_hello_world_get_type ())
 #define DEMO_HELLO_WORLD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DEMO_TYPE_HELLO_WORLD, DemoHelloWorld))
 #define DEMO_HELLO_WORLD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DEMO_TYPE_HELLO_WORLD, DemoHelloWorldClass))
 #define DEMO_IS_HELLO_WORLD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DEMO_TYPE_HELLO_WORLD))
 #define DEMO_IS_HELLO_WORLD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DEMO_TYPE_HELLO_WORLD))
 #define DEMO_HELLO_WORLD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DEMO_TYPE_HELLO_WORLD, DemoHelloWorldClass))
 
 typedef struct _DemoHelloWorld DemoHelloWorld;
 typedef struct _DemoHelloWorldClass DemoHelloWorldClass;
 typedef struct _DemoHelloWorldPrivate DemoHelloWorldPrivate;
 
 struct _DemoHelloWorld {
     GObject parent_instance;
     DemoHelloWorldPrivate * priv;
 };
 
 struct _DemoHelloWorldClass {
     GObjectClass parent_class;
 };
 
 
 static gpointer demo_hello_world_parent_class = NULL;
 
 GType demo_hello_world_get_type (void);
 enum  {
     DEMO_HELLO_WORLD_DUMMY_PROPERTY
 };
 gint demo_hello_world_main (char** args, int args_length1);
 DemoHelloWorld* demo_hello_world_new (void);
 DemoHelloWorld* demo_hello_world_construct (GType object_type);
 
 
 
 gint demo_hello_world_main (char** args, int args_length1) {
     gint result = 0;
     fprintf (stdout, "Hello, World\n");
     result = 0;
     return result;
 }
 
 
 int main (int argc, char ** argv) {
     g_type_init ();
     return demo_hello_world_main (argv, argc);
 }
 
 
 DemoHelloWorld* demo_hello_world_construct (GType object_type) {
     DemoHelloWorld * self;
     self = (DemoHelloWorld*) g_object_new (object_type, NULL);
     return self;
 }
 
 
 DemoHelloWorld* demo_hello_world_new (void) {
     return demo_hello_world_construct (DEMO_TYPE_HELLO_WORLD);
 }
 
 
 static void demo_hello_world_class_init (DemoHelloWorldClass * klass) {
     demo_hello_world_parent_class = g_type_class_peek_parent (klass);
 }
 
 
 static void demo_hello_world_instance_init (DemoHelloWorld * self) {
 }
 
 
 GType demo_hello_world_get_type (void) {
     static volatile gsize demo_hello_world_type_id__volatile = 0;
     if (g_once_init_enter (&demo_hello_world_type_id__volatile)) {
         static const GTypeInfo g_define_type_info = { sizeof (DemoHelloWorldClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) demo_hello_world_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DemoHelloWorld), 0, (GInstanceInitFunc) demo_hello_world_instance_init, NULL };
         GType demo_hello_world_type_id;
         demo_hello_world_type_id = g_type_register_static (G_TYPE_OBJECT, "DemoHelloWorld", &g_define_type_info, 0);
         g_once_init_leave (&demo_hello_world_type_id__volatile, demo_hello_world_type_id);
     }
     return demo_hello_world_type_id__volatile;
 }

This file shows that the output from the familiar hello world program written as hello.vala, for which the code is shown in the tutorial as the first programming example, is indeed translated into a C program. If you key in the code of the hello.vala program and compile it with the vala compiler using valac hello.vala, you will create an object program which may be executed by issuing the command ./hello.

The Vala language makes using the newer object orientated features of other languages easily achieved in C. As it is much easier to learn than would be the C required to achieve this, it has come into wide use. Also, the Valac compiler may be used to compile another new language, Genie, and several examples of this use are presented in the September 2010 issue of Linux Pro Magazine, in the article “In the Bottle” by Ankur Kumar. The main site also covers the features of the Genie language.

pic

Visual Basic

You will learn that the items available in Visual Basic are very much like those available in Gambas. In fact, the Gambas system even has a feature which will allow translating the Visual Basic code into the Gambas Basic dialect. So, in this way, Visual Basic has appeal to Linux users. Microsoft has made a limited edition of the program available for free. Quite naturally, this system runs under Windows. If you type the phrase “free Visual Basic” into the Google search engine, you will soon find an item which will direct you to the Microsoft download area.

There is more than one version available for free use. One will allow creating Active X components, but will prevent creating the output as a Windows *.exe file that can be used. The version we are interested in the the Limited Edition of Visual Basic 2008.

The program will operate for 30 days without being registered. However, if you wish to create applications which you may use on your Windows system, it is best to register the product. Here you obtain a passport, and you do that by submitting your current email address or entering your address at either hotmail or msn.com. If you have previously established an account with these and have forgotten the password, a message will be sent to your main email address, which will have a message sent to you, allowing you to reset your password, and thus enabling you to register the product.

This is what the opening screen will look like, once you have the product installed:

pic

As this is created using the Windows method of creating a screen shot, you can begin to appreciate the advantage of being able to take screen shots in the PNG format. Here, while loading this into the document, which is located on my Ubuntu 10.04 partition, I noticed that the BMP version of the screen shot takes 3.8 megs. That means that the two examples shown in this document alone take 7 megs. Many mail systems would not allow sending such a large document. So, a screen shot program which produced PNG output for Windows would be a useful item.

The system has a set of tutorials, and these are presented as video files, which will play on the Windows Media player. They may also be saved to the video area of “My Documents.”

The initial tutorial shows how to create a web browser within a frame. It uses a text box and a label box to allow entering the URL of the site you wish to view. The system has many such tutorials, enabling you to quickly learn the language, and to become proficient using Visual Basic. Essentially, one selects the items needed, and drags them into place on the form. See the default form for a Windows Application:

pic

The tutorials continue to demonstrate how to code the actions required when you interact with the form. Now that we are in Windows, the live.gnome.org site also mentions that there is a binary version of Vala for Windows. This loads a minimal G object system into Windows so that the programs will compile using the required Glib and G object features. I know that there is a Gnome version of PCLinuxOS. However, I did not test it on PCLinuxOS Gnome, since when I upgraded to the latest KDE version of PCLinuxOS, I overwrote my partition that was formerly occupied by PCLinuxOS Gnome 2009.2.