J James_Last New Member Licensed User Longtime User Feb 22, 2015 #1 Hello A newbie problem here I'm sure. In the code below, the line "EEText.Text=n" will crash the app despite n being as expected. How can I modify the contents of an EditText box with the value of n, in this example a number padded with leading zeroes, as each numerical character is entered by the user please? Code: Copy Sub EEText_TextChanged (Old As String, New As String) Dim n As String If New.Length >0 Then n=NumberFormat2(EEText.text, 10, 0,0, False) ' pad with leading zeroes, min str length=10 EEText.Text=n Log(n) End If End Sub many thanks
Hello A newbie problem here I'm sure. In the code below, the line "EEText.Text=n" will crash the app despite n being as expected. How can I modify the contents of an EditText box with the value of n, in this example a number padded with leading zeroes, as each numerical character is entered by the user please? Code: Copy Sub EEText_TextChanged (Old As String, New As String) Dim n As String If New.Length >0 Then n=NumberFormat2(EEText.text, 10, 0,0, False) ' pad with leading zeroes, min str length=10 EEText.Text=n Log(n) End If End Sub many thanks
Erel B4X founder Staff member Licensed User Longtime User Feb 23, 2015 #3 Please post the error message from the logs. Upvote 0
warwound Expert Licensed User Longtime User Feb 23, 2015 #4 Are you creating an infinite loop? Try this: Code: Copy Sub EEText_TextChanged (Old As String, New As String) Dim n As String If New.Length >0 Then n=NumberFormat2(EEText.text, 10, 0,0, False) ' pad with leading zeroes, min str length=10 If EEText.Text<>n Then EEText.Text=n End If Log(n) End If End Sub Upvote 0
Are you creating an infinite loop? Try this: Code: Copy Sub EEText_TextChanged (Old As String, New As String) Dim n As String If New.Length >0 Then n=NumberFormat2(EEText.text, 10, 0,0, False) ' pad with leading zeroes, min str length=10 If EEText.Text<>n Then EEText.Text=n End If Log(n) End If End Sub
J James_Last New Member Licensed User Longtime User Feb 23, 2015 #5 warwound said: Are you creating an infinite loop? Try this: Code: Copy Sub EEText_TextChanged (Old As String, New As String) Dim n As String If New.Length >0 Then n=NumberFormat2(EEText.text, 10, 0,0, False) ' pad with leading zeroes, min str length=10 If EEText.Text<>n Then EEText.Text=n End If Log(n) End If End Sub Click to expand... Thanks all for your support! I agree the problem must be due to an infinite loop, thank you warwound. I implemented the above code changes and it's just fine! I did need to add an extra line of code to put the cursor at the end of the 'updated' zero-padded string though else more char entries would add to the left e.g., "6000000005" instead of "0000000056" Code: Copy If EEText.Text<>n Then ' avoids an infinite loop! EEText.Text=n EEText.SelectionStart=EEText.Text.Length End If I do have one more problem that I would like to resolve if anyone can chip in please? I tried setting a limit on the max chars allowed in EEText Edit box to 10, i.e., : Code: Copy ' EE Number field.. p.SetLengthFilter (EEText, 10) 'max 10-digits allowed (assume "EE" prefix ignored) The first entered char is understandably displayed correctly as "0000000005" (for example), but then I've filled up all 10 chars to the limit and no further entries are accepted Upvote 0
warwound said: Are you creating an infinite loop? Try this: Code: Copy Sub EEText_TextChanged (Old As String, New As String) Dim n As String If New.Length >0 Then n=NumberFormat2(EEText.text, 10, 0,0, False) ' pad with leading zeroes, min str length=10 If EEText.Text<>n Then EEText.Text=n End If Log(n) End If End Sub Click to expand... Thanks all for your support! I agree the problem must be due to an infinite loop, thank you warwound. I implemented the above code changes and it's just fine! I did need to add an extra line of code to put the cursor at the end of the 'updated' zero-padded string though else more char entries would add to the left e.g., "6000000005" instead of "0000000056" Code: Copy If EEText.Text<>n Then ' avoids an infinite loop! EEText.Text=n EEText.SelectionStart=EEText.Text.Length End If I do have one more problem that I would like to resolve if anyone can chip in please? I tried setting a limit on the max chars allowed in EEText Edit box to 10, i.e., : Code: Copy ' EE Number field.. p.SetLengthFilter (EEText, 10) 'max 10-digits allowed (assume "EE" prefix ignored) The first entered char is understandably displayed correctly as "0000000005" (for example), but then I've filled up all 10 chars to the limit and no further entries are accepted