Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Passing arrays to .NET and getting arrays back
Message
From
02/05/2011 13:04:23
 
 
To
02/05/2011 12:11:17
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01509041
Message ID:
01509051
Views:
53
>>I have built a webservice wrapper in C# for VFP to eat. Works great. All my exposed methods are receiving and returning to and from VFP as expected - except arrays
>>
>>I think I need a refresher on the nuances of passing arrays in and out. Because of lack of strong typing, I assume the .NET incoming param must be object[] or object[,]
>>
>>I am currently trying to pass in a vfp @arrparam where arrparam is dime arrayparam[4] of strings. I would like to get back ids[4,2] with strings and integers.
>>
>>I could also pass in a 2 dime array by reference if I could figure out how to pass it back.
>>
>>If my object is lows, besides
>>
>>comarray(lows,0) to get the array to pass in 0 based what are the other tricks I should know about this?
>>
>>The method works fine in my .NET test harness
>>
>>
>>    public object[,] FindIdsByEmails(object[] emailarray)
>>        {
>>            int emailslen = emailarray.Length;
>>            object[,] returnarray = new object[emailslen, 2];
>>            for (int i = 0; i < emailslen; i++)
>>            {
>>                string email = (string)emailarray[i];
>>                long? id = this.FindIdByEmail(email);
>>                returnarray[i, 0] = email;
>>                if (id != null)
>>                {
>>                    returnarray[i, 1] = id;
>>                }
>>                else
>>                {
>>                    returnarray[i, 1] = 00000;
>>                }
>>            }
>>            return returnarray;
>>        }
>>
>>
>>But this VFP test prg gets me an error that "Function argument value, type or count is invalid."
>>
>>
>>CD "c:\users\pagan\documents\visual studio 2010\projects\glwebservice\glwebservice\bin\debug"
>>ACTIVATE WINDOW watch
>>lows = CREATEOBJECT("glwebservice.glclient")
>>lows.login("xxxxxx@xxxxx.org", "password", "<security key")
>>
>>DIMENSION foo(4)
>>
>>foo(1)="dan@primarydatasolutions.com"
>>foo(2)="charleshankey@f1tech.com"
>>foo(3) = "raferris@hsonline.net"
>>foo(4) = "foo@foo.net"
>>DIMENSION ids(4,2)
>>
>>comarray(lows,0)
>>
>>* here's where I get the error
>>
>>ids = lows.FindIdsByEmails(@foo)  
>>
>>lows.logout
>>lows = null
>>
>>RETURN
>>
>>
>>
>>
>>Suggestions, hints, pointing to docs all appreciated.
>
>
>See if Message #675527 helps...

Refactored to try to pass a 2 dime array by reference
CD "c:\users\pagan\documents\visual studio 2010\projects\glwebservice\glwebservice\bin\debug"
ACTIVATE WINDOW watch
SET STEP ON 
lows = CREATEOBJECT("glwebservice.glclient")
lows.login("mquigley@sba-list.org", "Sbalist123!", "RUIbS9BPsZ7TkyCRCl6B89Gi")
DIMENSION foo(4,2)


foo(1,1)="dan@primarydatasolutions.com"
foo(2,1)="charleshankey@f1tech.com"
foo(3,1) = "raferris@hsonline.net"
foo(4,1) = "foo@foo.net"
foo(1,2) = 0
foo(2,2) = 0
foo(3,2) = 0
foo(4,2) = 0
comarray(lows,0)

* doesn't this pass the array by reference ???

=lows.FindIdsByEmails(@foo)

lows.logout
lows = null

RETURN
Here is the refactored C# - once again works like a charm inside C# test harness
        public void FindIdsByEmails(object[,] emailarray)
        {
            int emailslen = emailarray.GetLength(0);

            for (int i = 0; i < emailslen; i++)
            {
                string email = (string)emailarray[i,0];
                long? id = this.FindIdByEmail(email);

                
                if (id != null)
                {
                    emailarray[i, 1] = id;
                }
                else
                {
                    emailarray[i, 1] = 00000;
                }
            }
        }


Charles Hankey

Though a good deal is too strange to be believed, nothing is too strange to have happened.
- Thomas Hardy

Half the harm that is done in this world is due to people who want to feel important. They don't mean to do harm-- but the harm does not interest them. Or they do not see it, or they justify it because they are absorbed in the endless struggle to think well of themselves.

-- T. S. Eliot
Democracy is two wolves and a sheep voting on what to have for lunch.
Liberty is a well-armed sheep contesting the vote.
- Ben Franklin

Pardon him, Theodotus. He is a barbarian, and thinks that the customs of his tribe and island are the laws of nature.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform