Rb programs 2

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

Improved A.T.M program with pushbuttons

This time we're going to make the atm program more realistic by adding some pushbuttons to it. Add an editfield and call it text1, two pushbuttons and call them buttonenter and buttonclose. Add a groupbox and add eleven bushbuttons, name then b1,b2,b3,b4,b5,b6,b7,b8,b9,b0, buttonclear.Arrange them and add their caption names as in the picture. Next add window2 and then add a pushbutton and call it buttonok, next add a statictextbox and type in an amount example...$10.00 this box will display with your bank balance when you enter the correct pin.How you design this is totaly up to you!

Now double click on the enter data button on window1 and add this code..........................

  dim intdata as integer
 
  intdata = val(text1.text)
 
 
  select case intdata
  case 12345
    msgbox(uppercase("you entered 12345, and that is the correct pin!"))
    text1.text = ""
    text1.setfocus
    window2.show
  case 1234
    msgbox(uppercase("you are one digit short of your number"))
  case else
    msgbox(uppercase("you entered an incorrect number, this machine will be disabled"))
    text1.text = ""
    text1.enabled = false
    buttonenter.caption = "DISABLED"
    buttonenter.enabled = false
    b1.enabled = false
    b2.enabled = false
    b3.enabled = false
    b4.enabled = false
    b5.enabled = false
    b6.enabled = false
    b7.enabled = false
    b8.enabled = false
    b9.enabled = false
    b0.enabled = false
    buttonclear.enabled = false
    buttonclose.setfocus
  end select
 
 
   Next double click on the close button and add this code.............................

   Window1.close

Next double click on the clear button and type this line of code......................

    Text1.text = ""

    text1.setfocus

Now you need to code the number buttons, the code is as follows..................

    text1.text = text1.text + me.caption

    text1.text = text1.text + me.caption

Add the above code from b1 to b0 now test your application out. Note that if you enter the wrong pin the keypad is disabled, and the only option your left with is to close the program! You'll also be able to see that the close button is highlited, this is done by the line "buttonclose.setfocus" 

 

Your month of birth using the select case statement

In this program we're going to enter a number and receive a string output in our text box.

First off add an editfield and name it text1, then three pushbuttons and name them... buttonenter, buttonclear, buttonexit label their caption properties as in the screenshot.Next add a groupbox and label it's caption property as months, then drop a statictext box inside it, resize it and name it statictextoutput, finally in the statictext box property window check the bold box. Now add the following code to the enter button........

  dim intmonth as integer
  dim stroutput as string
 
  intmonth = val(text1.text)
 
  select case intmonth
  case 1
    statictextoutput.text = "You were born in jan"
  case 2
    statictextoutput.text = "You were born in feb"
  case 3
    statictextoutput.text = "You were born in Mar"
  case 4
    statictextoutput.text = "You were born in Apr"
  case 5
    statictextoutput.text = "You were born in May"
  case 6
    statictextoutput.text = "You were born in June"
  case 7
    statictextoutput.text = "You were born in Jul"
  case 8
    statictextoutput.text = "You were born in Aug"
  case 9
    statictextoutput.text = "You were born in Sep"
  case 10
    statictextoutput.text = "You were born in Oct"
  case 11
    statictextoutput.text = "You were born in Nov"
  case 12
    statictextoutput.text = "You were born in Dec"
  case else
    msgbox"NUMBER OUT OF RANGE!"
  end select
 
  Next add this code to the clear button.................................

  text1.text = ""
  statictextoutput.text = ""
  text1.setfocus

And finally this code into the exit button.................................

  window1.close

All that's left now is to try your app out!

Mark.