How permanently save a text written in an EditText and added in a ListBox?

As written in the title, how permanently save a text written in an EditText and added in a ListBox? (when I reopen the rollout, the text written before is present in the listbox)

Below is my example:

-----------------------------------------------------------------

rollout t "test"
(
	listbox l1 "" items:#()
	edittext ed1 "" 
	button b "Insert Name in ListBox"
	button s "Save Text in Listbox"
 
 
	on b pressed do
	(
		if txt != "" do 
 
(
l1.items = append l1.items (ed1.text as string)
l1.selection = l1.items.count
ed1.text = ""
)
 
)
 
on s pressed do
(
-- How save the text???	
)
 
 
)
createdialog t

------------------------------------------------------------

Waiting for help, a greeting from
Michele

Question off topic:
how to write script code in discussions?

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Graph's picture

the classOf val you want is

the classOf val you want is array not integer or items

..  do val = execute val ;  ..

--sleep helps ;)

Raphael Steves

Michele71's picture

Thanks Insanto. The link

Thanks Insanto. The link works and I have already done tests. I have added:

ListBoxControl : (functions.sIs RO.name i.name i.items) -- and
 
ListBoxControl :(local val = functions.gIs RO.name i.name ; if val != undefined AND classOf val == String do val = execute val if classOf val == items OR classOf val == integer do i.items = val)

But dont work. I've been careful to the initial instructions. The problem is append word written EditText as array in items listbox...I can not understand where I am wrong...

Graph's picture

? I checked the link and it

? I checked the link and it leads to the "Save/Load UIItem's values" article.

you just have to add the editText UI control to the cases (the Items's class) to make it work for your purpose
it prints the classes (of all UIItems of the supplied RO) when the RO is closed; to the listener

in case the link doesnt work for you heres the code:

(
	/*
		automated loading and saving of UISettings for a complete Rollout
		make sure to not rename your rollout and/or UIItems between dev versions or the settings wont transfer
		simply include the struct and its local var in the header of your index scriptFile
 
		use the functions as demonstrated in the rolllout-example
	*/
 
	local functions
	struct temp 
	(
		val = 0 --dont change
		,
		gIs = fn gIs Category Key File:"Settings" =  
		(
 
			local type, val, key1
 
			registry.createKey HKEY_CURRENT_USER ("Software\\ROSettings\\"+File as string + "\\" + Category as string) accessRights:#all newKeyCreated:&newKeyCreated key:&key1
 
			registry.queryValue key1 (Key as string) type:&type value:&val
 
			val
		)--END gIs FN
		,
		sIs = fn sIs Category Key Val File:"Settings" del:false = 
		(
			try
			(
				local newKeyCreated , key1
 
				registry.createKey HKEY_CURRENT_USER ("Software\\ROSettings\\"+File as string + "\\" + Category as string) accessRights:#all newKeyCreated:&newKeyCreated key:&key1
 
				if not del then
				(
					registry.setvalue key1 (Key as string) #REG_SZ (Val as string)
				)
				else
				(
					registry.deleteKey key1
				)
			)
			catch
			(	
				print (registry.getLastError())	
			)
		)--END sIs FN
		,
		saveROSettings = fn saveROSettings RO =
		(
			local items = RO.controls
 
			for i in items do
			(
				print (classOf i)  --uncommend to find out the classes of the UI items
 
				case classOf i of
				(
					SpinnerControl : (functions.sIs RO.name i.name i.value)
 
					ColorPickerControl : (functions.sIs RO.name i.name i.color)
 
					CheckBoxControl : (functions.sIs RO.name i.name i.checked)
 
					CheckButtonControl : (functions.sIs RO.name i.name i.checked)
 
					RadioControl : (functions.sIs RO.name i.name i.state)
 
				)--END classes cases
			)--END items loop
		)--END saveROSettings FN
		,
		getROSettings = fn getROSettings RO =
		(
			local items = RO.controls
 
			for i in items do
			(
				case classOf i of
				(
					SpinnerControl : 
					(
						local val = functions.gIs RO.name i.name ; if val != undefined AND classOf val == String do val = execute val
						if classOf val == float OR classOf val == integer do i.value = val
					)
 
					ColorPickerControl : 
					(
						local val = functions.gIs RO.name i.name ; if val != undefined AND classOf val == String do val = execute val
						if classOf val == color do i.color = val
					)
 
					CheckBoxControl : 
					(
						local val = functions.gIs RO.name i.name ; if val != undefined AND classOf val == String do val = execute val
						if classOf val == BooleanClass do i.checked = val
					)
 
					CheckButtonControl : 
					(
						local val = functions.gIs RO.name i.name ; if val != undefined AND classOf val == String do val = execute val
						if classOf val == BooleanClass do i.checked = val
					)					
 
					RadioControl : 
					(
						local val = functions.gIs RO.name i.name ; if val != undefined AND classOf val == String do val = execute val
						if classOf val == float OR classOf val == integer  do i.state = val
					)					
 
				)--END classes cases
			)--END items loop
		)--END getROSettings FN
	)
	functions = temp val:1
 
	rollout testRO ""
	(
 		spinner spinner1
 
 		colorPicker colorpck1
 
		checkBox checkbox1 "what?"
 
		checkbutton checkbutton1 "check this"
 
		radiobuttons radioButtons1 "choices" labels:#("btn1", "btn2")
 
 
		on testRO open do
		(
			functions.getROSettings testRO
		)
 
		on testRO close do
		(
			functions.saveROSettings testRO
		)
 
	)--END RO
 
	createdialog testRO
 
)

Raphael Steves

Michele71's picture

Be a coincidence, but today I

Be a coincidence, but today I was looking at your great site congratulations ;)
And thank you for the answers that you gave me. Now check your link!

Very thanks Insanto!!! :) :)

Graph's picture

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.