How do I write a starter program?

How Ubercode works. My first Program. Starter programs.

How do I write a starter program?

Postby uberdroid on Wed Jan 14, 2009 10:05 pm

The simplest possible starting program is the Hello World program. This asks you to type in your name, then prints out a short greeting:
Code: Select all
// Myfirst.cls
  Ubercode 1 class Myfirst 

  public function main()
  var
    MyName:string[*]
  code
    MyName <- Inputbox("Myfirst", "What is your name?")
    call Msgbox("Myfirst", "Hello "+MyName+"!")
  end function

  end class

The following steps show how to run the program. They assume you've installed Ubercode - if not download the free Trial Package then continue.

(i) Start the Developer Environment
Start the Developer Environment from Windows, using Start - Programs - Ubercode - Developer Environment or by double clicking the Ubercode icon on the desktop.

When it starts, you will be shown the Startup Wizard screen. In the Startup Wizard, click the Close button because we don't need the wizard at this time. After the wizard has gone, your desktop should look like this:
Image
The top part of the screen is occupied by the main menu.
(ii) Write the Program
In the Developer Environment, use the File - New - Program menu command to write the code. A dialog titled "New Program" will appear. Click in the entry field next to "Name" and type in "Myfirst" (without the quotes). Then click in the entry field next to "Program Type", delete the existing text and and type in "2" (again without the quotes). Click OK to create the new program which looks like this:
Image
The name you typed in (Myfirst) was used as the class name and the file name. It's not essential the name was "Myfirst", you could have typed any other alphabetic name. The choice of "2" (Program type = Main function) means the new program uses a function (block of code) instead of a window. Now change the program to use an Inputbox to prompt for the name and a Msgbox to display the result. Change the following code:
Code: Select all
   public function main()
   code
     // Put code here
   end function

into this:
Code: Select all
   public function main()
   var
     MyName:string[*]
   code
     MyName <- Inputbox("Myfirst", "What is your name?")
     call Msgbox("Myfirst", "Hello "+MyName+"!")
   end function

The changes are to declare a string variable MyName, and to add the calls to Inputbox and Msgbox. When changing the code, make sure the commas and double-quotes match those above.
(iii) Run the program
Now it's time to compile the program and run it. Click the Run button and wait a few moments:
Image
The program is saved automatically when the compiler starts. After it compiles, the program starts running as a Windows EXE file. You should then see the Inputbox appear:
Image
Type some text in the Inputbox and click OK. You should then see the Msgbox:
Image
The text that came from the Inputbox forms part of the greeting in the Msgbox. If you look at the call to Msgbox in the code, you'll see there are two string parameters. The first string "Myfirst" is put in the message box caption (the blue area) and the second string (the greeting message) is in the main part of the message box. This order is easy to remember because it flows down the page.

Finally, click OK to close the program.
uberdroid
PostRobot
 
Posts: 38
Joined: Wed Jan 14, 2009 4:36 am

Return to Getting Started with Programming

Who is online

Users browsing this forum: Yahoo [Bot] and 0 guests

cron