For starters I'm very very new to writing code! :)
What I have so far...
So far I've used Xamarin.Forms to create a user interface for a sort of specialized calculator. I'm using a Grid Layout containing: a first column of Labels, a second column of Entries (that I have named in Xaml), and a third column of Steppers (so I can change the entries by typing or using the stepper). These 3 views on each row repeat for several rows with different label text on each row and at the bottom of the Grid Layout I have an Entry for the output.
The problem...
Basically, I want to buy a certain product at different weights and prices...among other criteria....and I want to quickly figure out how much money I'll make at a future possible sale price. Simply put... I'm trying to add/subtract/multiply/divide using Xamarin.Forms Entries. I've looked everywhere and can't seem find anyone giving an example of how to do this. I've tried different methods and usually end with an error of not being able to convert the Xamarin.Forms entry to a string...So I'm back to zero. Can I get an example of a Method where I would be able to add/subtract/multiply/divide 2 Xamarin.Forms Entry views together in the C# code behind? This seems very simple to me...what am I missing??? Is there a thread/article/video somewhere that I haven't found that covers this?? And like I said, I'm very new so the answer is probably very simple.
Thanks in advance!
Steven
Entries deal with strings, not numeric values, so you need to convert them before doing calculations.
var amount = Decimal.Parse(EntryA.Text);
var price = Decimal.Parse(EntryB.Text);
var total = amount * price;
// you can use a format string as an argument to ToString()
// to control the output - ie, how many decimals, commas, etc
LabelTotal.Text = total.ToString();
In a real app you will want to validate the input in case the user enters text instead of a value number (the Parse method will throw an exception if the input is bad);
Related
My main problem is that i need to be able to have asp.mvc accept the Danish number format (meaning a dot every thousand and a comma seperator). Since i am working on a larger system, I need a more in-depth solution.
The formating problem includes the fact that I need to beable to solve the errorhandling aswell, which does not accept the 0,00 as a number. best case, the solution still maintains the possibility to calculate with the numbers without having to format them each time.
As another point, I need to beable to switch between the English format, meaning (0.00) and the Danish (0,00).
TL;DR
Solve the problem of using a diffrent formatting in mvc asp.net from (en 0.00) to (da 0,00), including errorhandling, still allowing for calculations in jquery or javascript, and the posibility to switch back to the english format (0.00).
What would be the best way to go about this?
Edit: Solved most of it!
To get the View (Jquery validate) to accept comma as a seperator I've inserted "One regexp" from this: http://mfranc.com/javascript/jquery-valdiator-modyfing-decimal-separator/
Adding the custom model binding, provided by #chrispratt solved the problem of the controller receiving the number in the right format.
On top of this I've added code to modify any number entered into an input field into the right format.
Also all numbers and their display formats are checked before being shown. (since some doubles display without ,00)
I think that should be it, now all that remains is to devise some method of switching between languages and formats, which I should beable to manage.
Thanks for the help!
Any help is apprichiated!
Thanks in advance!
How can I compare two textboxes in c# using greater than or less than. Im working on billing system. I want the cash shoould be bigger than the total. if not. it will pop up messagebox for error. I already try convert to int. to double. to string.
Here's my current code right now.
if (txtCash.TextLength < txtTotal.TextLength){
MessageBox.Show("Cash must me bigger than the total");
txtCash.Focus();
return;
}
Any one can help me how?
I know text length is wrong. but im just using it.
I'm working on billing system. I want the cash should be bigger than
the total. if not. it will pop up message box for error.
You might be looking for something like this:
if (double.Parse(txtCash.TextLength) <= double.Parse(txtTotal.TextLength))
{
MessageBox.Show("Cash must me bigger than the total");
txtCash.Focus();
return; // i dont know why you put this here but i'll leave it there anyway.
}
else
{
var amount = double.Parse(txtCash.TextLength);
// DO something
}
You may want to further validate the user input if you wish. Example, if the user doesn't enter numbers...
Better ways to achieve your task in the most robust way possible, you should consider the below links:
How do I make a textbox that only accepts numbers?
double.TryParse(...)
Update:
Seems, you're not sure about the keyword var. I suggest you have a deep read of the MSDN reference page for var.
My report needs to display all information of application form in box format - similar to a bank account opening form:
|M|A|R|K| |J|O|H|A|N|S|O|N
How can I achieve this in Crystal Reports?
The logic for splitting the name may differ, but for simplicity I used an array extension method:
string name = "MARK JOHANSON";
char[] nameArray = name.ToArray<char>();
{nameArray[0]} &"|"& {nameArray[1]} &"|"& {nameArray[2]} & ..
This is very uncommon, so Crystal doesn't have something out of the box that supports this feature. When push comes to shove, if you don't like user3350003's answer, you'll probably have to make a series of box objects for each letter. In this case, Formulas.
Assume you're willing to support names up to N characters total. Create N many Formula Fields named Box1, Box2, Box3... BoxN. The logic inside each will be very similar - For example, Box7 would look like:
MID({PersonName}, 7, 1)
Then arrange them in order on your report, turn off Can Grow, and format them with Outside Borders:
I got the some alternate solution as crystal report not providing what I want. I have find the monospace fonts which have already bordered with particular character. By this technique I am able to fulfill my goal.
Thanks all for looking into this.
In my WPF application the user is inputting a GPS coordinates in the format of Degrees : Minutes : Seconds as decimal fraction of minutes.
So 60° 30' 45" would be entered as 60° 30.750' .
I then store it as a pure decimal number so the above example would be stored as 60.5125.
The idea was that so the users wouldn't mess up the input it would be set in 3 different textboxes. One for Degrees, other for Minutes and one for the fractionalSeconds. It's somewhat bad that one of the numbers is seperated into two textboxes but if they have to type the whole number in the are afraid of all the point or comma confusion and that they could mess up.
So one thing I thought might work was a IMultiValueConverter but it seems to only work with MultiBindings which is something I'm not doing here.
Currently my solution is to bind to different properties and do all the calculations in code behind but I'm not really happy about the fractional bit. I assume 3 fractional letters but if they enter only 7 and assume 0.700 but get 0.007 so I thought I would have to do a string format bit.
Is there a better solution out there. Can I use MultiValueConverter for something like this?
You could try using a MaskedTextBox, such as the one from the Extended WPF Toolkit.
You could use a Masked TextBox. This implementation uses MaskedTextProvider which is a .net class.
I've been working on an ExcelDNA/C# add in for a while, and I'm at the final hurdle.
I can get a selection address, and I first of all need to check if the rows in that selection are simply two, e.g. in Excel they would be 8+9, two rows next to each other or any two consecutive numbers.
I then need to check that there are more than two columns, etc C to J (more than two spaces in the alphabet).
This all needs to be done from a string like this: Sheet1!$C$8:$J$9
What I am trying to do, is split a selection like this, which returns the above string, into two strings, in the case of the example, the desired end result would be
Sheet1!$C$8:$J$8 + Sheet1!$C$9:$J$9 in two different strings, perhaps I need more coffee, but if anyone has a less trashy way of doing this than I plan, I would be forever in your debt!
Do you have a reference to the Range object? If so, range.Rows.Count == 2 will tell you if there are two rows, and range.Columns.Count > 2 will tell you if there are more than two columns.
Then, to get the addresses of the two rows independently you can do something like:-
var address1 = range.Rows[1].Address(external:true);
var address2 = range.Rows[2].Address(external:true);
I presume this is running from a macro called from a CommandBar or Ribbon event handler.
On that case you might as well use the COM Automation interface from the start, and never bother the the C API (XlCall and ExcelReference).
To get the current selection you'd just say
Application xlApp = (Application)ExcelDnaUtil.Application;
Range selectedRange = xlApp.Selection as Range;
if (selectedRange != null)
{ .... do you further checking here ...}
The C API stuff is a bit more important if you are making user-defined functions or you want high-performance data transfers. But for regular macros the COM API is easier.