The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 How can I pass String Array?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

winflowers

USA
34 Posts

Posted - 09/28/2004 :  11:58:32 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7.5
Operating System: windows 98
I make a function to collect all worksheet names under active folder and store them in a string array. But how can I use this string array in other functions?

easwar

USA
1965 Posts

Posted - 09/28/2004 :  12:52:27 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello,

StringArray is just a vector of type string, and so you can write code such as:


void test()
{
StringArray sa(3);
sa[0] = "one";
sa[1] = "two";
sa[2] = "three";
test2( sa );
}

void test2(StringArray& sa)
{
for(int ii = 0; ii < sa.GetSize(); ii++)
out_str( sa[ii] );
}




which is same as:


void test()
{
vector<string> sa(3);
sa[0] = "one";
sa[1] = "two";
sa[2] = "three";
test2( sa );
}

void test2(vector<string>& sa)
{
for(int ii = 0; ii < sa.GetSize(); ii++)
out_str( sa[ii] );
}



Easwar
OriginLab



Go to Top of Page

winflowers

USA
34 Posts

Posted - 09/29/2004 :  03:30:18 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you very much for your code, Easwar! But that is not what I exactly want. What I want is that test() is an indepentant function, and I would like to use this function in other functions, for example test2() . Maybe I didn't say it clearly. The following code can do it.

vector<string> test()
{
vector<string> sa(3);
sa[0] = "one";
sa[1] = "two";
sa[2] = "three";
return sa;
}
void test2()
{
vector<string> sa2;
sa2 = test();
for(int ii = 0; ii < sa2.GetSize(); ii++)
out_str( sa2[ii] );
}

When I run test2(), I can get the results for test(). Or is there any other code can do this as well?
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 09/29/2004 :  08:02:29 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Your code works fine so I'm not sure what you are asking. Do you want an alternative to vector<string> test()? This will work...
void test(SringArray &sa) 
{
sa.SetSize(3);
sa[0] = "one";
sa[1] = "two";
sa[2] = "three";
}
void test2() 
{
StringArray sa;
test(sa);
for(int ii = 0; ii < sa.GetSize(); ii++)
out_str( sa[ii] );
}


Mike Buess
Origin WebRing Member
Go to Top of Page

winflowers

USA
34 Posts

Posted - 09/29/2004 :  08:32:45 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Great! This is exactly what I want!
I don't like vector<string> test(), so I don't satisfied with my code although it works.
Thank you guys for your help. It's realy a good forum.
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000