Currency Conversions 
Author Message
 Currency Conversions

Hello all,
With a conversion utility that I am making, I want to be able to convert
currencies, but as currencies always fluctuate, I can't just convert
like anything else in my app.  

I want the user to input the values of the foreign currencies, all
relative to the USD.  

I have a screenshot of the window which I have created, that allows the
user to input the currency rates, according to what ever currencies they
wish to convert.  

It is at:
  http://www.*-*-*.com/ ~markbee/currency.jpg

    (you'll need to see the screenshot to understand my rambling on!)

I want these values to be saved as a 'preferences' text file, which my
app reads upon opening, and rewrites upon quitting, ie: everytime this
window, (the screenshot one) open, the values are there, as the user
entered last time.  

I know that I have to use binaryStreams and PreferencesFolder.Child(
"Currency Prefs" ), etc.  
Everytime I look at examples of how to do this, I get confused as to
what the code actually has to be, (because of my limited knowledge of
BASIC at this time)!  

If anyone could provide me with what the code that I should put into the
'ReadCurrencies' and 'WriteCurrencies' methods in my app. that would be
greatly appreciated, but just some help would also be appreciated.  

Also, that means the code I have used in all my other conversions,
(Mass, time, length, acceleration, etc), would also be different.  But
because the EditFields in the screenshot (above), would always show the
correct conversion, (would they? - due to the prefs file being read,
even though the window isn't visible?), I think I could just refer to
the field like this:
 val(CurrencyWindow.EditField1.Text)  //whichever field EditField1 is...
(could I?).  

If you understand what I'm trying to say, any help would be greatly
appreciated!

Thanks in advance,
Mark Bee.  



Fri, 30 Apr 2004 17:53:19 GMT  
 Currency Conversions

Quote:
> -- snip long stuff --

Well.  I don't know about anyone else here, but here are two
approaches.  I'd suggest using the one that works best for you.  I
spend most of my time writing in PHP these days and if I'm not using a
database I store data as xml blocks.

Firstly, think about how you want to store the data, and what the data
will be used for in the future.  Its good practice to plan this stuff,
even for the simple things like what you're doing.  You could store it
in a text file, simply like:

currency1|amt1
currency2|amt2

Each line is a 'record', each | seperates the items, and \n (chr(10))
seperates each record.  You could alternately store your data as:

<record>
  <currency>IEP</currency>
  <amt>1.3</amt>
</record>

Again storing this in a text file.  While I prefer the second
approach, the first is easier to implement.  Here's a way to read in a
file which looks like the first approach (file currency.txt must exist
already and I haven't tested this so beware it may not work
perfectly):

  dim f as folderItem, in as textInputStream
  dim s, item, t(-1) as string, i, n as integer

  f = getFolderItem( "currency.txt" )
  if f.exists and f <> nil then
    in = f.openAsTextFile
    s = in.readAll
    in.close

    n = countFields( s, chr(10 )  )
    for i = 1 to n
      item = nthField( s, chr(10), i )
      if item <> "" then
        t.append item
      end if
    next
  end if

By the end of this all records (currency1|amt1) are stored in the t
array for you to do what you wish with.  Probably better if the t var
is global or even better if you use a custom class.  Read more on
custom classes if you don't already know them; classes solve 75% of
problems imho.

nthfield( t(0), "|", 1 ) would be currency1
nthfield( t(1), "|", 2 ) would be amt1

Writing to disk would be similar.  Here's the code for that. Again it
may not work perfectly, but here we go.

  dim f as folderItem, out as textOutputStream
  dim s, t(-1) as string, i as integer

  t.append "currency1|amt1"
  t.append "currency2|amt2"

  f = getFolderItem( "currency.txt" )
  out = f.CreateTextFile
  for i = 0 to ubound( t )
    out.write t(i) + chr(10)
  next
  out.close

Hope that helps ya.  I haven't written a response on this group in
months and I may have lost my touch (not that I was all that good in
the first place lol).  At least the code to create, open, read and
write files is present here, which should help.  Good luck :)

Cheers;
Seth



Sat, 01 May 2004 09:31:04 GMT  
 Currency Conversions
Sorry, I don't really understand nost of this yet, as I'm pretty new to
BASIC.  

I was thinking of something like this in my 'WritePrefs' method,
executed upon saving values into the EditFields:

I'm not even sure if what I've got here will do what I want it to:

 dim file as TextOutputStream
  dim f as FolderItem
  dim [whatever I need] as [what ever they have to be]
f=PreferencesFolder.Child("Currency Conversions.txt")
[*** I don't know what to put here ***]
[Write whatever into the text file, which I don't know how to do, from
the text into the EditFields]
[whatever has to go here, I don't know either]
file.close

etc...

And for the ReadPrefs method, which is executed when my app opens, I
don't know how to make the app read the file, and automatically put the
previously entered text back into each of the editFields, (see
screenshot:
 http://homepages.ihug.com.au/~markbee/currency.jpg )

For intensive purposes, lets say that the name of each of the editfields
is the same as the corresponding 3 letter code for the particular
currency.$%$%  

As I've said, I want to be able to save the values upon clicking the
Save button, and when the app opens, the app reads each of the values,
and correctly puts them in their correct EditFields.  
Basically, I have completely no idea on coding this, (I don't even know
if the code above is right), so I really, want th code$%$%, and any
explanations possible with the code, so I can code my app and learn how
the code works at my leisure.  

Thanks again, in advance for this, and your putting up with my limited
knowledge of the language.  
Mark Bee.  

Quote:
>------snip your stuff too!------



Sat, 01 May 2004 16:34:01 GMT  
 Currency Conversions
Pretty much everything I said will still work.  Just when you are
writing to disk you want to write the editfield values.  This example
will write an editfield's text into the text file you mentioned:

dim f as folderItem, out as textOutputStream
f = preferencesFolder.child( "Currency Conversions.txt")
out = f.createAsTextFile
out.write editField1.text
out.close

This example will read it back into the editfield.

dim f as folderItem, in as textInputStream
f = preferencesFolder.child("Currency Conversions.txt")
if f.exists and f <> nil then
  in = f.openAsTextFile
  editField1.text = in.readAll
  in.close
end if

That will more than get ya started.  I can't help any more than that
without writing the app for ya :)  Ya have to realize there are so
many different ways to do this (resource, text, binary etc), and so
many ways of storing the data records.  If you are more interested in
looking at good preference writing classes have a look at the
resources area of the RB website.

Best of luck;
Seth



Sun, 02 May 2004 06:30:05 GMT  
 Currency Conversions
Thanks...
I am sort of getting how it works now.  Basic for me, looks logical and
'clean' when I read it, but to write it is a different story.  Is the
language basically the same, (but with a few differences her and there),
with all BASIC written programs, etc?  
Quote:

> Pretty much everything I said will still work.  Just when you are
> writing to disk you want to write the editfield values.  This example
> will write an editfield's text into the text file you mentioned:

> dim f as folderItem, out as textOutputStream
> f = preferencesFolder.child( "Currency Conversions.txt")
> out = f.createAsTextFile
> out.write editField1.text
> out.close

> This example will read it back into the editfield.

> dim f as folderItem, in as textInputStream
> f = preferencesFolder.child("Currency Conversions.txt")
> if f.exists and f <> nil then
>   in = f.openAsTextFile
>   editField1.text = in.readAll
>   in.close
> end if

> That will more than get ya started.  I can't help any more than that
> without writing the app for ya :)  Ya have to realize there are so
> many different ways to do this (resource, text, binary etc), and so
> many ways of storing the data records.  If you are more interested in
> looking at good preference writing classes have a look at the
> resources area of the RB website.

> Best of luck;
> Seth



Sun, 02 May 2004 10:30:11 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. COM and currency conversion

2. Currency converter on OA Website

3. Foreign currency

4. Foreign currency

5. How to display currency?

6. Swiss numeric and Currency pictures ?!?!

7. Currency Problems - Browsing 1 file in 2 boxes

8. Currency Symbols - International

9. Representing currency

10. Multi-Currency Question

11. Disappearing currency values

12. Symbol for Euro currency in CW?

 

 
Powered by phpBB® Forum Software