This is the piece of code and this doesnt take zero as an input value. But it does validate well with floating point and integer values.
I have tried with setting the locale, but that too doesnt seem to work.
$commNotEmpty = new Zend_Validate_Float();
$commNotEmpty->setMessage('Please enter a numeric value');
$this->comm = new Zend_Form_Element_Text('comm');
$this->comm->class ='full_width';
$this->comm->addValidators(array($commNotEmpty));
Related
I have developer console in my game and when you press up arrow it'll load previous command that you used, to input filed. But when I try to change text from script I'll write the previous command to the input filed but the input filed is not editable anymore until you press esc key.
I am using the new TMPro.TMP_InputField.
inputField.text = typedCommands[(typedCommands.Count) - backCount];
inputField.caretPosition = inputField.text.Length;
On the first line I am setting text variable of the input field and on the second one I am setting cursor behind tha last character in the input field.
When I try to delete all text from the input filed from editor when the game is running I get this error:
IndexOutOfRangeException: Index was outside the bounds of the array.
TMPro.TMP_InputField.GenerateCaret (UnityEngine.UI.VertexHelper vbo, UnityEngine.Vector2 roundingOffset) (at Library/PackageCache/com.unity.textmeshpro#2.0.0/Scripts/Runtime/TMP_InputField.cs:3304)
TMPro.TMP_InputField.OnFillVBO (UnityEngine.Mesh vbo) (at Library/PackageCache/com.unity.textmeshpro#2.0.0/Scripts/Runtime/TMP_InputField.cs:3271)
TMPro.TMP_InputField.UpdateGeometry () (at Library/PackageCache/com.unity.textmeshpro#2.0.0/Scripts/Runtime/TMP_InputField.cs:3209)
TMPro.TMP_InputField.Rebuild (UnityEngine.UI.CanvasUpdate update) (at Library/PackageCache/com.unity.textmeshpro#2.0.0/Scripts/Runtime/TMP_InputField.cs:3184)
UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/CanvasUpdateRegistry.cs:198)
UnityEngine.Canvas:SendWillRenderCanvases()
It seems that the input field change its value but it doesn't see that there is some text in itself that you did not type directly in it.
EDIT:
Here is more code for better understanding. I call this piece of code from the update loop.
private void typedCommandFunc()
{
if (Input.GetKeyDown(KeyCode.UpArrow) && backCount != (typedCommands.Count))
backCount++;
if (Input.GetKeyDown(KeyCode.DownArrow) && backCount > 0)
backCount--;
if(backCount != 0)
{
inputField.text = typedCommands[(typedCommands.Count) - backCount];
inputField.caretPosition = inputField.text.Length;
}
}
Based on your error log, it seems like the problem is with generating the caret:
IndexOutOfRangeException: Index was outside the bounds of the array.
TMPro.TMP_InputField.GenerateCaret(UnityEng...
It might not be possible to make a caret right after where the string ends, try:
inputField.caretPosition = inputField.text.Length -1;
instead.
If you really wanted to make a caret right after the string ends, use the same code, but have a blank white-space at the end of the input-field.It gives an illusion to the player where the caret is at the end of the string (Though, it is just at an empty white-space).
Also, it is possible for your typedCommands to have nothing and you might be still accessing it, so hence you might want to do:
if(backCount != 0 && typedCommands.Count != 0)
typedCommands.Count returns the length of typedCommands. Whenever backCount is equal to 0 the code actually reads typedCommands[typedCommands.Count]. This won't work since an array starts at 0 and typedCommands.Count will start counting at one and will return a value that is one outside of the bounds of the array.
You should always subtract 1 from the count to stay inside the bounds of the array like so:
inputField.text = typedCommands[typedCommands.Count - 1 - backCount];
String to Integer (atoi)
This problem is implement atoi to convert a string to an integer.
When test input = " +0 123"
My code return = 123
But why expected answer = 0?
======================
And if test input = " +0123"
My code return = 123
Now expected answer = 123
So is that answer wrong?
I think this is expected result as it said
Requirements for atoi:
The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value.
Your first test case has a space in between two different digit groups, and atoi only consider the first group which is '0' and convert into integer
I am writing some formulas in crystal reports. I have a field that may contain a numeric value, in which case I am doing some calulation on it, or it may contain a string value, in which case it should be returned verbatim. So I thought this should work: If Result.entry contains a number, then put that numeric value into Result, else just return Result.entry:
Local NumberVar Result := 0;
if NumericText({RESULT.ENTRY}) // may be N.D. or B.L.D.
then
( Result:=val({RESULT.ENTRY});)
else (
{RESULT.ENTRY} );
);
// something more going on here that at last returns some value
But no..."A number is required here" says CR and highlights the block following else... Any clue at all to what Crazy, sorry Crystal Reports wants here and why this is not acceptable? I've even tried to set a value and report that afterwards, (as per Crystal report if then help, how to return a string or variable with formula) but I still get the same error.
else ( 0 );
works - but that is definately not what I want. (the other return value from this function is also a string)
you are trying to assign if part as number and else part as String which won't work, you either return both numbers or both strings.
So you save the numeric value as string and while using in calculation convert to number
Local StringVar Result;
if NumericText({RESULT.ENTRY}) // may be N.D. or B.L.D.
then
Result:={RESULT.ENTRY};
else (
{RESULT.ENTRY} );
);
Now when using in calculation you can use ToNumber(Result)
Almost important to note here is that if declaring something as NumberVar then the field being added has to be a number. If dealing with decimals use CurrencyVar as you cannot set NumberVar to 0 and then add it to a decimal value, which will result in getting a number is expected here result.
Help My Balloon finding macro is not working with input box, it works only when i manually add the balloon number.. please tell me what i m missing ...Ferdo m expecting you
Language="VBSCRIPT"
Sub CATMain()
Set drawingDocument1 = CATIA.ActiveDocument
Set selection1 = drawingDocument1.Selection
result = InputBox("Ballon Number ?", "Title") 'The variable is assigned the value entered in the InputBox
selection1.Search "CATDrwSearch.DrwBalloon.BalloonPartName_CAP= result ,all"
End Sub
I don't know what you are doing but the last line looks wrong. I don't know what the docs are for your function but you are passing the string result rather than the value of the variable result because it is in quotes. Assuming your line is otherwise right ...
selection1.Search "CATDrwSearch.DrwBalloon.BalloonPartName_CAP= " & result & ",all"
I have a gtk.spinbutton and I want to set the digits according to the locale
format.
like say I have a locale installed hungarian so my decimal separator is
'.'(dot) and thousand separator is ','(comma) eg: my spinbutton value is
1131191 so after the user focus out of the gtk.spinbutton my value should
convert to 11,311.91 . the conversion is made by me but I am not able to set
it to gtk.spinbutton either using set_text / set_value method.
Any help is appreciated !
Thanks
Formatting a SpinButton can be done by handling the output signal.
locale.setlocale(locale.LC_ALL, '')
def output(spin):
digits = int(spin.props.digits)
value = spin.props.value
text = locale.format('%.*f', (digits, value), True)
spin.props.text = text
return True
spin.connect('output', output)
If you also want to let users enter values in the localised format (e.g. let the user type "1,000" instead of "1000"), handle the input signal.
def input(spin, new_value):
text = spin.props.text
try:
value = locale.atof(text)
except ValueError:
return -1
p = ctypes.c_double.from_address(hash(new_value))
p.value = value
return True
spin.connect('input', input)
(This code is longer than it should be because PyGTK does not properly wrap input, hence the ctypes hack. It's just parsing the text and then assigning the numeric value to a pointer location.)
Credits: The ctypes hack and digits formatting are inspired by Tim Evans's post in the PyGTK mailing list.