"Online" monitored TextBox

Standa

Member
Licensed User
Longtime User
Hi,
I have wrote unit converter application. For starting calculate with value typed in textbox I use button control. But I want my program will calculate value immediately as I type it to textbox. Problem is, that KeyPress event at first does action programmed in KeyPress sub, and after it writes value I typed on SIP to textbox.

For example:
B4X:
Sub TextBox1_KeyPress (key)
 TextBox2.Text=TextBox1.Text
End Sub

I try to handling it with Asc(key) etc., but it is more difficult than calculating of convert himself :). I know other ways how to do it, but I want use TextBox and SIP (not own writed keyboard).
 

specci48

Well-Known Member
Licensed User
Longtime User
Hello Standa,

a possible workaround could be using a timer:
B4X:
Sub Globals
   'Declare the global variables here.
End Sub

Sub App_Start
   Timer1.Interval = 1
   Timer1.Enabled = false
   Form1.Show
End Sub

Sub TextBox1_KeyPress (key)
   Timer1.Enabled = true
End Sub

Sub Timer1_Tick
   Timer1.Enabled = false
   ' do calculation
End Sub

The KeyPress events starts the timer and within the timer the TextBox1 has already the correct value.


specci48
 

Standa

Member
Licensed User
Longtime User
Thank you guys. Door library is something like big gun against sparrow for my little application. So I try code with timer. :)
 
Top