B4J Question Having a problem, getting the text from a text area

B4JExplorer

Active Member
Licensed User
Longtime User
Hi,

I'm appending lines of text to a textarea, but am having problems getting the current value, in order to append each line to the current contents.

SetVal is working fine below. But f_Area doesn't want to want to expose its text value, to s_Result. s_Result is always blank:



Dim s_Result As String = ""
Dim f_Area As Future = ta_Area.GetVal
...
...


ta_Area.SetVal( "0" )
s_Result = f_Area.Value

ta_area.SetVal( s_Result & Chr( 13 ) & Chr( 10 ) & "1" )
s_Result = f_Area.Value

ta_area.SetVal( s_Result & Chr( 13 ) & Chr( 10 ) & "2" )
s_Result = f_Area.Value

ta_area.SetVal( s_Result & Chr( 13 ) & Chr( 10 ) & "3" )
s_Result = f_Area.Value
 

billzhan

Active Member
Licensed User
Longtime User
I think s_Result = f_Area.Value will work only one time(the first time)in an event.

try
B4X:
Sub youreventname_event (Params As Map)

    Dim s_Result As String = ""
    Dim f_Area As Future = ta_Area.GetVal
    ...
    ...


    ta_Area.SetVal( "0" )
    s_Result = f_Area.Value     'only this one works
    log("1 "&s_Result)

    ta_area.SetVal( s_Result & Chr( 13 ) & Chr( 10 ) & "1" )
    s_Result = f_Area.Value
    log("2 "&s_Result)

    ta_area.SetVal( s_Result & Chr( 13 ) & Chr( 10 ) & "2" )
    s_Result = f_Area.Value
    log("3 "&s_Result)

    ta_area.SetVal( s_Result & Chr( 13 ) & Chr( 10 ) & "3" )
    s_Result = f_Area.Value
    log("4 "&s_Result)

End sub
 
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
Negative on the s_result. Empty in all instances, of f_Area.Value:




B4X:
	ta_Area.SetVal( "0" )
	s_Result = f_Area.Value
	
	Main.AppLog( "Result should be 0: " & s_Result )
	
	
	ta_Area.SetVal( s_Result & Chr( 13 ) & Chr( 10 ) & "1" )
	s_Result = f_Area.Value

	Main.AppLog( "Result should be 1: " & s_Result )

	
	s_Result = ta_Area.GetVal
	
	Main.AppLog( "Result should be 1: " & s_Result )
	
	
	ta_Area.SetVal( s_Result & Chr( 13 ) & Chr( 10 ) & "2" )
	s_Result = f_Area.Value

	Main.AppLog( "Result should be 2: " & s_Result )

	
	s_Result = ta_Area.GetVal

	Main.AppLog( "Result should be 2: " & s_Result )

	
	ta_Area.SetVal( s_Result & Chr( 13 ) & Chr( 10 ) & "3" )
	s_Result = ta_Area.GetVal
	
	
	Main.AppLog( "Result should be 3: " & s_Result )


10/02/2014 20:07:59:Result should be 0:
10/02/2014 20:07:59:Result should be 1:
10/02/2014 20:07:59:Result should be 1: anywheresoftware.b4j.object.WebSocket$SimpleFuture@47fb58c9
10/02/2014 20:07:59:Result should be 2:
10/02/2014 20:07:59:Result should be 2: anywheresoftware.b4j.object.WebSocket$SimpleFuture@4682190a
10/02/2014 20:07:59:Result should be 3: anywheresoftware.b4j.object.WebSocket$SimpleFuture@73a03b0
 
Last edited:
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
The .Value content of the Future variable, seems to be empty, only towards the end of the event.

I think I need to just play with this a bit. Thanks for the tips.
 
Last edited:
Upvote 0

billzhan

Active Member
Licensed User
Longtime User
I guess it's not right to use .getval after .SetVal in an event, as setVal(newValue) will clear JQueryElement attributes(val), and the newValue will not be updated before this end of event(ws response to browser and then the newValue will be set for JQueryElement ).
 

Attachments

  • c.PNG
    14.3 KB · Views: 202
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
Got it. The code needs to re-assign the Future variable f_Area to ta_Area.GetVal, each time the textarea changes content, before getting its value.

The confusion comes from the original Dim

Dim f_Area As Future = ta_Area.GetVal

I prefer to make only empty default assignments or just e.g. ,

Dim f_Area As Future

during a Dim, and make the actual assignments separately in the code. That's clear enough.

But I had cloned the Dim from another poster, and just forget about re-assigning the variable.


Long story short - my mistake, thanks for taking a look.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…