Storing a variable for use in a Calculated Field

Discussion of the version of HanDBase that runs on the iPhone and iPod touch devices. This includes the synchronization conduits as well.

Storing a variable for use in a Calculated Field

Postby Man in Mansfield » Fri Jun 19, 2009 10:00 pm

I would like to somehow store the current cost of a KWH of electricity, so that I can reference it in formulas in several calculated fields. When power costs change, I would then be able to simply change the KWH cost at one place and all the formulas would automatically adjust to the new value. Is this possible in HandBase?
Man in Mansfield
 
Posts: 3
Joined: Thu Jun 18, 2009 9:57 pm

Re: Storing a variable for use in a Calculated Field

Postby dhaupert » Mon Jun 22, 2009 3:02 pm

When designed HanDBase v1, I had thought about that feature. The idea of having some sort of global variables. But I honestly worried it was too programmer-y to be considered a user friendly feature. In the 11 years since HanDBase has been out, I don't recall a single request for it until now, so I always thought it was a smart move to leave it out. As they say, a good consumer friendly solution is not marked by the amount of features thrown in, but what was intentionally left out!

This said, here are two possible workarounds:

1. Desktop only (for now due to iPhone versions lack of a set value feature):
Create a text field and set it's default value to the constant global value you desire. You can safely hide this field from viewing in either list view or edit record view.
Use this field in your calculation.
Now use the Set Value to.. option to set this value to whatever the global variable is currently. This will apply to all records and recalc them as needed.


2. Hard code the value into the DB. Then the user will have to go into DB properties to change it.

There may be others, but none as simple as you probably can dream up!
dhaupert
 
Posts: 4111
Joined: Tue May 26, 2009 11:51 am

Re: Storing a variable for use in a Calculated Field

Postby Man in Mansfield » Wed Jun 24, 2009 10:01 pm

I worked out a method that actually seems to do exactly what I was looking to do.

I created a second database called "Power Cost", with two fields, $/KWH and ID. I entered 0 as the ID and .15 as our current dollar/kwh cost.

Then in my main database where I'm recording the power used by different devices, I created a hidden ID field with a static default value of 0, and a $/KWH field set as a Relationship field, keyed to find the single record in the other database using the matching ID fields. I use this $/KWH field in several calculated fields in this main database.

I can now change the $/KWH in the Power Cost db and it updates all the calculations in my main db.

Dave, can you explain a bit more about the workaround involving "hardcoding in the db"? Maybe that's a simpler approach that the one I've described here.
Man in Mansfield
 
Posts: 3
Joined: Thu Jun 18, 2009 9:57 pm

Re: Storing a variable for use in a Calculated Field

Postby dhaupert » Thu Jun 25, 2009 9:10 am

I think you have come up with a better solution than either I suggested! At least from a user perspective- you could even make a database called global variables and use it for many database designs with numerous values in it.

By hardcoding I meant putting in the calculation the current value and if the cost/kWh changes, the calculation is just edited. In other words, if the cost per kWh is 0.2 and goes to 0.3, go into the calculation and change the calculation to be hours * 0.3 instead of hours * 0.2. Hope that makes sense!
dhaupert
 
Posts: 4111
Joined: Tue May 26, 2009 11:51 am

Re: Storing a variable for use in a Calculated Field

Postby Man in Mansfield » Sun Jun 28, 2009 7:38 pm

OK, thanks for the explanation, Dave. I'm impressed with the amount of attention you pay to these forums -- very helpful! So far my approach of storing the power cost variable in a separate db seems to be working fine....
Man in Mansfield
 
Posts: 3
Joined: Thu Jun 18, 2009 9:57 pm


Return to HanDBase for iPhone and iPod touch

Who is online

Users browsing this forum: No registered users and 1 guest

cron