none
Need a soultion/another way RRS feed

  • Question

  • Hello everyone,

    I need a soultion. I wrote the following code:

    Sub TBInput
      TypedTB = Controls.LastTypedTextBox
      TypedText = GraphicsWindow.LastKey  
      
      If TypedText = "D0" Then
        a = "0"
        Controls.SetTextBoxText(TypedTB, Text.Append(TBText[TypedTB], a))
      ElseIf TypedText = "D1" Then
        a = "1"
        Controls.SetTextBoxText(TypedTB, Text.Append(TBText[TypedTB], a))
      ElseIf TypedText = "OemComma" Then
        a = ","
        Controls.SetTextBoxText(TypedTB, Text.Append(TBText[TypedTB], a))
      ElseIf TypedText = "OemPeriod" Then
        a = "."
        Controls.SetTextBoxText(TypedTB, Text.Append(TBText[TypedTB], a))
      Else
        Controls.SetTextBoxText(TypedTB, TBText[TypedTB])
      EndIf
      TBText[TypedTB] = Controls.GetTextBoxText(TypedTB)
    EndSub

    On this way keys like the delete key will be ignored. I don't want this.

    Next, everytime I write a , or . the next entrys will be placed at the start of the textbox. But I want that the user ca decide where to place the entry. Like in every normal textbox.

    Any solution? I have no ideas at the moment.


    Mit freundlichen Grüßen Timo Greetings Timo

    Saturday, September 28, 2013 9:07 PM

Answers

  • i have all available extensions in lib folder and checking them for an 'End'-key function.

    Edit:

    LDControls.SetCursorToEnd   !!

    Set the cursor caret to the end of a textbox.

    see: WTD906  or final WTT869.



    Sunday, September 29, 2013 9:56 PM
    Answerer
  • I'm stumped.

    I'm not sure how to put the cursor at end of the text instead of having it jump back to the beginning like you mentioned above. I'll do some research...

    MyTextBox=Controls.AddTextBox(0,0)
    Controls.TextTyped = OnDataEntry
    
    Sub OnDataEntry
      TextBoxText = Controls.GetTextBoxText(MyTextBox)
      Length = Text.GetLength(TextBoxText)
      LastCharacterTyped = Text.GetSubText(TextBoxText,Length,1)
      
      If (LastCharacterTyped = "0" Or LastCharacterTyped = "1" or LastCharacterTyped = ","or LastCharacterTyped = ".") Then
        Controls.SetTextBoxText(MyTextBox,TextBoxText)
      Else
         T = Text.GetSubText(TextBoxText,1,length-1)
        Controls.SetTextBoxText(MyTextBox,T) 
      EndIf 
      
    EndSub

    Sunday, September 29, 2013 8:44 PM
  • How about this?  But input error lets cursor go back to the left of the text.

    Main()
    Sub Main
      GraphicsWindow.BackgroundColor = "Gray"
      GraphicsWindow.BrushColor = "Black"
      Controls.AddTextBox(10, 10)
      Controls.TextTyped = TBInput
    EndSub  
    Sub TBInput
      TypedTB = Controls.LastTypedTextBox
      TypedText = Controls.GetTextBoxText(TypedTB)
      len = Text.GetLength(TypedText)
      valid = ""
      For i = 1 To len
        c = Text.GetSubText(TypedText, i, 1)
        If Text.IsSubText("01,.", c) Then
          valid = Text.Append(valid, c)
        EndIF
      EndFor
      If TypedText = valid Then
        TBText[TypedTB] = TypedText
      Else
        Sound.PlayClick()
        TBText[TypedTB] = valid
        Controls.SetTextBoxText(TypedTB, valid)
      EndIf
    EndSub
      


    Nonki Takahashi

    • Marked as answer by Timo Sö Thursday, October 3, 2013 9:30 AM
    Tuesday, October 1, 2013 1:21 PM
    Moderator

All replies

  • Hallo Timo,

    also wenn ich Dich richtig verstehe, willst eh bloß eine normale Textbox als ganzes auslesen. Am einfachsten einfach nach dem Schreiben per Button den gesamten Text (incl. ev. Änderungen , . oder 'Entf'  egal was dann auch drinnensteht) auslesen  MDL536

    Saturday, September 28, 2013 11:05 PM
    Answerer
  • You did not understand me right. I want to read out a textbox, but that's note in the code.

    I want that the user can only write 0 1 , . in to the textbox. Nothing else.


    Mit freundlichen Grüßen Timo Greetings Timo

    Sunday, September 29, 2013 3:37 PM
  • Hello Timo,

    If the goal is to restrict the data that can be entered to 0 1 , . and nothing else, then one solution could be to test the data that was typed into the textbox instead of looking at what typed at the keyboard. Try modifying your code so that TypedText holds the data that was typed into the textbox.

    Once TypedText holds the data that was typed into the textbox you can then evaluate the TypedText variable to see if what was typed is a 0 1 , or .

    Hope that helps.

    -Anthony

    Sunday, September 29, 2013 5:33 PM
  • Hello Anthony,

    that is exactly what I want to do. And I tried this, too.

    But it doesn't work for me, so I tried it with the keyboard.

    I would be very grateful if you give me a working example of this.

    Thanks in advance.


    Mit freundlichen Grüßen Timo Greetings Timo

    Sunday, September 29, 2013 6:39 PM
  • I'm stumped.

    I'm not sure how to put the cursor at end of the text instead of having it jump back to the beginning like you mentioned above. I'll do some research...

    MyTextBox=Controls.AddTextBox(0,0)
    Controls.TextTyped = OnDataEntry
    
    Sub OnDataEntry
      TextBoxText = Controls.GetTextBoxText(MyTextBox)
      Length = Text.GetLength(TextBoxText)
      LastCharacterTyped = Text.GetSubText(TextBoxText,Length,1)
      
      If (LastCharacterTyped = "0" Or LastCharacterTyped = "1" or LastCharacterTyped = ","or LastCharacterTyped = ".") Then
        Controls.SetTextBoxText(MyTextBox,TextBoxText)
      Else
         T = Text.GetSubText(TextBoxText,1,length-1)
        Controls.SetTextBoxText(MyTextBox,T) 
      EndIf 
      
    EndSub

    Sunday, September 29, 2013 8:44 PM
  • Same prob here (DPW569)

    Whenever a wrong char is typed, cursor jumps to 1st position.

    would need to add  ..+Text.GetCharacter(EOL)

    EOL.. goto EndOfLine  ?? (is there an ascii code)

    Sunday, September 29, 2013 9:03 PM
    Answerer
  • I did a quick search through the Small Basic forum and this functionality was asked about a few times. However, it looks like the textbox control doesn't allow the placement of the cursor. Have you tried checking to see if there's an extension that provides this functionality? I believe the Small Basic extensions can be found here: http://blogs.msdn.com/b/smallbasic/archive/2012/10/12/small-basic-extensions-gallery.aspx

    Sorry I couldn't be of more help.

    Sunday, September 29, 2013 9:41 PM
  • i have all available extensions in lib folder and checking them for an 'End'-key function.

    Edit:

    LDControls.SetCursorToEnd   !!

    Set the cursor caret to the end of a textbox.

    see: WTD906  or final WTT869.



    Sunday, September 29, 2013 9:56 PM
    Answerer
  • Thanks for your replies.

    I will try the option in litdev's extension. But I would prefer to use none extension.


    Mit freundlichen Grüßen Timo Greetings Timo

    Monday, September 30, 2013 3:13 PM
  • How about this?  But input error lets cursor go back to the left of the text.

    Main()
    Sub Main
      GraphicsWindow.BackgroundColor = "Gray"
      GraphicsWindow.BrushColor = "Black"
      Controls.AddTextBox(10, 10)
      Controls.TextTyped = TBInput
    EndSub  
    Sub TBInput
      TypedTB = Controls.LastTypedTextBox
      TypedText = Controls.GetTextBoxText(TypedTB)
      len = Text.GetLength(TypedText)
      valid = ""
      For i = 1 To len
        c = Text.GetSubText(TypedText, i, 1)
        If Text.IsSubText("01,.", c) Then
          valid = Text.Append(valid, c)
        EndIF
      EndFor
      If TypedText = valid Then
        TBText[TypedTB] = TypedText
      Else
        Sound.PlayClick()
        TBText[TypedTB] = valid
        Controls.SetTextBoxText(TypedTB, valid)
      EndIf
    EndSub
      


    Nonki Takahashi

    • Marked as answer by Timo Sö Thursday, October 3, 2013 9:30 AM
    Tuesday, October 1, 2013 1:21 PM
    Moderator
  • Thanks Nonki!

    That's what I needed.

    For the cursour I will use litdev's extension than. So everything is fine.


    Mit freundlichen Grüßen Timo Greetings Timo


    • Edited by Timo Sö Thursday, October 3, 2013 9:31 AM
    Thursday, October 3, 2013 9:30 AM