J joaomelo Member Licensed User Longtime User Mar 24, 2012 #1 Hello, I am writing an app that has 3 editext, I want to call a calculator (tapecalc) from a menu button and bring the result from the calculator to the edittext that was with the focus when the calculator menu button was clicked. I'm doing this but is not working. Code: Copy Sub Globals Dim txtN As EditText Dim txtD As EditText Dim txtI As EditText Dim Send As EditText End Sub Sub Activity_Create(FirstTime As Boolean) txtN.Initialize("edText") txtD.Initialize("edText") txtI.Initialize("edText") ' txtN.RequestFocus End Sub Sub Activity_Resume 'Msgbox(TapeCalc.Resultado,"Resultado") If Sender = Null Then Msgbox("Nulo","Sender") Else Msgbox(Send,"Sender") Send.Text = TapeCalc.Resultado End If End Sub Sub edText_FocusChanged (HasFocus As Boolean) Send = Sender End Sub Resultado is declared in Sub Process_Globals from tapecalc activity. What am I doing wrong ? Thanks.
Hello, I am writing an app that has 3 editext, I want to call a calculator (tapecalc) from a menu button and bring the result from the calculator to the edittext that was with the focus when the calculator menu button was clicked. I'm doing this but is not working. Code: Copy Sub Globals Dim txtN As EditText Dim txtD As EditText Dim txtI As EditText Dim Send As EditText End Sub Sub Activity_Create(FirstTime As Boolean) txtN.Initialize("edText") txtD.Initialize("edText") txtI.Initialize("edText") ' txtN.RequestFocus End Sub Sub Activity_Resume 'Msgbox(TapeCalc.Resultado,"Resultado") If Sender = Null Then Msgbox("Nulo","Sender") Else Msgbox(Send,"Sender") Send.Text = TapeCalc.Resultado End If End Sub Sub edText_FocusChanged (HasFocus As Boolean) Send = Sender End Sub Resultado is declared in Sub Process_Globals from tapecalc activity. What am I doing wrong ? Thanks.
P Penko Active Member Licensed User Longtime User Mar 24, 2012 #2 Just write a function for the calculator. Let's assume the calculater is a function in a Code Module: CodeModule Calculator: Code: Copy Sub calc(a as int, b as int, c as int) Return a * 2 / b + c End Sub In your Activity, just call the function: Dim result as int : result = Calculator.code(1,2,3) ' or here you can use your variables EditText1.Text = result Se non ho capito vero, scrivi piu information di cosa vuoi fare. In case I haven't understood, write more information about what you want to achieve. Upvote 0
Just write a function for the calculator. Let's assume the calculater is a function in a Code Module: CodeModule Calculator: Code: Copy Sub calc(a as int, b as int, c as int) Return a * 2 / b + c End Sub In your Activity, just call the function: Dim result as int : result = Calculator.code(1,2,3) ' or here you can use your variables EditText1.Text = result Se non ho capito vero, scrivi piu information di cosa vuoi fare. In case I haven't understood, write more information about what you want to achieve.
J joaomelo Member Licensed User Longtime User Mar 24, 2012 #3 The calculator is an activity that is called form a menu button (see "Tape Calc" in the "Basic4android Share Your Creations" forum). I can call it and the result is back in the main activity, I only can't put it in the text property of the edittext that was with focus when the calculator was called. Upvote 0
The calculator is an activity that is called form a menu button (see "Tape Calc" in the "Basic4android Share Your Creations" forum). I can call it and the result is back in the main activity, I only can't put it in the text property of the edittext that was with focus when the calculator was called.
thedesolatesoul Expert Licensed User Longtime User Mar 24, 2012 #4 In activity resume, you are checking for sender instead of send to be null. Sent from my GT-I9000 using Tapatalk Upvote 0
In activity resume, you are checking for sender instead of send to be null. Sent from my GT-I9000 using Tapatalk
J joaomelo Member Licensed User Longtime User Mar 24, 2012 #5 I need to test sender because in the first time this acticvity is opened the sender is null and send too. If I don't do this I receive an error message. Upvote 0
I need to test sender because in the first time this acticvity is opened the sender is null and send too. If I don't do this I receive an error message.
thedesolatesoul Expert Licensed User Longtime User Mar 24, 2012 #6 You can check send.isinitialized instead. Sent from my GT-I9000 using Tapatalk Upvote 0
J joaomelo Member Licensed User Longtime User Mar 25, 2012 #7 The msgbox in the activity_resumo shows the picture attached and the edittext shows nothing. Attachments Erro.png 31.6 KB · Views: 384 Upvote 0
klaus Expert Licensed User Longtime User Mar 25, 2012 #8 Try something liks this: Code: Copy Sub Process_Globals Dim edtIndex As Int : edtIndex = -1 End Sub Sub Globals Dim edText(3) As EditText End Sub Sub Activity_Create(FirstTime As Boolean) For i = 0 To 2 edText(i).Initialize("edText") edText(i).Tag = i Next edText(0).RequestFocus End Sub Sub Activity_Resume If edtIndex < 0 Then edText(edtIndex).Text = "" Else edText(edtIndex).Text = TapeCalc.Resultado End If End Sub Sub edText_FocusChanged (HasFocus As Boolean) Dim Send As EditText Send = Sender edtIndex = Send.Tag End Sub Best regards. Upvote 0
Try something liks this: Code: Copy Sub Process_Globals Dim edtIndex As Int : edtIndex = -1 End Sub Sub Globals Dim edText(3) As EditText End Sub Sub Activity_Create(FirstTime As Boolean) For i = 0 To 2 edText(i).Initialize("edText") edText(i).Tag = i Next edText(0).RequestFocus End Sub Sub Activity_Resume If edtIndex < 0 Then edText(edtIndex).Text = "" Else edText(edtIndex).Text = TapeCalc.Resultado End If End Sub Sub edText_FocusChanged (HasFocus As Boolean) Dim Send As EditText Send = Sender edtIndex = Send.Tag End Sub Best regards.
J joaomelo Member Licensed User Longtime User Mar 30, 2012 #9 Thanks, it's solved with your help. The tag was the solution. Sent from my GT-P1000L using Tapatalk Upvote 0