Beijer Electronics (formerly QSI Corporation)

Manufacturer of Mobile Data and Human Machine Interface Terminals.
It is currently Sun Nov 19, 2017 3:20 am

All times are UTC - 7 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Persistent Variables
PostPosted: Fri Dec 02, 2011 11:49 am 
Offline

Joined: Thu Aug 09, 2007 4:44 pm
Posts: 67
I'm trying to save a list of global variables and arrays using PersistenVariablesV2. Upon initiating a save I am getting an "Error saving property..." error, specifying the final variable in my long "save list". Actually, it is an array I am attempting to save, but it doesn't seem matter which array is listed last. I am formatting the list as:

init savelist := "default.array1[];default.array2[];...

Is not the correct way to format a list of arrays to save?

Aaron


Top
 Profile  
 
 Post subject: Re: Persistent Variables
PostPosted: Fri Dec 02, 2011 11:58 am 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
Leave off the brackets. "default.array1;default.array2;"

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
 Post subject: Re: Persistent Variables
PostPosted: Fri Dec 02, 2011 1:54 pm 
Offline

Joined: Thu Aug 09, 2007 4:44 pm
Posts: 67
I used the following code, pulled from a similar example, to save the listed text strings in a listboxV2 object.

It seems that LBData holds the strings themselves and LBDataI holds the index of the string in the listbox

Code:
dim LBData as charstr
dim LBDataI[] as integer

'calls ListBoxToString for each list box and its global string array
'then saves the data to a file using PersistentVariables.
func SaveChanges()
    ListBoxToString(LBData, LBDataI, Saved_list)
    Save_list.Save()
endfunc
'converts listbox data into a string array
func ListBoxToString(data as reference to charstr, dataI[] as reference to integer,lb as ListBoxV2)
    dim i as integer
    dim tmpCh as charstr
    data = ""
    redim(dataI, lb.GetCount())
    'save listbox items and lengths
    for i = 0 to lb.GetCount()-1
        tmpCh = lb.GetString(i)
        'save string item
        data = data + tmpCh
        'save length
       dataI[i] = len(tmpCh)
    next
endfunc

'calls the function string to listbox to populate listboxes using the
'previously restore string arrays.
func RestoreChanges()
    StringToListBox(LBData, LBDataI, saved_list)
endfunc
'takes a string array and converts it to the listbox items
func StringToListBox(data as reference to charstr, dataI[] as reference to integer, ->
    lb as ListBoxV2)
    dim ind, i as integer
    dim tmpCh as charstr
    'remove all items from listbox
    lb.Clear()
    for i = 0 to len(dataI)-1
        'get string at index
        tmpCh = mid(data, ind, dataI[i])
        'increment to next index in string
        ind = ind + dataI[i]
        lb.AddString(tmpCh)
    next
endfunc



I want to be able to remove items from the list of saved data. I wrote this up but it doesn't seem to do anything. I guess I don't understand quite the format that the data is stored as.

Code:
func RemoveString(value as string,i as integer)
    dim pos as integer
    dim l as integer
    l=len(value)
    pos = find(LBData, 0, -1, value)
    if pos >= 0 then
        LBData = left(LBData, pos) + mid(LBData, pos+l, -1)
        LBdataI = left(LbdataI, i) + mid(LbdataI, i+1, -1)
    endif
endfunc


Top
 Profile  
 
 Post subject: Re: Persistent Variables
PostPosted: Fri Dec 02, 2011 2:55 pm 
Offline
User avatar

Joined: Thu Mar 02, 2006 2:12 pm
Posts: 487
Location: Salt Lake City, Utah
I think you just need to use the already existing _DeleteString function.

Quote:
_DeleteString
Location: Library standard source stringarray

func _DeleteString (index as integer, strings as reference to string, breakInfo[] as reference to integer)

Parameters:
index: The element to delete
strings: One of the variables which contains the string array
breakInfo: One of the variables which contains the string array



Removes the specified element from a string array. All with an index higher than the onde deleted are shifted down one index position to fill in the gap. (A string array is a variable of type string and an array of integers that are passed into the "String Array" functions. To create a string array, create a string and an array of integers and pass them into these functions).

See also: _AppendString, _FindString, _GetStrCount, _GetString, _RedimStrArray, _RemoveLastString, _SetString, String Array

_________________
Ron L.

http://www.beijerelectronicsinc.com/


Top
 Profile  
 
 Post subject: Re: Persistent Variables
PostPosted: Fri Dec 02, 2011 3:40 pm 
Offline

Joined: Thu Aug 09, 2007 4:44 pm
Posts: 67
Ron,

I tried that using this code:

_deletestring(saved_list.selected,LBData,LBDataI)


...but I got an error "unable to promote charstr as reference to string"

What am I doing wrong?


Top
 Profile  
 
 Post subject: Re: Persistent Variables
PostPosted: Fri Dec 02, 2011 3:48 pm 
Offline
User avatar

Joined: Thu Mar 02, 2006 2:12 pm
Posts: 487
Location: Salt Lake City, Utah
Are you using unicode characters in your workspace (i.e. Chinese fonts)?
(here are your 3 options, depending on the answer to this question)

1. If no, go to Tools->Settings->Compile and un-check "Enable Unicode support in standard objects".
2. If yes, but not in this particular list, then you can use _StrToCharstr and _CharstrToStr to switch back and forth between string and charstr.
3. If you are using unicode characters in that particular list, you'll need to write your own _DeleteString function, but you can copy some of the code from here.
Code:
func _DeleteString (index as integer, strings as reference to string, breakInfo[] as reference to integer)
    dim count, i, j as integer
    dim offset as integer

    count = len(breakInfo)

    if index < 0 or index >= count then
        Throw ("_DeleteString", "String array index out of bounds (" + str(index) + ")")
    endif

    if index == 0 then
        strings = mid(strings, breakInfo[0], -1)
        offset = breakInfo[0]
    else
        strings = left(strings, breakInfo[index-1]) + mid(strings, breakInfo[index], -1)
        offset = breakInfo[index] - breakInfo[index-1]
    endif

    j = count - 2
    for i = index to j
        breakInfo[i] = breakInfo[i+1] - offset
    next
    redim (breakInfo, count-1)
endfunc

_________________
Ron L.

http://www.beijerelectronicsinc.com/


Top
 Profile  
 
 Post subject: Re: Persistent Variables
PostPosted: Fri Dec 02, 2011 3:52 pm 
Offline

Joined: Thu Aug 09, 2007 4:44 pm
Posts: 67
Hmmm... I am not using unicode characters and that box is already unchecked in tools->Settings->compile->

Anything else?

I see that the variable LBData is a charstr so I guess it is not compatible with the standard _deleteString function? I guess I'll have to rewrite the _deleteString function to handle a Charstr... but I'd appreciate some pointers on how to go about this and the difference between CharStr and String


Top
 Profile  
 
 Post subject: Re: Persistent Variables
PostPosted: Fri Dec 02, 2011 4:22 pm 
Offline
User avatar

Joined: Thu Mar 02, 2006 2:12 pm
Posts: 487
Location: Salt Lake City, Utah
If that is unchecked, then you just need to call the functions _StrToCharstr and _CharstrToStr to switch back and forth between "string" and "charstr". You can still use the existing_DeleteString function..

_________________
Ron L.

http://www.beijerelectronicsinc.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 7 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group