Beijer Electronics (formerly QSI Corporation)

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

All times are UTC - 7 hours




Post new topic Reply to topic  [ 30 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: Tue May 09, 2006 9:20 am 
In my opinion, it should be easier using integers. With integers, you know the size is always 4 bytes unlike a string which can be any length.



I would do something like this using a fileobj: (perhaps not the best method)





FileObj1.WriteInteger(ObjCount, 0) <-- start of file

for x:=1 to ObjCount

FileObj1.WriteInteger(Red[x], x*4) <---this spaces the integers properly

'for ex: 1=byte 4, 4=byte 16

next





Then to read:

FileObj1.ReadInteger(ObjCount, 0) <--read count at start

for x:=1 to ObjCount

FileObj1.ReadInteger(Red[x], x*4)

next







Results if Red[3]=3,2,1

Byte 0: ObjCount is 3

Byte 4: 3

Byte 8: 2

Byte 12:1



===================

On the other hand, I mixed integer and strings. To use the string effectively, I simply kept adding "," seperated items to the list. Finally before saving the string to the file, I write the LEN(MyString) as integer, then the string. Now when I come back to read, I know the length of my huge string, and then parse it accordingly.









Hope this helps somewhat.


Top
  
 
 Post subject:
PostPosted: Tue May 09, 2006 10:01 am 
Offline

Joined: Mon May 01, 2006 3:27 pm
Posts: 60
MY ERROR Disregard this .....





I dont know what happend but It works now. Except one problem.

On startup I assign the variables via SetDimmers(), Then write the file then Read the file and all works. I comment out SetDimmers() and WriteData() then run. The files are there with all the data.

In my code I change some data via RED[x] = XX then do a WriteData(). I restart and the data I changed is not there ? Do I need to redim when I WriteData ?







Code:





func SetDimmers()

    Dim i as integer

    dim s as integer



for s =1 to 32



        for i=1 to 15

        RED[i*s]=1

        Green[i*s]=2

        Blue[i*s]=0

        next

next

endfunc



func WriteData()

    dim fnum as fileDesc



    fnum = OpenFile("ProjectFile.dat", FILE_BINARY and FILE_WRITE)

    WriteFile(fnum, RED)

    WriteFile(fnum, GREEN)

    WriteFile(fnum, BLUE)



    CloseFile(fnum)



endfunc





func ReadData()

    dim fnum as fileDesc

    fnum = OpenFile("ProjectFile.dat", FILE_BINARY AND FILE_READ)

    ReadFile(fnum, RED)

    ReadFile(fnum, GREEN)

    ReadFile(fnum, BLUE)



    CloseFile(fnum)

    redim(RED, 170)

    redim(GREEN, 170)

    redim(BLUE, 170)





label_7.value=str(RED[0])+ str(RED[1])+ str(RED[2])+ str(RED[3])









endfunc











Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 10:18 am 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
Ok, I assume that you got it working then.

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 12:15 pm 
Offline

Joined: Mon May 01, 2006 3:27 pm
Posts: 60
Yes, Its working. I think I now understand the String Array concept.



Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 1:18 pm 
Heres my func i use to split up delimited (by a comma in this case) arrays. There must be a COMMA at the end for this to work.

(example) MyArray="123,45,67," <-note trailing comma



You pass your array/string to the func and it returns the next ITEM and updates the array you passed by removing the ITEM that was returned (and its comma)





func GetNextDelimItem(MyArray[] as reference to char ) returns string

dim x as integer

dim MyStr as string

x=find(MyArray,0,-1,",")

MyStr:=Left(MyArray,x) 'MyStr is ITEM

MyArray:=Mid(MyArray,x+1,-1) 'Orig array has ITEM removed

'note the list has to END with a , for this to work 100%

return MyStr



endfunc


Top
  
 
 Post subject:
PostPosted: Tue May 09, 2006 1:44 pm 
Offline

Joined: Mon May 01, 2006 3:27 pm
Posts: 60
cloud9



thanks I will add this to my code snippets for refrence.



Jerry


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 6:53 pm 
Offline

Joined: Mon May 01, 2006 3:27 pm
Posts: 60
The sample code has got my interest. I want to create a file with a text string and select each part of the string to display. I changed the code for my needs.

I can use a comma to seperate the strings I wamt to store.



How do I get the string I want ?



GetNextDelimItem()





Code:

Dim FixtureLabel as string

FixtureLable="Fixture 1,Fixture 2,Fixture 3,"











Code:



func GetNextDelimItem(FixtureLable[] as reference to char ) returns string

dim x as integer

dim MyStr as string

x=find(FixtureLable,0,-1,",")

MyStr:=Left(FixtureLable,x) 'MyStr is ITEM

FixtureLable:=Mid(FixtureLable,x+1,-1) 'Orig array has ITEM removed

'note the list has to END with a , for this to work 100%

return MyStr

endfunc







Top
 Profile  
 
 Post subject:
PostPosted: Wed May 10, 2006 7:23 am 
There may be a problem using the same var name for the global var and the paramater var (in the func). I would change the name of the global to anything else like:

Code:

dim GlobalFixture as string

init GlobalFixture := "Fixture 1, Fixture 2, Fixture 3,"





Other than that you are ready to grab the next item by calling:

Code:

GetNextDelimItem(GlobalFixture)





If you know how many items exist you can do:

Code:

for x := 1 to ItemCount do

SomeArray[x] := GetNextDelimItem(GlobalFixture)

next







[/code]


Top
  
 
 Post subject:
PostPosted: Wed May 10, 2006 8:15 am 
Offline

Joined: Mon May 01, 2006 3:27 pm
Posts: 60
I got the code to work but there is a probem I not sure how to fix.





Fixture is set by 5 buttons 1-5. The first click of fixture 1 sets the Text to "Fixture 1" the second click of button 1 sets the Text to "Fixture 2" I understad why its doing it but how do I reset to start looking at the front of the string each tme its accessed ?











Code:



    for x = 0 to Fixture

     Label_7.value= GetNextDelimItem(GlobalFixture)

    next







This I dont understad. I though String Arrays will not work.





Code:



for x := 1 to ItemCount do

SomeArray[x] := GetNextDelimItem(GlobalFixture)

next







Top
 Profile  
 
 Post subject:
PostPosted: Wed May 10, 2006 8:40 am 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
I hope you don't mind me interjecting a few things here.



First of all -- the case of giving a parameter name the same as the name of a global variable. Local variables (including parameters) will mask global variables of the same name. This means that his code should be fine as long as he doesn't need to access the global version of FixtureLable within that function.



Second, the code that Cloud9 provided should work (I haven't personally tested it, but it looked right). However, if you are using a large data set, it can be inefficient as you are constantly shifting data around the array.



The following version is a bit more efficient at parsing the array, but it is more complex and harder to use -- so decide which is better for your application. For small strings you will never see the performance difference.



Code:

func ParseAString(data as reference to string)

    dim pos as integer

    dim oldPos as integer



    pos := find (data, 0, -1, ",")

    while pos >= 0 do

       'Do whatever magic you need to do here to process an item

        mid(data, oldPos, pos-oldPos) 'this returns an item, assign it or pass it to a function

        oldPos := pos+len(separator)

        pos := find (data, oldPos, -1, separator)

        index := index + 1

    loop

endfunc





Just a note about strings and chars. This will probably never affect you but you may wish to be aware of it. Strings are arrays of bytes, not chars. A char is often identical to a byte. However, if you enable Unicode support chars become identical to a unibyte and you can no longer pass in a string to a function which expects an array of chars.



Finally, colormaker, you are correct that you cannot make arrays of strings. The code

Code:

for x := 1 to ItemCount do

    SomeArray[x] := GetNextDelimItem(GlobalFixture)

next




will not work. You do have a few options at your disposal though.



You could use the string array functions provided to simulate an array of strings using a single string and an array of bytes. These are relatively inefficient, but they are easy to use.



You could create listboxV2 object and make it disabled. The listboxV2 contains functions to add, remove, and get strings. By making it disabled it will never display. This will be somewhat more efficient.



Another option is to create a new object template with a single string property.
Code:

'This would have to go in advanced code

define object type StringHolder

    dim strg as string

enddef



declare sh1 as StringHolder

enddec



declare sh2 as StringHolder

enddec



declare sh3 as StringHolder

enddec



'Declare as many StringHolders as you need



dim StrArray[] as objref StringHolder

init StrArray := [sh1, sh2, sh3]



This enables you code to look like this

Code:

for x := 1 to ItemCount do

    StrArray[x].strg := GetNextDelimItem(GlobalFixture)

next





This will be the most efficient speed wise, but requires you to pre-declare every string you could possibly need.



Finally, if you are familiar and comfortable with the constraints of C-style memory managment, you could use the ArrayHandles routines to store you strings as an array handle which can be placed in a normal array of array handles (this is what the list box does). This option entails the possibility of memory leaks of you do not properly call FreeArrayHandle for each handle when you have completed using it.

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 10, 2006 9:00 am 
Offline
User avatar

Joined: Wed May 10, 2006 7:25 am
Posts: 26
Location: Nashvegas, TN
I obviously didnt put alot of thought into that one.... You are correct, Qlarity (unfortunately) doesnt support string (multidimensional) arrays.



As far as the other portion of your question, I dont understand it. When you call our GetNextDelim() func it automatically removes your text from the original string\array. Everytime you call that func it is grabbing the first item, then removing that from the main array.



Are you saying that if you click Button 1 you ONLY want it to grab item1, Button 2 for Item 2? In that case, we could do like:

Code:



func MyTest()



dim MyString as string '<--main

dim CommaLocations[4] as integer

dim x, LastX as integer

init LastX := -1

init MyString := "Chris,Joe,Bobby,Mike,"



'Now we succesively find the location of ALL commas by doing:

for x = 0 to 3

CommaLocations[x] = find(MyString, LastX+1 , -1,",")

LastX = CommaLocations[x]



    If LastX == -1 then  'No COMMA found, so exit

return

endif



    MyLabel.value = MyLabel.value + " " + str(LastX)

next



endfunc





Now you know item1 is between 0 and Comma1, and item2 is between Comma1 and Comma2 and you do not have to modify your original array/string to get your values. You could even write funcs to grab specific items:



Code:

func GetItemOne() returns string

dim AStr as string

AStr = Mid(OriginalArray, 0, CommaLocations[0]-1)

return AStr

endfunc



func GetItemTwo() returns string

dim AStr as string

AStr = Mid(OriginalArray,  CommaLocations[0]+1, CommaLocations[1]-1)

return AStr

endfunc







I have a tendency to write obscure code, I would highly doubt this is the most efficient way to do this but hopefully you get some ideas from it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 10, 2006 9:25 am 
Offline

Joined: Mon May 01, 2006 3:27 pm
Posts: 60
I think until I get more familar with the Qlairty I should stick to the basics. Maybe the ListboxV2 is the way I should start off.



I looked through all the samples and could not find any code that I could reference the ListBoxV2 finctions.



Anyone have samples ?



Add, read and edit list box contents and how to select...



To start all I need is to store 16 strings with each astring having a maximum chr length of 15.



Cloud9 and Jerimy thanks for all the help.



Jerry


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 10, 2006 9:43 am 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
I don't know that there is much sample code for manipulating a listbox -- people don't do it at runtime all that often.



It is very straightforward. Just look up the ListboxV2 in the online help. Focus on the AddString, SetString, InsertString, GetString and DeleteString functions. If you plan to pre-set the strings at design time, use the InitialListcontent property (set this one in the Properties Window of Layout View).



Code:

'Transmits each string in a list box out the serial port

dim i, max as integer

max = list.GetCount() - 1

for i = 0 to max

    Transmit (com1, list.GetString(i) + "\n", false)

next


_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 10, 2006 9:50 am 
Offline

Joined: Mon May 01, 2006 3:27 pm
Posts: 60
I may be missing something but the help documentation is not very helpful.



Help and Support Center F1





"AddString" gives me this -



fixed func AddString (newStr as charStr)

Call this function to add an entry at the end of the list.





No Examples ???


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 10, 2006 9:56 am 
Offline
User avatar

Joined: Thu Mar 02, 2006 2:12 pm
Posts: 487
Location: Salt Lake City, Utah
There is a sample program called: "parse_comma_separated_list.qly " that is installed with Qlarity Foundry under the /Samples directory that uses the AddString function that might be a good start.



FYI, many of the ListBox functions may not work in a Startup function that handles MSG_INIT. If you want to call list box functions on startup create a PostStartup function like this:



Code:
'this code is in globals

func Startup ()

    handles MSG_INIT

    userdirectmsg(default, _msg_post_init, 0, false)

    return

endfunc

func PostStartup(dmy as integer) returns boolean

    handles _msg_post_init

    listbox_1.addstring("blblblb")

    return true

endfunc

_________________
Ron L.

http://www.beijerelectronicsinc.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 30 posts ]  Go to page Previous  1, 2

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