I have a UITextField and I want to limit the user to only input decimal numbers that are between 0.0 and 24.00.
The main idea is that user is entering Hours in that field. So It can't go over 24 hours in a day.
is it possible to automatically enter a decimal after 2 digits? So when a user enter "18" for example, a decimal "." automatically shows up.
Right now, I am limiting the user to only enter full hours. So they can only enter 2 digits. I really need to change that. This is what I have now.
txtFld_Hours.ShouldChangeCharacters = (textField, range, replacementString) => {
var newLength = textField.Text.Length + replacementString.Length - range.Length;
return newLength <= 2;
};
Thank you for your time.
Everything is possible of course, but like other people mentioned, it would be much better to use UIDatePicker control for a time picker (it even handles localisation for you on iOS, as some countries use 12-hour time with AM/PM marker for example). Even MonoTouch documentation says there are differences between platforms and you should structure your code in a way that only the difference in UI code is written for each platform, but all other code is common to all platforms.
But if you absolutely have to do this on your own, this requires a bit more complex solution, so we cannot write this for you directly. Search over GitHub for some code samples, I am sure that you can easily convert Objective-C into MonoTouch, since it is supposed to be a 1:1 mapping of the API.
Here are a few things on where to start:
See IUITextFieldDelegate interface documentation (which you already know about)
Update the ShouldBeginEditing method with code that will handle the dot.
When 2 characters are reached, add the dot programatically and move the cursor behind the dot using SelectedTextRange property.
The maximum length of the text, should now be 5.
Handle the automatic removal of the dot when text length is 3 and user taps backspace.
Following this and you should have your own UITextField with your custom hour picker.
Related
this is potentially really simple but I have been looking at it for ages, which may be the problem.
I am looking at log in times on a phone system v the times when calls are incoming. The spreadsheet breaks down the phone hours by minute and then checks the times someone logged in and displays if they were logged in at any given minute.
Then the data from incoming calls is pasted in which is converted into timestamps and compared.
The problem is a bit odd because it correctly counts from 9:30 to around 15:00 but then does not count entries after that time.
Here is a link to the spreadsheet copy I have made.
Any help would be appreciated. As I said it's probably really simple but often when you have looked at something too long you miss obvious things.
The problem is due to rounding errors
For example, both cell H72 and MK11 have the display value 15:05:00.
However, if you visualize the real value of the cells, e.g. by Paste values only into a cell formatted as a number you will see:
The exact value of cell H72 is 0.628472222222222
The exact value of cell MK11 is 0.628472222222221
This rounding error was not obvious for the first rows / columns but it kept propagating through the data until the point of becoming big enough to change 15th decimal position.
The reason is that Google Sheets stores numbers as 64 bit signed floating points which limits the precision to the 15th decimal position and thus rounding errors will not become obvious as long as they are smaller than this.
Solution
Given that you use the formula
=ROUNDUP(F12*1440/1,0)*1/1440
on column H for the call list, you should do the same for the incoming rows in row 9, so
=ROUNDUP(1440*(N11+time(0,1,0)))/1440
and so on.
Here is the code that I thought and tried. I thought that it was the right way to buy and sell for the Fractals signals. But getting buy and sell signals simultaneously.
double UP[],DOWN[];
double fractal_output = iFractals(_Symbol,_Period);
ArraySetAsSeries(UP,true);
ArraySetAsSeries(DOWN,true);
CopyBuffer(fractal_output,0,0,5,UP);
CopyBuffer(fractal_output,1,0,5,DOWN);
if (UP[1])
{
Comment("BUY");
trade.Buy(0.1);
}
if (DOWN[1])
{
Comment("SELL");
trade.Sell(0.1);
}
I don't understand how I can plan to buy and sell using the iFractals function indicator in my MQL5. What improvements need to be done?
A double fractal_output should be int not double and initialized in the OnInit(){...} just once, not each tick.
Make sure you understand which fractal is obtained when accessing UP[1] - it seems to be 0,1,2,3,4 (left to right), so you are asking for fractal 3 bars before the current Bar.
Alternatively you can get a value before the current Bar (most probably it is zero until next bar after current starts).
Make sure that you have copied the buffer correctly (it is possible that it is not copied and UP[1] may throw out-of-range error - for that reason CopyBuffer returns a number of elements actually copied (so if CopyBuffer()!=5){print();return;})
What do you expect to see when calling if(UP[1]){} ?
A buffer might take both positive values and EMPTY_VALUE (== 2^31-1).
It is better to check the value of the buffer: if(UP[i]>0){} or if(UP[i]!=EMPTY_VALUE){...}
Do not forget about a special case, when some candle has both an upper and a lower fractal - What to do in that corner-case?
It will open a Long and then open a Short (so it may close the Buy by opening a Short).
Probably you need check the open orders before that or open bar - otherwise you'll have many positions opened during one candle.
Tester will help you find other problems that you could miss when planning the EA.
I want to offer the user the choice of imperial or metric measurement of weight in my app to increase audience suitability. I have designed the following below to allow me to determine which setting the user wishes to use.
However, im unsure how I would go about applying the metric selection to the whole rest of the app? Would it be a case of setting the app reach into each object the user has created in coredata and all text labels relating to a weight measurement and alter their weight property by multiplication or division each time the user changes weight system?
Appreciate any insight into how I may achieve this as I didnt want to go too far in the wrong direction!
func convertAppMetric() {
if self.userSelectedWeightSystem == "Metric" {
print("THE USER SET THE APP TO METRIC, CONVERTING FIGURES...")
//some code
} else if self.userSelectedWeightSystem == "Imperial" {
print("THE USER SET THE APP TO IMPERIAL, CONVERTING FIGURES...")
//some other code
}
}
This is going to be one of those answers that SO hates, but you want to go read up on NSMeasurement.
NSMeasurement holds both a value and a Unit, the later of which is the original measurement type. You store all your data in the format that was originally provided - if the user puts in pounds, store a NSMeasurement with 182 pounds. If they put in kg, make one with 90 kg. You can even put in your own Units, like stone.
From then on, always present the data using an NSMeasurementFormatter. You can pass in the output type, which in your case is the global setting you mentioned in your question. This means that no matter what unit they provided, it always comes out properly converted to the one you want, and changing it instantly changes it everywhere.
Its easy to make your own converters for weird units. I made one for decimal inches and feet/inches, so 13.5 inches turns into 1' 1.5".
I am not able to make iOS voice over / Accessiblity read large amounts in money format for example £782284.00 , this should read as seven hundered eighty two thousand , two hundered and eight four, but iOS voice over reads this as seven eight two two eight four.
The best way to get your purpose is to format perfectly your numbers to be vocalized as desired by VoiceOver.
Use of NumberFormatter and .spellOut style to read out the accessibilityLabel are important tools to adapt the VoiceOver vocalization for large amounts.
I deeply encourage you to try and vocalize numbers as they should : the application content MUST be adapted to the VoiceOver users, not the opposite.
It is really important to make sure you do all you can to make the app easier to use for VoiceOver users. I have been running an app for sighted and visually impaired players, you can see an example of this method running in the inventory section of the app:
https://apps.apple.com/us/app/swordy-quest-an-rpg-adventure/id1446641513
The number of requests I got from blind & visually impaired players to read out millions as millions, rather than individual digits, was huge. Please do take the extra effort to make it fully VoiceOver compatible. It makes life so much easier for VoiceOver users. Here is a method I created solely for this purpose, that VoiceOver seems to like. You are basically adding thousand comma separators:
// e.g. 1000 -> "1,000"
public static func addCommaSeperatorsToInt(number: Int) -> String {
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = NumberFormatter.Style.decimal
return numberFormatter.string(from: NSNumber(value: number))!
}
I agree to #aadrian is suggesting, try not to break convention VoiceOver users are used to. Because some large numbers are read in a long time, then the users have slow navigation across numbers.
However, if that is the case you need it hard, here you can have (I couldnot find sth for swift/objc but you will get the idea) a number to word converter and then you can set that to _.accessbilityLabel of the UIView or whatever. Then it will read as you like.
Also see this
I am developing a billing system using PowerBuilder 12.5 Classic and I need to set 0 for a textbox; like in vb.net txtchange.Text = 0
i have two drop down list boxes
ddlb_price (defines the price value of an item)
ddlb_cash (the cash amount given by the customer)
sle_change (the change that the cashier is to give the customer)
the system should set the value for sle_change when the cashier inputs the cash.
1. this gives me syntax error;
if cash=price then
sle_fare.settext=0
end if
2. this gives 'incompatible types in assinment
if cash=price then
sle_fare.text=0
end if
The single line edit (sle) control is designed to hold text. You're trying to assign it a numeric value. You will have to change the number into a string if you want the sle to display it:
sle_fare.text = "0"
or
sle_fare.text = string(variableHere)
Once again, I'm going to step back, ignore the actual questions, and look at how a DataWindow would help as an alternative.
You seem to want a control with a data type behind it. The DataWindow has those types of controls. Don't forget that a DataWindow doesn't have to have a SELECT statement behind it; it can have a stored procedure, web service, or nothing at all (external DataWindow) behind the data set. Once you have a control with a numeric data type behind it, you get (for free) some basic editing controls, such as not allowing alpha characters in the field and making sure the entered value is really a number (e.g. "0-.2.1" would fail).
A step beyond that is looking at one of your coming requirements: calculating change. On a DataWindow, you can create a compute with an expression that will automagically calculate your change for you, once price and cash are entered.
I certainly don't want to say you can't do things the way you're proceeding, but there are many issues that a DataWindow would remove over some other approach. The strength of PowerBuilder is in the DataWindow.
Good luck,
Terry