Hello Everyone
Today we are going to look at how you can change text formatting on the fly using xBasic code. To do this we will examine the Tape Calculator we created for our new desktop.
You can see from the image, the calculator has all the standard buttons for a calculator as well as a unit of measure converter and a scrollable tape window. The calculator works with the keyboard number pad allowing ten key entry for those so inclined and it allows the user to edit their tapes at any position in the tape then it automatically recalculates the total. Finally it has a print option because what good is a tape calculator without the tape.
Now some of you are saying what has this got to do with changing text formatting and properties on the fly with xBasic. Well imagine you are building a currency converter or you wanted your calculator to flip over to scientific. You would then need to change the output to match the currency or expected scientific notation. The principle we discuss here today will allow you to do just that, so lets get started.
To make the calculator work and to allow for the formatting and properties to change on the fly we first need to set up a series of variables.
- vLineItm is a character variable which captures the number keys as the user enters them on the keypad or presses the button with the mouse.
- vLastAns is a numeric variable which is a running total for the tape.
- vLastEntry Numeric and stores the last line item entered
- vOpr the operand used (plus, minus etc.)
- vfmtType formats the answer as whole numbers or currency
- vDec holds the number of decimal places for the number.
Now lets look at the code for entering a value. Below is the code on the Plus button
if vLineItem = "" then vOpr = "+" goto entend end if t = table.current() t.enter_begin() t.Date = Date() t.SAVECNT = vSaveCnt t.TAPETYPE = vTapeType t.TITLE = vTitle t.Coperand = "+" t.NVALUE = Val(vlineitem) t.NANSWER = vLastAns+val(vlineitem) vLastEntry = t.Nvalue vLastAns = t.NAnswer t.cVALUE = str(t.NValue,16,vDec,vFmtType) t.cANSWER = str(vLastAns,16,vDec,vFmtType) t.enter_end(.t.) cdcTapeCalc:nanswer.entry.dec = vDec vLineItem = "" cdcTapeCalc:vlineitem.value = " " cdcTapeCalc:nanswer.entry.format = vFmtType cdcTapeCalc:nanswer.refresh() cdcTapeCalc:vlineitem.Refresh() entend: cdcTapeCalc.Fetch_Last() cdcTapeCalc:browse1.refresh() end
This code is the same on each of the operand buttons with the exception of the operand used.
First we check vLineItm to see if it is blank. If it is we move to the last record in the table and end the routine. This insures we do not have a blank line in our tape. Next we use the table method to enter new records in our current table.
- t = table.current()
- t.enter begin……
Using this method allows you to create records in the table and assign their values using xbasic code, calculated formulas, variables or even values stored in other tables. Notice that cValue and cAnswer use variables vDec and vFmtType which convert the str() function and value properties.
vDec is the radio choice on the calculator which allows the user to select decimal places from 0 to 6 and vFmtType is set by choosing a button labeled 0.00 or $0.00
Now lets look at the Edit button
dim prmpt_title as c
dim prmpt_prompt as c
dim prmpt_default as c
prmpt_title = "TapeEdit"
prmpt_prompt = "Enter the correct value"
prmpt_default = "0"
DIM SHARED xte AS C
xte = ui_get_number(prmpt_title,prmpt_prompt,prmpt_default)
rNbr = recno("calc_detail")
t = table.current()
t.fetch_first()
t.fetch_goto(rNbr)
t.change_begin()
t.nValue = Var->xte
t.change_end(.t.)
cdcTapeCalc:btntapeedit.push()
We start by building a simple dialog box which prompts for a number. I created this box using the code genie and set the default value to zero. If you want to be more creative you can fetch the record selected value and make it the default. Next we fetch the record number
rNbr = recno(“calc_detail”)
then use fetch_goto(rNbr) to locate the record to be edited in the table. Assign the value then push the Recalculate button on the form.
Now lets look at the recalculate button.
parentform.commit() vLastAns = 0 t = table.current() t.fetch_first() while .not. t.eof() t.change_begin() if t.COPERAND = "+" then vLastAns = vLastAns + t.NVALUE t.NANSWER = vLastAns else if t.COPERAND = "-" then vLastAns = vLastAns - t.NVALUE t.NANSWER = vLastAns else if t.COPERAND = "%" then vLastAns = vLastAns * t.NVALUE / 100 t = vLastAns else if t.COPERAND = "*" then vLastAns = vLastAns * t.NVALUE t.NANSWER = vLastAns else if t.COPERAND = "/" then vLastAns = vLastAns / t.NVALUE t.NANSWER = vLastAns else if t.COPERAND = "=" then vLastAns = vLastAns t.NVALUE = vLastAns t.NANSWER = vLastAns end if t.cVALUE = str(t.NValue,16,vDec,vFmtType) t.cANSWER = str(vLastAns,16,vDec,vFmtType) t.change_end(.t.) t.fetch_next() end while t.fetch_last() t.change_begin() if t.COPERAND = "+" then vLastAns = vLastAns + t.NVALUE t.NANSWER = vLastAns else if t.COPERAND = "-" then vLastAns = vLastAns - t.NVALUE t.NANSWER = vLastAns else if t.COPERAND = "%" then vLastAns = vLastAns * t.NVALUE / 100 t = vLastAns else if t.COPERAND = "*" then vLastAns = vLastAns * t.NVALUE t.NANSWER = vLastAns else if t.COPERAND = "/" then vLastAns = vLastAns / t.NVALUE t.NANSWER = vLastAns else if t.COPERAND = "=" then vLastAns = vLastAns t.NVALUE = vLastAns t.NANSWER = vLastAns end if t.cVALUE = str(t.NValue,16,vDec,vFmtType) t.cANSWER = str(vLastAns,16,vDec,vFmtType) t.change_end(.t.) cdcTapeCalc:browse1.refresh() cdcTapeCalc:browse1.Fetch_First()
Here we again use the table method to modify our values, but instead of t.enter we use t.change. In both cases, it is important to remember to end the enter or change with t.enter_end(.t.) or t.change_end(.t.) depending on which is being used.
Finally we will look at the conversion button which is a little more complicated but still simple.
dim SHARED conver as N dim SHARED cvlabel as C dim SHARED mymenu as C style = <<%str% menu.v_item_min_leftx=.25 color.menu_v_background=Dirty White color.menu_v_left=Dark Red color.menu_v_right=White font.menu=Tahoma,8,0 %str% vMenuItems = <<%a% Length|Inches|01 To Centimeters Length|Inches|02 To Feet Length|Inches|03 To Yards Length|Inches|04 To Miles Length|Centimeters|05 To Inches Length|Centimeters|06 To Meters Length|Centimeters|07 To Kilometers Length|Feet|08 To Meters Length|Feet|09 To Inches Length|Feet|10 To Yards Length|Feet|11 To Miles Length|Meters|12 To Feet Length|Meters|13 To Centimeters Length|Meters|14 To Kilometers Length|Yards|15 To Inches Length|Yards|16 To Feet Length|Yards|17 To Miles Length|Miles|18 To Kilometers Length|Miles|19 To Inches Length|Miles|20 To Feet Length|Miles|21 To Yards Length|Kilometers|22 To Miles Length|Kilometers|23 To Centimeters Length|Kilometers|24 To Meters Liquids|Teaspoon|25 To Ounce Liquids|Teaspoon|26 To Tablespoon Liquids|Tablespoon|27 To Ounce Liquids|Tablespoon|28 To Teaspoon Liquids|Ounce|29 To Teaspoon Liquids|Ounce|30 To Tablespoon Liquids|Ounce|31 To Cup Liquids|Ounce|32 To Pint Liquids|Ounce|33 To Fifth Liquids|Ounce|34 To Quart Liquids|Ounce|35 To Half Gallon Liquids|Ounce|36 To Gallon Liquids|Cup|37 To Ounce Liquids|Cup|38 To Pint Liquids|Cup|39 To Fifth Liquids|Cup|40 To Quart Liquids|Cup|41 To Half Gallon Liquids|Cup|42 To Gallon Liquids|Pint|43 To Ounce Liquids|Pint|44 To Cup Liquids|Pint|45 To Fifth Liquids|Pint|46 To Quart Liquids|Pint|47 To Half Gallon Liquids|Pint|48 To Gallon Liquids|Fifth|49 To Ounce Liquids|Fifth|50 To Cup Liquids|Fifth|51 To Pint Liquids|Fifth|52 To Quart Liquids|Fifth|53 To Half Gallon Liquids|Fifth|54 To Gallon Liquids|Quart|55 To Ounce Liquids|Quart|56 To Cup Liquids|Quart|57 To Pint Liquids|Quart|58 To Fifth Liquids|Quart|59 To Half Gallon Liquids|Quart|60 To Gallon Liquids|Half Gallon|61 To Ounce Liquids|Half Gallon|62 To Cup Liquids|Half Gallon|63 To Pint Liquids|Half Gallon|64 To Fifth Liquids|Half Gallon|65 To Quart Liquids|Half Gallon|66 To Gallon Liquids|Gallon|67 To Ounce Liquids|Gallon|68 To Cup Liquids|Gallon|69 To Pint Liquids|Gallon|70 To Fifth Liquids|Gallon|71 To Quart Liquids|Gallon|72 To Half Gallon Time|Hundreth's|73 To Minutes Time|Seconds|74 To Minutes Time|Seconds|75 To Moments Time|Seconds|76 To Hours Time|Seconds|77 To Days Time|Minutes|78 To Seconds Time|Minutes|79 To Hundreth's Time|Minutes|80 To Hours Time|Minutes|81 To Moments Time|Minutes|82 To Days Time|Minutes|83 To Weeks Time|Minutes|84 To Fortnight Time|Minutes|85 To Months Time|Minutes|86 To Years Time|Moments|87 To Seconds Time|Moments|88 To Hours Time|Moments|89 To Days Time|Moments|90 To Weeks Time|Moments|91 To Fortnight Time|Moments|92 To Months Time|Moments|93 To Years Time|Hours|94 To Seconds Time|Hours|95 To Minutes Time|Hours|96 To Moments Time|Hours|97 To Days Time|Hours|98 To Weeks Time|Hours|99 To Fortnight Time|Hours|100To Months Time|Hours|101To Years Time|Days|102To Seconds Time|Days|103To Minutes Time|Days|104To Moments Time|Days|105To Hours Time|Days|106To Weeks Time|Days|107To Fortnight Time|Days|108To Months Time|Days|109To Years Time|Weeks|110To Seconds Time|Weeks|111To Minutes Time|Weeks|112To Moments Time|Weeks|113To Hours Time|Weeks|114To Days Time|Weeks|115To Fortnight Time|Weeks|116To Months Time|Weeks|117To Years Time|Fortnight|118To Seconds Time|Fortnight|119To Minutes Time|Fortnight|120To Moments Time|Fortnight|121To Hours Time|Fortnight|122To Days Time|Fortnight|123To Weeks Time|Fortnight|124To Months Time|Fortnight|125To Years Time|Month|126To Seconds Time|Month|127To Minutes Time|Month|128To Moments Time|Month|129To Hours Time|Month|130To Days Time|Month|131To Weeks Time|Month|132To Fortnight Time|Month|133To Years Time|Year|134To Seconds Time|Year|135To Minutes Time|Year|136To Moments Time|Year|137To Hours Time|Year|138To Days Time|Year|139To Weeks Time|Year|140To Fortnight Time|Year|141To Months %a% mymenu = ui_popup_styled_menu(vMenuItems, style) if mymenu = "" then end end if if mymenu = "01 To Centimeters" Then conver = 2.54 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Inches to Centimeters" goto cvert else if mymenu = "02 To Feet" Then conver = 12 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Inches to Feet" goto cvert else if mymenu = "03 To Yards" Then conver = 36 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Inches to Yards" goto cvert else if mymenu = "04 To Miles" Then conver = 63360 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Inches to Miles" goto cvert else if mymenu = "05 To Inches" Then conver = 2.54 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Centimeters to Inches" goto cvert else if mymenu = "06 To Meters" Then conver = 100 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Centimeters to Meters" goto cvert else if mymenu = "07 To Kilometers" Then conver = 100000 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Centimeters to Kilometers" goto cvert else if mymenu = "08 To Meters" Then conver = 3.2808399 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Feet to Meters" goto cvert else if mymenu = "09 To Inches" Then conver = 12 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Feet to Inches" goto cvert else if mymenu = "10 To Yards" Then conver = 3 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Feet to Yards" goto cvert else if mymenu = "11 To Miles" Then conver = 5280 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Feet to Miles" goto cvert else if mymenu = "12 To Feet" Then conver = 3.2808399 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Meters to Feet" goto cvert else if mymenu = "13 To Centimeters" Then conver = 100 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Meters to Centimeters" goto cvert else if mymenu = "14 To Kilometers" Then conver = 1000 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Meters to Kilometers" goto cvert else if mymenu = "15 To Inches" Then conver = 36 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Yards to Inches" goto cvert else if mymenu = "16 To Feet" Then conver = 3 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Yards to Feet" goto cvert else if mymenu = "17 To Miles" Then conver = 1760 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Yards to Miles" goto cvert else if mymenu = "18 To Kilometers" Then conver = 1.609344 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Miles to Kilometers" goto cvert else if mymenu = "19 To Inches" Then conver = 63360 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Miles to Inches" goto cvert else if mymenu = "20 To Feet" Then conver = 5280 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Miles to Feet" goto cvert else if mymenu = "21 To Yards" Then conver = 1760 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Miles to Yards" goto cvert else if mymenu = "22 To Miles" Then conver = .62137 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Kilometers to Miles" goto cvert else if mymenu = "23 To Centimeters" Then conver = 100000 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Kilometers to Centimeters" goto cvert else if mymenu = "24 To Meters" Then conver = 1000 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Kilometers to Meters" goto cvert else if mymenu = "25 To Ounce" Then conver = 6 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Teaspoon to Ounce" goto cvert else if mymenu = "26 To Tablespoon" Then conver = 3 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Teaspoons to Tablespoons" goto cvert else if mymenu = "27 To Ounce" Then conver = .5 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Tablespoon to Ounce" goto cvert else if mymenu = "28 To Teaspoon" Then conver = 3 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Tablespoon to Teaspoon" goto cvert else if mymenu = "29 To Teaspoon" Then conver = 6 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Ounce to Teaspoon" goto cvert else if mymenu = "30 To Tablespoon" Then conver = 2 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Ounce to Tablespoon" goto cvert else if mymenu = "31 To Cup" Then conver = 8 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Ounce to Cup" goto cvert else if mymenu = "32 To Pint" Then conver = 16 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Ounce to Pint" goto cvert else if mymenu = "33 To Fifth" Then conver = 25.6 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Ounces to Fifth" goto cvert else if mymenu = "34 To Quart" Then conver = 32 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Ounce to Quart" goto cvert else if mymenu = "35 To Half Gallon" Then conver = 64 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Ounce to Half Gallon" goto cvert else if mymenu = "36 To Gallon" Then conver = 128 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Ounce to Gallon" goto cvert else if mymenu = "37 To Ounce" Then conver = 8 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Cup to Ounces" goto cvert else if mymenu = "38 To Pint" Then conver = 2 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Cup to Pints" goto cvert else if mymenu = "39 To Fifth" Then conver = 3.2 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Cup to Fifth's" goto cvert else if mymenu = "40 To Quart" Then conver = 4 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Cup to Quart's" goto cvert else if mymenu = "41 To Half Gallon" Then conver = 8 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Cup to Half Gallons" goto cvert else if mymenu = "42 To Gallon" Then conver = 16 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Cup to Gallons" goto cvert else if mymenu = "43 To Ounce" Then conver = 16 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Pint to Ounces" goto cvert else if mymenu = "44 To Cup" Then conver = 2 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Pint to Cups" goto cvert else if mymenu = "45 To Fifth" Then conver = 1.60 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Pint to Fifth" goto cvert else if mymenu = "46 To Quart" Then conver = 2 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Pint to Quart" goto cvert else if mymenu = "47 To Half Gallon" Then conver = 4 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Pint to Half Gallon" goto cvert else if mymenu = "48 To Gallon" Then conver = 8 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Pint to Gallon" goto cvert else if mymenu = "49 To Ounce" Then conver = 25.6 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Fifth to Ounces" goto cvert else if mymenu = "50 To Cup" Then conver = 3.2 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Fifth to cup" goto cvert else if mymenu = "51 To Pint" Then conver = 1.6 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Fifth to Pints" goto cvert else if mymenu = "52 To Quart" Then conver = 1.25 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Fifth to Quart" goto cvert else if mymenu = "53 To Half Gallon" Then conver = 2.5 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Fifth to Half Gallon" goto cvert else if mymenu = "54 To Gallon" Then conver = 5 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Fifth to Gallon" goto cvert else if mymenu = "55 To Ounce" Then conver = 32 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Quart to Ounces" goto cvert else if mymenu = "56 To Cup" Then conver = 4 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Quart to Cups" goto cvert else if mymenu = "57 to Pint" Then conver = 2 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Quart to Pints" goto cvert else if mymenu = "58 To Fifth" Then conver = 1.25 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Quart to Fifth" goto cvert else if mymenu = "59 To Half Gallon" Then conver = 2 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Quart to Half Gallon" goto cvert else if mymenu = "60 To Gallon" Then conver = 4 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Quart to Gallons" goto cvert else if mymenu = "61 To Ounce" Then conver = 64 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Half Gallon to Ounces" goto cvert else if mymenu = "62 To Cup" Then conver = 8 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Half Gallon to Cups" goto cvert else if mymenu = "63 To Pint" Then conver = 4 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Half Gallon to Pints" goto cvert else if mymenu = "64 To Fifth" Then conver = 2.5 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Half Gallon to Fifths" goto cvert else if mymenu = "65 To Quart" Then conver = 2 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Half Gallon to Quarts" goto cvert else if mymenu = "66 To Gallon" Then conver = 2 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Half Gallon to Gallons" goto cvert else if mymenu = "67 To Ounce" Then conver = 128 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Gallon to Ounces" goto cvert else if mymenu = "68 To Cup" Then conver = 16 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Gallon to Cups" goto cvert else if mymenu = "69 To Pint" Then conver = 8 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Gallon to Pints" goto cvert else if mymenu = "70 To Fifth" Then conver = 5 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Gallon to Fifths" goto cvert else if mymenu = "71 To Quart" Then conver = 4 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Gallon to Quarts" goto cvert else if mymenu = "72 To Half Gallon" Then conver = 2 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Gallon to Half Gallons" goto cvert else if mymenu = "73 To Minutes" Then conver = .6 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Hundreth's to Minutes" goto cvert else if mymenu = "74 To Minutes" Then conver = 60 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Seconds to Minutes" goto cvert else if mymenu = "75 To Moments" Then conver = 90 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Seconds to Moments" goto cvert else if mymenu = "76 To Hours" Then conver = 3600 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Seconds to Hours" goto cvert else if mymenu = "77 To Days" Then conver = 86400 vLastEntry = vLastAns/conver vOpr = "*" cvlabel = "Seconds to Days" goto cvert else if mymenu = "78 To Seconds" Then conver = 60 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Minutes to Seconds" goto cvert else if mymenu = "79 To Hundreth's" Then conver = .6 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Minutes to Hundreths" goto cvert else if mymenu = "80 To Hours" Then conver = 60 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Minutes to Hours" goto cvert else if mymenu = "81 To Moments" Then conver = 1.5 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Minutes to Moments" goto cvert else if mymenu = "82 To Days" Then conver = 1440 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Minutes to Days" goto cvert else if mymenu = "83 To Weeks" Then conver = 10080 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Minutes to Weeks" goto cvert else if mymenu = "84 To Fortnight" Then conver = 20160 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Minutes to Fortnights" goto cvert else if mymenu = "85 To Months" Then conver = 43829.1 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Minutes to Months" goto cvert else if mymenu = "86 To Years" Then conver = 525949.2 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Minutes to Years" goto cvert else if mymenu = "87 To Seconds " Then conver = 90 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Moments to Seconds" goto cvert else if mymenu = "88 To Hours" Then conver = 40 vLastEntry = vLastAns/conver vOpr = "" cvlabel = "Moments to Hours" goto cvert else if mymenu = "89 To Days" Then conver = 960 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Moments to Days" goto cvert else if mymenu = "90 To Weeks" Then conver = 6720 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Moments to Weeks" goto cvert else if mymenu = "91 To Fortnight" Then conver = 13440 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Moments to Fortnight" goto cvert else if mymenu = "92 To Months" Then conver = 29219.4 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Moments to Months" goto cvert else if mymenu = "93 To Years" Then conver = 350632.8 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Moments to Years" goto cvert else if mymenu = "94 To Seconds" Then conver = 3600 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Hours to Seconds" goto cvert else if mymenu = "95 To Minutes" Then conver = 60 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Hours to Minutes" goto cvert else if mymenu = "96 To Moments" Then conver = 40 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Hours to Moments" goto cvert else if mymenu = "97 To Days" Then conver = 24 vLastEntry = vLastAns/conver vOpr = "" cvlabel = "Hours to Days" goto cvert else if mymenu = "98 To Weeks" Then conver = 168 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Hours to Weeks" goto cvert else if mymenu = "99 To Fortnight" Then conver = 336 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Hours to Fortnights" goto cvert else if mymenu = "100To Months" Then conver = 730.485 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Hours to Months" goto cvert else if mymenu = "101To Years" Then conver = 8765.82 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Hours to Years" goto cvert else if mymenu = "102To Seconds" Then conver = 86400 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Days to Seconds" goto cvert else if mymenu = "103To Minutes" Then conver = 1440 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Days to Minutes" goto cvert else if mymenu = "104To Moments" Then conver = 960 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Days to Moments" goto cvert else if mymenu = "105To Hours" Then conver = 24 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Days to Hours" goto cvert else if mymenu = "106To Weeks" Then conver = 7 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Days to Weeks" goto cvert else if mymenu = "107To Fortnight" Then conver = 14 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Days to Fortnights" goto cvert else if mymenu = "108To Months" Then conver = 30.436875 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Days to Months" goto cvert else if mymenu = "109To Years" Then conver = 365.2425 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Days to Years" goto cvert else if mymenu = "110To Seconds" Then conver = 604800 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Weeks to Seconds" goto cvert else if mymenu = "111To Minutes" Then conver = 10080 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Weeks to Minutes" goto cvert else if mymenu = "112To Moments" Then conver = 6720 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Weeks to Moments" goto cvert else if mymenu = "113To Hours" Then conver = 168 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Weeks to Hours" goto cvert else if mymenu = "114To Days" Then conver = 7 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Weeks to Days" goto cvert else if mymenu = "115To Fortnight" Then conver = 2 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Weeks to Fortnight" goto cvert else if mymenu = "116To Months" Then conver = 4.3333 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Weeks to Months" goto cvert else if mymenu = "117To Years" Then conver = 52 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Weeks to Years" goto cvert else if mymenu = "118To Seconds" Then conver = 1209600 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Fortnight to Seconds" goto cvert else if mymenu = "119To Minutes" Then conver = 20160 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Fortnight to Minutes" goto cvert else if mymenu = "120To Moments" Then conver = 13400 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Fortnight to Moments" goto cvert else if mymenu = "113To Hours" Then conver = 336 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Fortnight to Hours" goto cvert else if mymenu = "114To Days" Then conver = 14 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Fortnight to Days" goto cvert else if mymenu = "123To Weeks" Then conver = 2 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Fortnight to Weeks" goto cvert else if mymenu = "124To Months" Then conver = 2.174 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Fortnight to Months" goto cvert else if mymenu = "125To Years" Then conver = 26.089 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Fortnight to Years" goto cvert else if mymenu = "126To Seconds" Then conver = 2629746 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Months to Seconds" goto cvert else if mymenu = "127To Minutes" Then conver = 43829 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Months to Minutes" goto cvert else if mymenu = "128To Moments" Then conver = 29219.4 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Months to Moments" goto cvert else if mymenu = "129To Hours" Then conver = 730.485 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Months to Hours" goto cvert else if mymenu = "130To Days" Then conver = 30.436875 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Months to Days" goto cvert else if mymenu = "131To Weeks" Then conver = 4.348 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Months to Weeks" goto cvert else if mymenu = "132To Fortnight" Then conver = 2.174 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Months to Fortnight" goto cvert else if mymenu = "133To Years" Then conver = 12 vLastEntry = vLastAns/conver vOpr = "/" cvlabel = "Months to Years" goto cvert else if mymenu = "134To Seconds" Then conver = 31556952 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Years to Seconds" goto cvert else if mymenu = "135To Minutes" Then conver = 525949.2 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Years to Minutes" goto cvert else if mymenu = "136To Moments" Then conver = 350632.8 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Years to Moments" goto cvert else if mymenu = "137To Hours" Then conver = 8765.82 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Years to Hours" goto cvert else if mymenu = "138To Days" Then conver = 365.2425 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Years to Days" goto cvert else if mymenu = "139To Weeks" Then conver = 52 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Years to Weeks" goto cvert else if mymenu = "140To Fortnight" Then conver = 26.089 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Years to Fortnights" goto cvert else if mymenu = "141To Months" Then conver = 12 vLastEntry = vLastAns*conver vOpr = "*" cvlabel = "Year to Months" goto cvert end if end cvert: t = table.current() t.enter_begin() t.Date = Date() t.SAVECNT = vSaveCnt t.TAPETYPE = vTapeType t.TITLE = vTitle t.NVALUE = conver t.NANSWER = vLastAns t.Lineitemdesc = cvlabel t.Coperand = vOpr t.cVALUE = str(t.NValue,16,vDec,vFmtType) t.cANSWER = str(vLastAns,16,vDec,vFmtType) t.enter_end(.t.) vLastAns = t.NANSWER cdcTapeCalc:nanswer.entry.dec = vDec vLineItem = "" cdcTapeCalc:nanswer.entry.format = vFmtType cdcTapeCalc:nanswer.refresh() cdcTapeCalc:vlineitem.Refresh() cdcTapeCalc.Fetch_Last() cdcTapeCalc:browse1.refresh() vLastAns = vLastEntry t = table.current() t.enter_begin() t.Date = Date() t.SAVECNT = vSaveCnt t.TAPETYPE = vTapeType t.TITLE = vTitle t.NVALUE = vLastEntry t.NANSWER = vLastAns t.Lineitemdesc = "Answer" t.Coperand = "=" t.cVALUE = str(t.NValue,16,vDec,vFmtType) t.cANSWER = str(vLastAns,16,vDec,vFmtType) t.enter_end(.t.) vLastAns = t.NANSWER cdcTapeCalc:nanswer.entry.dec = vDec vLineItem = "" cdcTapeCalc:nanswer.entry.format = vFmtType cdcTapeCalc:nanswer.refresh() cdcTapeCalc:vlineitem.Refresh() cdcTapeCalc.Fetch_Last() cdcTapeCalc:browse1.refresh() cdcTapeCalc:btntapeedit.push()
There is a lot of code here but most of it is designing the popup menu. When the user selects a menu choice, the if else if.. statement sets the variables then branches to the actual code to create the conversion and new answer. Last step we push the edit button to commit the record and present the answer.
For those of you who learn better by seeing rather than reading, here is a short video of the calculator in action and the code discussed above.
Well that’s it for today’s session. I hope you found it informative. In our next session I will revisit our file organizer because it does not work as well as intended. Hope you will stop back. Thanks again for stopping by and Remember, if you need help with an Alpha Software application or wish to inquire about a custom application for your business go to our website
and inquire or contact
NLawson@cdc-TakeCharge.com
Have a great day.
Leave a comment