combobox or? is this even possible? - calculator

using windows form in visual studio ....ok so i am creating a sales tax calculator. I need to enter the state and the sales tax for the state and on a click event display the total amount in a textbox. i want to use only one dropdown instead of seperating out to two boxes(one for state and one for tax)
so if the combobox looked like this:
alabama 4%
alaska 5%
wisconsin 5.5%...and so on down the list of states
how can i click on one of the states that includes the tax shown in the dropdown and use just the percentage to run the calculation based on the item amount inputted.
c#calculator

There are Quite a few ways you could do this and here is one. You could use a variable to store
the part of the string on combo box i.e. { alabama 4% } the 4 would be what you want to get store
it in a double, then make a switch statement that checks what state text is in the combo box and
pass that into the switch and if it is alabama then make the tax variable be 4.0;
var tax;
switch(comboboxText)
{
case alabama:
tax = 4.0;
break;
case pennsylviana:
tax = 5.5;
break;
//and so forth
}
then just append tax onto the end of your combobox string.

Related

Auto select an option from a dropdown after a certain date

I'm creating a lost&found log for work, I have a dropdown list with options like "Collected", "Sent to guest", "Donated" etc.
I'd like to have the sheet automatically select 'Donated' after a certain date (maybe after 1 month) IF an option hasn't already been selected.
E.G. If somebody inputs a found pair of gloves on Nov 2nd, The empty dropdown will automatically change to 'Donated' on Dec 2nd unless somebody already selected another option (E.G. 'Collected').
You can accomplish this by either making use of Apps Script to check the conditions and make the corresponding changes or by directly implementing Sheets functions.
Sheets Functions
You can achieve the desired outcome by putting this formula on each status cell:
=IF(TODAY()-D4>30,"Donated","")
It will work as intended, the cell will not display anything until there are 30 days between the TODAY() date and the date provided in the D4 cell. If there are, the cell will display Donated. If another option from the drop-down is selected, that will erase the formula and only the new value will be displayed.
However, this method is more of a quick hack than an actual robust solution, as several things can go wrong. For instance, if an option from the drop-down is chosen by accident and then it is left blank again, the method will not work anymore for that line as the formula will have been permanently erased.
You can read about how TODAY() works here.
Apps Script (recommended)
The following script will check that, for every row in the sheet, both the status cell is blank and that subtracting the DATE FOUND is more than 30 days (unfortunately that has to be done in milliseconds).
function myFunction() {
var spreadSheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadSheet.getSheetByName("Sheet1");
sheet.getLastRow()
var range = sheet.getRange(4,1,sheet.getLastRow(), 7);
//SELECT A RANGE WITH THE 7TH FIRST COLUMNS AND AS MANY ROWS AS NECESSARY
//(WE ARE INTERESTED IN DATA STARTING FROM ROW 4TH)
var values = range.getValues();
var millisecondsIn30Days = 30 * 24 * 60 * 60 * 1000;
for(var row = 0; row<values.length; row++){
var status = values[row][6]; //STATUS IS THE 6TH ELEMENT IN THE ROW ARRAY (COLUMN G)
if(status == "" && (new Date() - values[row][3]) > millisecondsIn30Days){
//MORE THAN 30 DAYS AFTER FOUND
sheet.getRange(row+4,7).setValue("DONATED");
}
}
}
Of course, that script can be run manually or the job can be automated with an installable trigger that runs, for example, every month. You can read more about how to set up such triggers here.

Google Sheets: Show values on a tab depending on date

We have a restaurant and want to show the Menu on a screen with google sheets.
I am using 2 tabs in Google sheets, The main (number 1) with the menu showing to the visitors, the second tab (number 2) has all the dates from today until coming 6 weeks like:
Column A
Column B
Column C
Column D
21 June
Appetizer this day
Main dish this day
Desert today
22 June
Appetizer this day
Main dish this day
Desert today
23 June
Appetizer this day
Main dish this day
Desert today
etc. etc.
Now what we want is that the 3 menu items are copied to the main tab on the day of today, so if it is 22 June, the corresponding appetizer, main dish and desert are copied to the main tab.
Is that possible?
This can be achieved with Google Apps Script. You can have a JavaScript code snippet that does this for you.
Open the required spreadsheet. Go to the Tools menu and click Script Editor. This will open up the script editor window with an empty function, code will have to be written inside this function, give it a name, I'm using updateFood():
function updateFood() {
// Fetch all the sheets/tabs of the current spreadhsheet
let sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
// Select the second sheet/tab using [1], first tab will be [0]
// Fetching the second sheet because that is where the data about the upcoming dates are present
let listSheet = sheets[1];
// Get all the data in the sheet
let data = listSheet.getDataRange().getValues();
// Iterate over all data in the sheet
for(i = 0; i < data.length; i++) {
// Get the date of the current row and create a date object
rowDate = new Date(data[i][0]);
// Get today's date
today = new Date();
// Check if the row date is equal to today's date
if(rowDate.setHours(0,0,0,0) == today.setHours(0,0,0,0)) {
// If the code reaches here, this row has the date same as today
// Get the first tab/sheet and then I'm selecting the cells A1, B1 and C1
// Modify the range as per which cells you want the dish names to be in
let range = sheets[0].getRange("A1:C1");
// Set the values of the selected three cells as the value of the second, third and fourth column in the current row of the 2nd tab which are Appetizer, Main dish and Dessert for that date respectively
range.setValues([[data[i][1], data[i][2], data[i][3]]])
}
}
}
And that's all the code you need! Save it and then you can try clicking on run code and then checking the first tab to see the values updated. However, when you click run for the first time, Google will ask you to grant permissions to the script to access your sheet. Click Review Permissions and then click on your account. Then click Advanced and then click:
.
But you will have to run this code every day. This can be achieved using a time-driven trigger.
In the same script editor window, look at the triggers button on the left:
Click on the + Add Trigger on the bottom right of the screen.
And select the values as follows (change the time as required):
That's all you need. Make sure that in the second tab, create dates in the date column with the Excel DATE(YEAR, MONTH, DAY) function rather than manually typing in the dates.

Conditional logic in Docusgin

I have a legal document where if the money being paid to the vendor is over $5000, then the senior vice president has to sign the document. I'm currently using a text field where the value being paid to the vendor would be entered and wanted to use conditional logic for the scenario: if the value in the text box is over $5000, then the vice president's signature will be required" but this doesn't seem possible since the conditional logic for text boxes is rather restrictive.
You cannot have logic for required tab or not, instead you can use conditional logic for show/hide of the tabs. In your case, you can use text and formula tab to show and hide the Signature tab. Formula will return 1 if value > $5000 and it will return 0 if value is <= 5000. Now conditional logic on Signature tab should be on formula, show Signature tab only when formula value is 1 else do not show Sign tab.

How best to store temperature data for different cities?

It is a little confusing but I will do my best to explain it, I hope it will be fine.
I am trying to create the following functionality in iOS:
I have red button on each row of tableview. The red button is dragged and dropped over the (prototype) tableViewcell and in each row the button will be used. The button text shows the temperature in Fahrenheit. But it changes when tapped so that the color of the button changes to green. And I want the extra functionality at this point; The temperature in Fahrenheit will change into Celcius. (I have the problem on this functionality)
The problem here is that I have a list of tableviewcells (Each is another city), not just one. So I have got that number of buttons and I don't use database to save the temperature data. The data is read through a service and put into an array and transferred to this view by NSUserDefaults.
For example; I have got a list of cities in my tableview. Each is a row and each temperature is put over a red button. Temperature values are the texts of the red buttons.
Berlin 45F
Istanbul 70F
Miami 100F
Chicago 30F
...etc.
So for example, when I tap on the button on Berlin row to change the Fahrenheit to Celcius, there is no problem for the first time so I can get the Celcius value for Berlin, no problem. But when I tap it next time to change it to Fahrenheit again, the value does not come correctly. The Fahrenheit value of Berlin is confused with the other values. Because I don't use a database and it does read the value from an array and it doesn't know which value to use. After some clicks, all the Fahrenheit values come to a single value which is the last city's Fahrenheit value (I use the indexPath.row so it gets the last clicked value)
How can I maintain the temperature data for Berlin without using a database so that when I tap that again after tapping the other cities' buttons, it will show me the correct value (45F or the correct Celcius value)?
Thanks for your help!
While I suggest you use some form of key-based storage (like creating a class "Cities" that stores the temperature, or even storing the city -> temperature key combo in a dictionary), you could read the button text when you click it and convert the value from NSString back to a double or integer.
I assume the function that gets called when you click the button looks something like the one I'm about to write. You can then get the button you clicked and the text it displays like so:
- (IBAction)convertTemperature:(id)sender {
UIButton *myButton = (UIButton *)sender;
NSString *buttonText = [myButton titleForState:UIControlStateNormal];
//...
}
After this, you just convert the string to get the temperature, convert it and display it back.

How to update another text box while typing in access 2007 form?

I have a few text boxes which have to be filled with numeric values from 0 to 100. Below them there is another text box which stands for a total (the sum of the values from the text boxes above). How can I update the sum text box while typing in any of the other text boxes above?
If you are happy that the sum box updates after a box is updated (enter, tab or such like is pressed), then this can be done without any code. First, you will need to set the format of the textboxes to be summed to numeric, then the control source of the sum box becomes:
=Nz([text0],0)+Nz([text2],0)+Nz([text4],0)+Nz([text6],0)+Nz([text8],0) ...
Note the use of Nz, it may be possible to eliminate this by setting the default value property of the various textboxes to be summed.
A large set of controls that need to be summed in this way is often an indication of an error in the design of the database. You would normally expect this kind of thing to be a separate recordset, which could more easily be summed.
I know this is old, but Google didn't come up with much for this topic and this thread didn't really help either. I was able to figure out a very easy way to do this, so hopefully anyone else looking for this will find this helpful.
My need was for actual text as opposed to numbers, but the same applies.
To do what the OP is asking for you'll need at least 3 textboxes. 1 is the textbox you want to have updated each time you type, 2 is the textbox you will be typing in, and 3 is a hidden textbox.
Set textbox 1 to reference the value of the hidden textbox 3 in its control source:
="something in my textbox " & [textbox3]
In the OnChange event of textbox 2 right a line that will set the value of the hidden textbox 3 to the Text property of textbox 2 that you are typing in:
Private Sub textbox2_Change()
Me.textbox3.Value = Me.textbox2.Text
End Sub
Each time the value of the hidden textbox 3 gets updated, the calculation/reference in the displayed textbox 1 will be updated. No need to save caret locations or anything else mentioned in this post.
I was able to do this in Access 2007 by using the On Lost Focus event of the text box.
Just put something like this on the On Lost focus event of each text box that you want to be added , just make sure to set the default value of each text box to 0.
Me.Totals.Value = Me.Text1.Value + Me.Text2.Value + etc..
The moment you click on the next text box or anywhere as long as it loses focus, your sum will already be on the Totals box. You may add as many text boxes as you like, just include them in the code.
This is problematic due to the asinine requirement in Access that you have to set focus to text areas before you can get their value. I would recommend you change your design so that the text field is updated in response to a button click instead of on change.
If you want to go the update-on-change route, you would attach change events to each of the addend text fields. The event handlers would need to save the caret position/selection length, update the sum in the output text field, and restore the caret position. You need to save/restore the caret position because this is lost when the focus changes.
Here's an example for two text fields (txt1 and txt2). The output field is named txtOutput.
Private Sub txt1_Change()
Dim caret_position As Variant
caret_position = Array(txt1.SelStart, txt1.SelLength)
UpdateSum
txt1.SetFocus
txt1.SelStart = caret_position(0)
txt1.SelLength = caret_position(1)
End Sub
Private Sub txt2_Change()
Dim caret_position As Variant
caret_position = Array(txt2.SelStart, txt2.SelLength)
UpdateSum
txt2.SetFocus
txt2.SelStart = caret_position(0)
txt2.SelLength = caret_position(1)
End Sub
Private Sub UpdateSum()
Dim sum As Variant
sum = CDec(0)
txt1.SetFocus
If IsNumeric(txt1.Text) Then
sum = sum + CDec(txt1.Text)
End If
txt2.SetFocus
If IsNumeric(txt2.Text) Then
sum = sum + CDec(txt2.Text)
End If
txtOutput.SetFocus
txtOutput.Text = sum
End Sub