PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Dan English on May 06, 2010, 11:29:26 AM

Title: Trouble populating My Little Grid with data from UDT
Post by: Dan English on May 06, 2010, 11:29:26 AM
I'm having trouble getting data from a user-defined type into a My Little Grid control.

I have verified that the user-defined type is populated with correct data.  All members in the UDT are strings, so that shouldn't be an issue.  I can even populate a listview no problem with this data.

When I try assigning these values to cells in a MLG control, I keep getting an "Error 480: PARAMETER MISMATCHES DEFINITION".

Setting hard-coded test works fine:

MLG_Put HWND_MLGCONTROL, 1, 1, "testvalue1", 0
MLG_Put HWND_MLGCONTROL, 1, 2, "testvalue2", 0
MLG_Put HWND_MLGCONTROL, 1, 3, "testvalue3", 0


But setting values from a UDT does not work:

MLG_Put HWND_MLGCONTROL, 1, 1, MyUDT.Value1, 0
MLG_Put HWND_MLGCONTROL, 1, 2, MyUDT.Value2, 0
MLG_Put HWND_MLGCONTROL, 1, 3, MyUDT.Value3, 0


My UDT is defined similarly as follows:

Type MyUDT
    Value1 AS String * 5
    Value2 AS String * 10
    Value3 AS String * 1
End Type


Displaying MyUDT.Value1 in a MsgBox immediately before the first MLG_Put displays data, so I know it's there.

Am I missing something obvious??
Title: Re: Trouble populating My Little Grid with data from UDT
Post by: Paul Squires on May 06, 2010, 12:34:55 PM
Not sure if Jim will see your message here but in case he does not, you should send any MLG support questions directly to James Klutho at  mlg@planetsquires.com

Title: Re: Trouble populating My Little Grid with data from UDT
Post by: Dan English on May 06, 2010, 12:44:40 PM
Thanks -- I'll try e-mailing James!
Title: Re: Trouble populating My Little Grid with data from UDT
Post by: Elias Montoya on May 06, 2010, 12:52:47 PM

Try:

MLG_Put HWND_MLGCONTROL, 1, 1, TRIM$(MyUDT.Value1, chr$(0,32)), 0

Maybe the engine is not made for null characters.
Title: Re: Trouble populating My Little Grid with data from UDT
Post by: Dan English on May 06, 2010, 01:21:16 PM
Thanks Elias... that seemed to work.  Seems a bit messy having to do that for each MLG_Put, but it gets the job done!
Title: Re: Trouble populating My Little Grid with data from UDT
Post by: Paul Squires on May 06, 2010, 01:39:08 PM
I wonder if the problem is that you are sending a fixed length string to a parameter that expects to be a dynamic string?

Maybe try something like;

MLG_Put HWND_MLGCONTROL, 1, 1, ByCopy MyUDT.Value1, 0
Title: Re: Trouble populating My Little Grid with data from UDT
Post by: Dan English on May 06, 2010, 02:04:29 PM
Thanks -- ByCopy works too!  It never would have crossed my mind to use that.
Title: Re: Trouble populating My Little Grid with data from UDT
Post by: Dan English on May 07, 2010, 12:37:18 AM
Just to finalize this -- Mr. Klutho kindly responded to my e-mail, and simply suggested wrapping the UDT string value with Trim$().  Worked!

Many ways to do this apparently.  Thanks to all!
Title: Re: Trouble populating My Little Grid with data from UDT
Post by: Paul Squires on May 07, 2010, 08:33:18 AM
If you don't want to trim then you could change your udt to be asciiz.


Type MyUDT
    Value1 AS Asciiz * 5
    Value2 AS Asciiz * 10
    Value3 AS Asciiz * 1
End Type

Title: Re: Trouble populating My Little Grid with data from UDT
Post by: Brian Chirgwin on May 07, 2010, 12:36:57 PM
 A UDT with fix length strings, or array of them, is to be fast. Adding code to automatically "Trim" or what ever one would want to do would add a lot of overhead when it might not be needed.

If you think about it, it would be difficult to impossible to tell when to add this code. For example, if you use Array Sort should it be added and how.

To get what you want, you could use an class/object. An object can have a dynamically sized string.

Code not tested

Class myClass
   instance m_sName as string
   interface myClassInterface
      property get Name() as string
         property = m_sName
     end property
   end interface

end class


A collection class would allow you to have multiple. In the end this might be more work to load into the grid, but it also may allow more flexibility.
Title: Re: Trouble populating My Little Grid with data from UDT
Post by: Paul Squires on May 07, 2010, 01:43:29 PM
It would be even better if dynamic strings where allowed in UDT's, but they are not and I fought and lost that new feature suggestion many moons ago in the PB forum (some people just can't get past the "UDT's must be fixed length" argument).

Likewise, dynamic arrays in UDT's would be a great addition. These days, it is probably just as easy to convert your code to use classes rather than play with manually allocating/deallocating dynamic strings in UDT's (like I am doing in all my code).