Answered by:
Define a TextBox with allowed Character

Question
-
It is possible to create a Textbox with define character for input?
I mean yes it is possible.
A sample is the progam JLP318 it allowed only Numbers, Decimalpoint, Left, Right, Delete and so on.
Show JLP318
Best Regards Martin
Monday, June 10, 2013 6:29 PM
Answers
-
Oh, that is not my way. I change the , to . before add the number and the add is correctly. That the TextBox names are not number is ok, but that the if canot function with no numbers is a old problem that i wrote by version 0.8 and is not corrected in the following version. We can't write all programs in SB, by so mathch problem it is better to change to visual studio. But this is a long way :-). SB is so easy.
Best Regards Martin
- Marked as answer by martmen Monday, June 17, 2013 5:41 PM
Monday, June 17, 2013 5:41 PM
All replies
-
Nice, I also recently added a method to the LD extension to set the cursor at the end of textbox text after setting it, LDControls.SetCursorToEnd. This allows incorrect values to be deleted and the textbox content reset and the cursor positioned at the end for more data entry.Monday, June 10, 2013 6:37 PM
-
My methode set the cursor on the same possition at the last time. Put in Left, Left (with the cursor key), delete a character and then the cursor is on the same position. It is a litle bit to slow because yuo see the not alowed character in a short time. It is possible to make it faster?
Best Regards Martin
Monday, June 10, 2013 6:45 PM -
Not perfectly in SmallBasic since the character is displayed before the event recogonising it is fired. In your code it may be a bit faster using KeyDown rather than KeyUp since this detects the start of the key press, not its finish.Monday, June 10, 2013 7:03 PM
-
It is possible to set the cursor on the same position after input a not allowed character. That is not evry time the end.
Best Regards Martin
Monday, June 10, 2013 7:34 PM -
It would be possible to create an extension to position the cursor anywhere, but I thought usually it would be the last character at the end, other wise to programmer would have to say at which character they want the cursor placed. If you want this extra feature it would be easy to implement.Monday, June 10, 2013 7:42 PM
-
Please create an extension to position the cursor at position X.
Best Regards Martin
Monday, June 10, 2013 8:01 PM -
LDControls.SetCursorPosition added and uploaded.
- Proposed as answer by Ed Price - MSFTMicrosoft employee Thursday, June 13, 2013 10:51 PM
Monday, June 10, 2013 8:03 PM -
It is unpossible to create a Textbox with definate character. By char "^" as sample it is not possible to check it out because it wait to the second char and show then the ^.
Have anybody an answer for this problem?
@litdev the new function worked fine. Thank you.
Best Regards Martin
Wednesday, June 12, 2013 7:42 PM -
Not sure I understand the question, do you have a small sample program and a little more explanation how to show the problem?Wednesday, June 12, 2013 7:58 PM
-
load QMN689
start it and press keys 1,2 ^12. In the textbox is now 1,^12. It is not allowed the sign ^.
Best Regards Martin
Friday, June 14, 2013 1:54 PM -
This was my test code to only allow a number input and replace the caret cursor correctly if a non number character is entered in the middle of of input, import DLP863
Friday, June 14, 2013 4:05 PM -
its fine but its dumpt!
Put in ^ and ^ then crashed by me. ^ + a = â
Decimal point is in Germany comma. What can i do for change it.
Another bug is by input - and - on the first place.
Best Regards Martin
- Edited by martmen Friday, June 14, 2013 6:17 PM
Friday, June 14, 2013 6:10 PM -
The language locales are always going to be a problem to handle numbers well because SB treats them as strings.
Perhaps just a list of allowed characters along with 0 to 9.
Getting a bit messy, but:
JBR601
Friday, June 14, 2013 6:33 PM -
The dump "^^" is a problem and another is now you can input more then one "," or ".". I think it is not so easy to write a safty input with only numbers. It is not possible to put in negative number. - at first sign is now not possible.
Best Regards Martin
Friday, June 14, 2013 8:10 PM -
The first version I showed works for numbers with UK/US locale, but for German locale you have got many more problems, you could detect a - at the start or multiple ., but it gets even messier.
I do remember seeing an extension I think that tests if a variable is a number which you could use. I can't remember which it was though and it may not work for German (,) numbers.
If you want to test it, I could write one for my extension and see if it works for your German numbers?
Test extension here and SB code to test, import XBZ985.- Edited by litdev Friday, June 14, 2013 9:29 PM
Friday, June 14, 2013 8:55 PM -
Let us start the next test session (the last the language problem in your extention).
I put the text extention with new name in the folder lib under small basic folder. Import the Testprogram XBZ985 save it and start it. I put in the first sign "1" on the number block from my note-book and it dumbt. I stoped the program and start it new. I put in "1" from the text block and its dumbt.
I send you the screen-shot from the dump.
Best Regards Martin
- Edited by martmen Saturday, June 15, 2013 4:03 PM
Saturday, June 15, 2013 4:00 PM -
Do you mean you just typed 1 into the textbox?
I assume you replaced the extension LitDev.dll and LitDev.xml with the one from the test download?
Please re-download the test version again to be sure.
I can't reproduce the crash or see why it could occur.
Saturday, June 15, 2013 4:21 PM -
In the folder lib is only now the test extention. I typed 1 into the text-box and it crashed. Here the LOG of the crash:
bei _SmallBasicProgram.ontexttyped()
bei Microsoft.SmallBasic.Library.Controls.OnTextChanged(Object sender, EventArgs e)
bei System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
bei System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
bei System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
bei System.Windows.Controls.Primitives.TextBoxBase.OnTextChanged(TextChangedEventArgs e)
bei System.Windows.Controls.Primitives.TextBoxBase.OnTextContainerChanged(Object sender, TextContainerChangedEventArgs e)
bei System.Windows.Controls.TextBox.OnTextContainerChanged(Object sender, TextContainerChangedEventArgs e)
bei System.Windows.Documents.TextContainerChangedEventHandler.Invoke(Object sender, TextContainerChangedEventArgs e)
bei System.Windows.Documents.TextContainer.EndChange(Boolean skipEvents)
bei System.Windows.Documents.TextRangeBase.EndChange(ITextRange thisRange, Boolean disableScroll, Boolean skipEvents)
bei System.Windows.Documents.TextRange.ChangeBlock.System.IDisposable.Dispose()
bei System.Windows.Documents.TextEditorTyping.DoTextInput(TextEditor This, String textData, Boolean isInsertKeyToggled, Boolean acceptControlCharacters)
bei System.Windows.Documents.TextEditorTyping.OnTextInput(Object sender, TextCompositionEventArgs e)
bei System.Windows.Controls.Primitives.TextBoxBase.OnTextInput(TextCompositionEventArgs e)
bei System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
bei System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
bei System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
bei System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
bei System.Windows.Input.InputManager.ProcessStagingArea()
bei System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
bei System.Windows.Input.TextCompositionManager.PostProcessInput(Object sender, ProcessInputEventArgs e)
bei System.Windows.Input.InputManager.ProcessStagingArea()
bei System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
bei System.Windows.Input.TextCompositionManager.PostProcessInput(Object sender, ProcessInputEventArgs e)
bei System.Windows.Input.InputManager.ProcessStagingArea()
bei System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
bei System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
bei System.Windows.Interop.HwndKeyboardInputProvider.ProcessTextInputAction(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
bei System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
bei System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
bei System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
bei System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
bei System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(MSG& msg, Boolean& handled)
bei System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(MSG& msg)
bei System.Windows.Threading.Dispatcher.TranslateAndDispatchMessage(MSG& msg)
bei System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
bei System.Windows.Application.RunInternal(Window window)
bei Microsoft.SmallBasic.Library.Internal.SmallBasicApplication.<>c__DisplayClass1.<.cctor>b__0()
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bei System.Threading.ThreadHelper.ThreadStart()Best Regards Martin
Saturday, June 15, 2013 9:42 PM -
No idea,
Strangely the extension method is only 2 lines long (C# below) and neither command should be possible to cause an exception.
public static Primitive IsNumber(Primitive input) { double value; return double.TryParse((string)input, out value) ? "True" : "False"; }
Please re-download the testversion again to be sure. I have re-uploaded it in case there was some problem when I uploaded it before.
Maybe there is something else - the log isn't clear where the problem was.
Saturday, June 15, 2013 9:56 PM -
I downloded all new. The input function normaly good. The number input is ok. The language problem with the decimal point "," is ok. Only one "," is now normaly.
There are some problems i saw:
1. It isn't possible to put in - (minus) at first or last position.
2. Its crashed by sign with 2 key function like keys "^^", "´´" or "``" (not " ' "). Allways it crashed by input "^^" and the others double function keys.
I think we are on a good way to make a number input. I need the input with number input for a program. It is possible to write an extention so for number for definate key (in an array ar allowed key) that was fantastic.
Best Regards Martin
The log is to big. The window has no function to scroll. Here is the log for the 2. problem.
bei System.Windows.Input.TextCompositionManager.UnsafeUpdateComposition(TextComposition composition)
bei System.Windows.Input.TextCompositionManager.PostProcessInput(Object sender, ProcessInputEventArgs e)
bei System.Windows.Input.InputManager.ProcessStagingArea()
bei System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
bei System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
bei System.Windows.Interop.HwndKeyboardInputProvider.ProcessTextInputAction(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
bei System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
bei System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
bei System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
bei System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
bei System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(MSG& msg, Boolean& handled)
bei System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(MSG& msg)
bei System.Windows.Threading.Dispatcher.TranslateAndDispatchMessage(MSG& msg)
bei System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
bei System.Windows.Threading.DispatcherOperation.Wait(TimeSpan timeout)
bei System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
bei System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method)
bei Microsoft.SmallBasic.Library.Controls.GetTextBoxText(Primitive textBoxName)
bei _SmallBasicProgram.ontexttyped()
bei Microsoft.SmallBasic.Library.Controls.OnTextChanged(Object sender, EventArgs e)
bei System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
bei System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
bei System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
bei System.Windows.Controls.Primitives.TextBoxBase.OnTextChanged(TextChangedEventArgs e)
bei System.Windows.Controls.Primitives.TextBoxBase.OnTextContainerChanged(Object sender, TextContainerChangedEventArgs e)
bei System.Windows.Controls.TextBox.OnTextContainerChanged(Object sender, TextContainerChangedEventArgs e)
bei System.Windows.Documents.TextContainerChangedEventHandler.Invoke(Object sender, TextContainerChangedEventArgs e)
bei System.Windows.Documents.TextContainer.EndChange(Boolean skipEvents)
bei System.Windows.Documents.TextRangeBase.EndChange(ITextRange thisRange, Boolean disableScroll, Boolean skipEvents)
bei System.Windows.Documents.TextRange.ChangeBlock.System.IDisposable.Dispose()
bei System.Windows.Documents.TextEditorTyping.DoTextInput(TextEditor This, String textData, Boolean isInsertKeyToggled, Boolean acceptControlCharacters)
bei System.Windows.Documents.TextEditorTyping.OnTextInput(Object sender, TextCompositionEventArgs e)
bei System.Windows.Controls.Primitives.TextBoxBase.OnTextInput(TextCompositionEventArgs e)
bei System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
bei System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
bei System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
bei System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
bei System.Windows.Input.InputManager.ProcessStagingArea()
bei System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
bei System.Windows.Input.TextCompositionManager.PostProcessInput(Object sender, ProcessInputEventArgs e)
bei System.Windows.Input.InputManager.ProcessStagingArea()
bei System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
bei System.Windows.Input.TextCompositionManager.PostProcessInput(Object sender, ProcessInputEventArgs e)
bei System.Windows.Input.InputManager.ProcessStagingArea()
bei System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
bei System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
bei System.Windows.Interop.HwndKeyboardInputProvider.ProcessTextInputAction(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
bei System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)- Edited by martmen Sunday, June 16, 2013 7:48 AM
Sunday, June 16, 2013 7:45 AM -
Thank you that makes some sense, I will try to make it work for both locales. Might need some testing to cover all cases.
1] The initial - is easy, not sure why we would allow the last character to be a -.2] I can't reproduce the ^^ issue, perhaps my UK keyboard is different - which line of code causes this crash - is ^ the ALT key?
3] Please explain more your idea for an array?
- Edited by litdev Sunday, June 16, 2013 2:00 PM
Sunday, June 16, 2013 8:31 AM -
1. Some software allowed - at the end but it is not necessary to do it in small basic. It is ok if the - on the first place.
2. The roof sign is a sign in france (fenêtre = window) and it worked on the following: first you press the key with roof sign (^) and key up. On the screen is no new sign. Second you press as sampe the key a. Automaticly on the sreen show it an â. <-- The roof sign is automaticly over the a. It is a special of language.
3. Define an array for allowed sign. as sample:
allow[1] = "A"
allow[2] = "B"
allow[3] = "C"
allow ...
allow[27] = "Z"
allow[28] = "a"
allow[29] = "b"
allow[30] = "c"
allow ...
allow[54] = "z"The TextBox allowed only the sign in the arry allow. This is my idea. By Input (Y/y = yes or N/n = no) the array is then:
allow[1] = "Y"
allow[2] = "y"
allow[3] = "N"
allow[4] = "n"
In the textbox reaction is only by key Y, y, N, or n. All other key has no reaction.It this possible?
Best Regards Martin
- Edited by martmen Sunday, June 16, 2013 4:11 PM
Sunday, June 16, 2013 4:02 PM -
1] Probably just allow '-' at the start for the IsNumber method - this means that the input would actually be treated by SB as a number, a - at the end isn't I don't think.
2] I'm not sure about the roof sign (circumflex). No option for it on my keyboard - this may be a more general SmallBasic problem that cannot be handled with an extension.
2] Could this not just be handled inside a SmallBasic program checking the GraphicsWindow.LastKey
Sunday, June 16, 2013 5:31 PM -
1) ok, do you change it in the extention?
2)It is a issue for the next version?
3) yes this can handled by checking the GraphikWindow.LastKey but it is to slow by many sign in the array. The sign is a moment on the screen before delete it. I put the last input in a backup-variable, so i don't need delete the input-key. The way to delete the key is to dificult, because the key input is not evrery time on the end. Have you an other idea to do it?
Best Regards Martin
Sunday, June 16, 2013 8:31 PM -
1] Uploaded new version with the IsNumber including initial '-'.
2] I think this is a general internationalization issue with SmallBasic (i.e. not able to handle circumflex etc in textbox).
3] There are ways this could be done in C# say, but can't think yet on any general type commands that could be created for use in SmallBasic. Perhaps the solution for you is to limit a bit the interactive textbox control and have an accept button that does the validation checking.
Sunday, June 16, 2013 10:03 PM -
I wrote a Testprogram and there is a problem with the input number. Please show MVS395. The Result is not a number it ist a text. Why?
The input is 12,25 + 24 + 0,75. Its is correct if i put in "." not ","!
Please help me.
Best Regards Martin
- Edited by martmen Monday, June 17, 2013 4:19 PM
Monday, June 17, 2013 4:16 PM -
Short suggestion: use . not ,
Second, the IsNumber is never used in your program!
TextBox[1] etc is not a number and cannot be checked with:
If (Controls.LastTypedTextBox < TextBox[4] And Controls.LastTypedTextBox >= TextBox[1]) Then
The above is never true.
On my PC , has a different meaning and for some reason behaves differently again. Mixing locales is a real minefield.
Monday, June 17, 2013 4:57 PM -
Oh, that is not my way. I change the , to . before add the number and the add is correctly. That the TextBox names are not number is ok, but that the if canot function with no numbers is a old problem that i wrote by version 0.8 and is not corrected in the following version. We can't write all programs in SB, by so mathch problem it is better to change to visual studio. But this is a long way :-). SB is so easy.
Best Regards Martin
- Marked as answer by martmen Monday, June 17, 2013 5:41 PM
Monday, June 17, 2013 5:41 PM -
Internally SmallBasic decides if variables are numbers in a culture invariant way. To control these culture conversions you would need VS or use culture invariant conventions i.e "." for decimals.
It you use VS and program against different cultures, it is still non trivial to be consistent and allow all different conventions. Sometimes "," is a decimal deliminator, sometimes a thousands separator etc etc. you may be able to get it to work for your culture, but then it would fail for others - at some point you need to limit what the user can do with some conventions.
Is 3,142 'a number less than 4' or '3 thousand 1 hundred and forty two' or 'no number at all'?
Different cultures will treat it differently, so what should a general program do when the user enters this?
Also, comparing strings with < or > in this way inside an if statement is not a good idea even if a lexical comparison were available.
For example the second textbox will be named by SmallBasic TextBox2 and the 10th TextBox10. Lexically TextBox10 < TextBox2. All sorts of potential problems doing this (in any language).
- Edited by litdev Monday, June 17, 2013 6:59 PM
Monday, June 17, 2013 5:53 PM -
If you are still interested, I added 2 new commands LDUtilities.GetCurrentCultureNumber and LDUtilities.GetCultureInvariantNumber
With these and some understanding, appropriate conversion is possible. My test code HNG364.
To use, you should certainly read up on how MS handles cultures - also essential if you are to do this in VS C# or VB.
Some ideas about how SB (and other programs do this)
1] Internally everything is in invariant culture e.g. 3.14.
2] Output is converted to current culture e.g. 3,14.
3] Input from textboxes for example (usually entered with current culture, but it is not converted to invariant culture). This is the problem that the method GetCultureInvariantNumber solves, converting to invariant culture number that can do arithmetic.
Just like you can't write a SB program with:
value = 3,14
It must be:
value = 3.14
When input is made in a textbox it needs to be converted to 3.14 (invariant culture) before it is treated as a number.
If this doesn't make sense then some reading on cultures in MS or just ignore.
Monday, June 17, 2013 8:12 PM -
I will write 2 subroutines:
1. ConvertComma2Point sample: 10.341,25 --> 10,341.25
1) change , to ;
2) change . to ,
3) change ; to .2. ConvertPoint2Comma sample: 10,341.25 --> 10.341,25
1) change . to ;
2) change , to .
3) change ; to ,In program define the notation and if it necessary the program convert it. This is my way to do it. Please write a change command for text like this:
LDTextChange(Text, A, B) --> Change all A to B in Text
Sample: Text = "Abcdefgabcdefg"
A = "f"
B = "t"After LDTextChang Text is: "Abcdetgabcdetg"
I can write it in SB but then it is to slow :-).Best Regards Martin
Tuesday, June 18, 2013 1:35 PM -
The culture conversion routines should handle these conversions and is the right way to do it, once it is clear what SB is doing (some testing to see this and reading up on culture handling in MS will be needed).
I wrote a regex (loads on the web about it) extension - but again this will be relatively advanced and users will need to form proper regex expression strings to use.
LDUtilities.RegexMatch and LDUtilities.RegexReplace
input = "my test text to test 3.14 12,65" match = LDUtilities.RegexMatch(input,"test","True") matchIndex = Array.GetAllIndices(match) For i = 1 To Array.GetItemCount(matchIndex) j = matchIndex[i] TextWindow.WriteLine(match[j]+" at "+j) EndFor replace = LDUtilities.RegexReplace(input,"Test","HELP","False") TextWindow.WriteLine(replace) replace = LDUtilities.RegexReplace(input,",",".","True") TextWindow.WriteLine(replace) replace = LDUtilities.RegexReplace(input,"\.",",","True") TextWindow.WriteLine(replace)
- Edited by litdev Tuesday, June 18, 2013 9:51 PM
Tuesday, June 18, 2013 6:22 PM -
show TGM788. It is possible to set a point/comma by numbers over 1000/1000000 (1.000/1.000,000 or 1,000/1,000,000 and so on?
Extention with a format coment?
Best Regards Martin
Wednesday, June 19, 2013 4:59 PM