Problem with *if statement

Moderator: GiD Team

Post Reply
wfmoralesp
Posts: 8
Joined: Fri Apr 10, 2015 1:30 pm

Problem with *if statement

Post by wfmoralesp »

Hi,

I'm trying to use an IF statement in my .bas file as:

*loop intervals
check_mat=*IntvData(1)
*if(IntvData(1)!=0)
*IntvData(1),*IntvData(2),*IntvData(3)
*Set Cond Structure *nodes
*if(CondNumEntities>0)
*loop *nodes *OnlyInCond
*if(strcmp(*cond(1),"Liner")==0)
*cond(2),1,*NodesNum,*cond(4),*cond(3)
*endif
*end nodes
*endif
*endif
*end intervals

with a condition:

NUMBER:30 CONDITION: Structure
CONDTYPE: over lines
CONDMESHTYPE: over nodes
QUESTION: Structural_element#CB#(Liner,Beam,Pile,Rockbolt)
VALUE:Liner
QUESTION: Sequential_ID
VALUE:1
QUESTION: Property_ID
VALUE:1
QUESTION: Segments
VALUE:10
END CONDITION

and:

INTERVAL DATA
QUESTION: Material_ID_to_modify
VALUE:1
QUESTION: Material_ID_to_apply
VALUE:1
QUESTION: Sequential_ID
VALUE:1
END INTERVAL DATA

But it keeps telling me "Error into an *if expression".

Why is it telling me this or what am I doing wrong? Thx so much in advance.

cheers,

Ferney
User avatar
escolano
Posts: 1922
Joined: Sun Sep 05, 1982 10:51 pm

Re: Problem with *if statement

Post by escolano »

I think that the error is in the line
*if(strcmp(*cond(1),"Liner")==0)
try without the '*' inside conditionals
*if(strcmp(cond(1),"Liner")==0)

other comments,
I recommend you to use field names instead of field index when possible, it is easier to be mantained and more user readable,
e.g.
instead of
*IntvData(1),*IntvData(2),*IntvData(3)
use
*IntvData(Material_ID_to_modify),*IntvData(Material_ID_to_apply),*IntvData(Sequential_ID)


and
*if(CondNumEntities>0)
*endif
is unneded, the *loop *nodes *OnlyInCond will be done only over the entities with the condition (none if CondNumEntities==0)
wfmoralesp
Posts: 8
Joined: Fri Apr 10, 2015 1:30 pm

Re: Problem with *if statement

Post by wfmoralesp »

Hi,

your suggestion of using (*if(strcmp(cond(1),"Liner")==0)) worked. However, the another IF statement (*if(IntvData(1)!=0)) continues showing the error message. I even tried your suggestion of using the field's name, i.e. *if(IntvData(Material_ID_to_modify)!=0), but nothing :(, any other ideas?

Thx for your support,

Ferney
User avatar
escolano
Posts: 1922
Joined: Sun Sep 05, 1982 10:51 pm

Re: Problem with *if statement

Post by escolano »

Instead
*if(IntvData(1)!=0)
you can simply use
*if(IntvData(1))
(the condition is true if is not zero, like all languages: C/C++,...)
and if the error persists try to splicitly say that this field must be considered as an integer (in general all dada fields are strings)
to do this could add an extra argument ,int

*if(IntvData(1,int))
wfmoralesp
Posts: 8
Joined: Fri Apr 10, 2015 1:30 pm

Re: Problem with *if statement

Post by wfmoralesp »

Thx so much for your help, your idea of explicitly expressing field as integer did the work, at the end I have it working as: *if(IntvData(1,int))
Post Reply