Source language: Translate to:

ListBoxMoveItem and Save problem

General questions about NeoAppBuilder - our rapid application development tool for building HTML5, web and mobile apps.

Moderator: Neosoft Support

ListBoxMoveItem and Save problem

Postby StarterPack » Thu Nov 17, 2016 5:45 am

Hi guys. Im struggling here. When i load a text file in ListBox example.
1
2
3
4
and use the ListBoxMoveItem command to move 1 to forth place and 4 to first place. When i save the ListBox to file, it still save it as
1
2
3
4
and not
4
2
3
1
any help please
StarterPack
 
Posts: 115
Joined: Fri Feb 19, 2016 6:55 am

Re: ListBoxMoveItem and Save problem

Postby Gaev » Thu Nov 17, 2016 8:58 am

StarterPack:

I have not had the time to verify what you are experiencing ... but you might try a different way of saving ...
Code: Select all
ListBoxSize "ListBox1" "[Count]"

FileErase "yourItemsSavedFile.dat"

Loop "1" "[Count]" "[ThisItem]"
   ListBoxGetItem "ListBox1" "[ThisItem]" "[Result]"
   FileWrite "yourItemsSavedFile.dat" "Append" "[Result]"
EndLoop
User avatar
Gaev
 
Posts: 3728
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: ListBoxMoveItem and Save problem

Postby StarterPack » Thu Nov 17, 2016 11:34 am

Hi gaev. Thanks for your reply, but this does not work for me. Im typing from my cellphone so i cant put the script here. But what i want to do is when i read any text file into a listbox. I had a button to move the selected item in the listbox up or down. Now i want to save the complete listbox again. I read the text file into listbox, then use the ListboxMove command and write the complete listbox again. But it wont work
StarterPack
 
Posts: 115
Joined: Fri Feb 19, 2016 6:55 am

Re: ListBoxMoveItem and Save problem

Postby Gaev » Thu Nov 17, 2016 3:28 pm

StarterPack:

but this does not work for me

What does not work for you ? ... the script I supplied ? ... or something else ?

what i want to do is when i read any text file into a listbox. I had a button to move the selected item in the listbox up or down. Now i want to save the complete listbox again. I read the text file into listbox, then use the ListboxMove command and write the complete listbox again. But it wont work

I am assuming that you ...

- defined a variable to be used for ListItems
- have FileRead into this variable
- FileWrite from this variable

... if so, it won't work ... because the "Variable-ListItems" relationship is "one way only" i.e. the box displays the contents of the Variable .. but when you change the content/order of the ListItems, this is not reflected back in the Variable ... so you can not just do a FileWrite of the contents of the Variable ... you have to "fetch the contents of each item separately" and save to your file.

Im typing from my cellphone so i cant put the script here.

If you are doing something different from what I described above, post your script ... otherwise, use the script I supplied (for saving the new set of ListItems one at a time).

P.S. You posted this in the wrong Forum ... this one is reserved for the NeoApp product (not NeoBook) ... perhaps Dave can move it later.
User avatar
Gaev
 
Posts: 3728
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: ListBoxMoveItem and Save problem

Postby StarterPack » Thu Nov 17, 2016 10:20 pm

Hi gaev, Ok here are the script and what i'm trying to do.

First i read a text file into ListBox
FileRead "[PubDir]NameList.txt" "All" "[ListBox]"

Pete
John
Dave
Josh

Now i click on a name in the ListBox and use a up or down button to move the selected name up or down

This is my ListBox properties in "Selection Changed" when i click on a name
ListBoxFindItem "ListBox1" "[ListBox1]" "[Count]"

(Up Button)
ListBoxMoveItem "ListBox1" "[Count]" "[Count]-1"
Math "[Count]-1" "" "[Count]"
If "[Count]" "<=" "1"
SetVar "[Count]" "1"

(Down Button)
ListBoxMoveItem "ListBox1" "[Count]" "[Count]+1"
Math "[Count]+1" "" "[Count]"

Now lets say i move the names and it looks like this now

Dave
John
Josh
Pete

Now i save the ListBox

FileWrite "[PubDir][NameList].txt" "All" "[ListBox]"
SetVar "[ListBox]" ""
FileRead "[PubDir]NameList.txt" "All" "[ListBox]"

It does'nt save the ListBox with new Name order.
StarterPack
 
Posts: 115
Joined: Fri Feb 19, 2016 6:55 am

Re: ListBoxMoveItem and Save problem

Postby Gaev » Fri Nov 18, 2016 5:49 am

StarterPack:
Now i save the ListBox

FileWrite "[PubDir][NameList].txt" "All" "[ListBox]"
SetVar "[ListBox]" ""
FileRead "[PubDir]NameList.txt" "All" "[ListBox]"

It does'nt save the ListBox with new Name order.

As I mentioned in my previous post ...
it won't work ... because the "Variable-ListItems" relationship is "one way only" i.e. the box displays the contents of the Variable .. but when you change the content/order of the ListItems, this is not reflected back in the Variable ... so you can not just do a FileWrite of the contents of the Variable ... you have to "fetch the contents of each item separately" and save to your file.
User avatar
Gaev
 
Posts: 3728
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: ListBoxMoveItem and Save problem

Postby StarterPack » Fri Nov 18, 2016 7:51 am

Hi gaev
Ok i understand.. thank you so much
StarterPack
 
Posts: 115
Joined: Fri Feb 19, 2016 6:55 am

Re: ListBoxMoveItem and Save problem

Postby dpayer » Fri Nov 18, 2016 3:16 pm

StarterPack wrote:Hi gaev
Ok i understand.. thank you so much


Take a look at a Listbox function I created. It synchronizes the variable used to set the initial listbox contents with any additions / changes that are made to the list.

viewtopic.php?f=22&t=21587

It may be helpful.
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1382
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: ListBoxMoveItem and Save problem

Postby StarterPack » Sat Nov 19, 2016 2:26 am

Gaev! I love you man!!!! Works perfectly now
And Thank You dpayer.. i'll look at it
StarterPack
 
Posts: 115
Joined: Fri Feb 19, 2016 6:55 am


Return to General NeoAppBuilder Discussion

Who is online

Users browsing this forum: No registered users and 0 guests

cron