One thing I didn't explain is that I used a Variant for the auto String-Integer coercion (between others).

Thank you for your explanations, that is exactly what I supposed it does... once I get the error string which is very explicit in this case.

The real object of the original mail was to flag this "strange behavior" - for me - ...

I already use Variant for other things and Variant is good.


And the original idea waas to have a better styled example to pass data to an array (to create PolyGon).

BTW: the "start filling Array at position 1" have to be explained in the Language Reference (documentation). I didn't ask the explanation why, but a simple sentence telling that "it works that way".


I will follow your suggestion

Emile

Subject: Re: Variant and Split: does not works for String to Integer
        coercion
From: [EMAIL PROTECTED]
Date: Thu, 4 May 2006 10:27:52 -0600

On May 04, 2006, at 15:30 UTC, Emile Schwarz wrote:

  Dim TriangleOne As Variant // To use the automatic type conversion
  Dim TriOne(5)   As Integer // 6 entries array
// Fills the Variant with a "String variable"
  TriangleOne = "5,5,25,5,15,25"
// Fills the Array
  // Test #1 (fails)
  TriOne = TriangleOne.Split(",")

This fails for two reasons.  First, you can't call Split on a variant (and 
there is no need for this to be a variant; you're only storing a string in it, 
so you should declare it as a string).  Second, Split returns an array of 
strings, not an array of integers.

  // Test #2 (fails too)
  TriOne = Split(TriangleOne,",")

This one correctly calls Split, but fails for reason two: the result is 
String(), and you're trying to stuff it into Integer(), which is a type 
mismatch.

To split a string and then convert that into an array of integers, you could 
use the SplitToInt function in the StringUtils module:

  TriOne = SplitToInt( TriangleOne, "," )

But even easier might be to simply use the built-in Array function:

 TriOne = Array( 0, 5,5,25,5,15,25 )

Note that I have to insert an extra number (0) because DrawPolygon expects a 
1-based array for odd historical reasons.

Also note, with any of these, that it doesn't matter how big you dimension 
TriOne in its Dim statement; you're going to throw out that array and replace 
it with the result of SplitToInt or Array anyway.  So just declare it as: Dim 
TriOne() as Integer.


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to