One of April challenges is writing a converter, the kind that converts meter to yard. A lot of people are doing it the hard coding way. I am way to busy to do that. So, I decided to spend one hour on it, and no more! The result is here. Not perfect, but close enough.
There are several design issues:
1. The display for various conversion and the result is rolled into one.
2. You only select the original data, all the possible conversions is done automatically.
3. Range is limited to valid input
4. The data is provided via text. You can modify the text to suit.
5. More importantly, the text also include range of numbers, which the program uses for conversion. The ratio for conversion is calculated automatically. This includes negative numbers, or shifting numbers (i.e. 1-5 into 3-7)
6. I use a hidden Main scale to facilitate ease of conversion.
7. Pay attention to Field entries! They defined the data field locations!
These design decisions helped me contained the implementation of this program into one hour.
I did encounter one bug. When copying Choice Loop into NumLoop, I forgot to change the Goto statement, so it went back to Choice Loop. Easily fixed.
Turns out, the algorithm for conversion is robust enough to handle out of range condition, so that I don't have to restrict its input. I could have avoided that bug after all.
It also means, that I don't have to show the range of numbers. It means I can just display the descriptions, and the converted numbers. It would make a cleaner presentation.
'Small Basic Converter - ZLW480
'By Harry Hardjono
'Data="N DescriptionFrom To :"
Data="1 USD From 0 To 100000 : "
Data="2 GBP From 0 To 158308 : "
Data="3 CAD From 0 To 99962 : "
Data="4 EUR From 0 To 130240 : "
Data="5 AUD From 0 To 103447 : "
TextWindow.WriteLine("Small Basic Converter")
For i=1 To Array.GetItemCount(Data)
If (Choice<1 or Choice>Array.GetItemCount(Data)) then
TextWindow.WriteLine("Out of Range!")
TextWindow.WriteLine(Text.GetSubText(Data[Choice],Field,Field-Field)+" to "+Text.GetSubText(Data[Choice],Field,Field-Field))
TextWindow.Write("Enter the amount: ")
' If (Num
' TextWindow.WriteLine("Out of Range!")
' Goto NumLoop
Sub map 'map function