USD to EUR converter in REALbasic line

It would be nice if we could make a USD to EUR converter in REALbasic? Studding Mid and InStr Functions in REALbasic and Creating a Class in REALbasic you can do it! Let me show you how. Watch it, learn it, enjoy it!

Building the GUI for USD to EUR converter

Use two TextFields Controls and one PushButton. Try to get result something like on this image. Please note that you can make this application on Windows or Linux too. I prefer Mac OS, you can use what you like – REALbasic is cross-platform.

realbasic usd to eur

Creating and setting up HTTPSocket Class

Go to Project TAB and create Class called cHTTP. Then add to Super value HTTPSocket. In code editor for cHTTP Class create a new Property and in Declaration type code and in As type String. Great! Now Add Method and enter for Method Name: convertHTML for Parameters: KeyQuery As String, KeyQuery2 As String, data As String and for Result: String. Insert then the code below:

1
2
3
4
Dim KeyStart As String = KeyQuery 
Dim KeyEnd As String = KeyQuery2
 
Return Mid( Data, InStr( Data, KeyStart ) + Len(KeyStart), InStr( Data, KeyEnd ) - (InStr( Data, KeyStart) + Len(KeyStart) ) )

Create new Method called downloadHTML and use this code. When we type in Google search ex. 20 USD to EUR we will get the result between h2 class=”r” style=”font-size:138%” and /h2. If we know this than we are done with work.

1
2
3
4
5
6
7
8
9
Dim Data As String
 
Data = Me.Get ("http://www.google.com/search?hl=en&q=" + (Window1.TextField2.text) + "+USD+in+EUR&aq=f&oq=&aqi=g1", 3 )
 
code = convertHTML( "h2 class=r style=" + chr(34) + "font-size:138%" + chr(34) + "&gt;<b>" , "</b></h2>", Data )
 
Window1.TextField1.Text = code
 
Me.Close

Finishing work in 2 lines

PushButton1 Sub Action ()

1
2
3
Dim tuts As new cHTML
 
tuts.downloadHTML

Author: Jakub Pawlak

I'm interested in all. Currently working on the development of TUTSPOLIS and I hope that in near feature the project will be successful.

4 Responses to “USD to EUR converter in REALbasic”

  1. Frank Thomas says:

    Thanks for the example, but I believe that I’ve done something wrong. My code get hung up on the Data = Me.Get …

    Any ideas?

    Frank

  2. Frank Thomas says:

    Thanks for that, but what I mean is that realbasic is throwing an error on the command ‘me.get’ part.

Leave a Reply

Copyrights (c) TUTSPOLIS | Powered by Wordpress MU | Inspired at Elegant Themes designed by qbap (HTML5 & CSS3)