Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

Application Builder, Newbie help, using For loop

Please login with a confirmed email address before reporting spam

Hi

I have just started out using the API for the first time and I wish to generate a number of Global Parameters entries, namely sigma_ink1, sigma_ink2, sigma_ink3 etc.

I have successfully recorded a Method using the Set operation and surrounded it with a For block statement ...

int n=10;
for (int i=0; i<n; ++i) {
int j=i+1
with (model.param());
set("sigma_ink"+j, "1000[S/m]");
endwith();
}

but instead of using 'n' I want to use a defined Global parameter 'ArraySize' which = 10 (or whatever the user enters).

Question: What is the syntax for using ArraySize instead of 'n'?

I have tried...

for (int i=0; i<"ArraySize"; ++i)

...but this just gives an error and I have searched but not found an answer.

Any newbie help much appreciated
Colin

2 Replies Last Post Sep 20, 2016, 5:54 a.m. EDT
Edgar J. Kaiser Certified Consultant

Please login with a confirmed email address before reporting spam

Posted: 8 years ago Sep 20, 2016, 5:38 a.m. EDT
Colin,

you compare with i, which is an integer, you decared it locally this way. So ArraySize has to be declared as a global integer. "ArraySize" as you used it is just a string constant.

If for some reason you need to declare ArraySize as a global string, you can convert, using toInt(Arraysize).
Your set method is wrong as well. You are adding the integer j and a string constant.

There are quite some JAVA tutorials around for syntax questions like this one. I am using them extensively.

Cheers
Edgar

--
Edgar J. Kaiser
emPhys Physical Technology
www.emphys.com
Colin, you compare with i, which is an integer, you decared it locally this way. So ArraySize has to be declared as a global integer. "ArraySize" as you used it is just a string constant. If for some reason you need to declare ArraySize as a global string, you can convert, using toInt(Arraysize). Your set method is wrong as well. You are adding the integer j and a string constant. There are quite some JAVA tutorials around for syntax questions like this one. I am using them extensively. Cheers Edgar -- Edgar J. Kaiser emPhys Physical Technology http://www.emphys.com

Please login with a confirmed email address before reporting spam

Posted: 8 years ago Sep 20, 2016, 5:54 a.m. EDT
Thank you, I understand that there is no substitute for learning the basics and I can see this mix-up of integers and strings.

I was cheekily looking for help on this one aspect so that I could demonstrate the feature and in-turn buy some time for myself some time to study it more thoroughly.

Appreciate your time.

Colin
Thank you, I understand that there is no substitute for learning the basics and I can see this mix-up of integers and strings. I was cheekily looking for help on this one aspect so that I could demonstrate the feature and in-turn buy some time for myself some time to study it more thoroughly. Appreciate your time. Colin

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.