forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Logical arguments to %rb, and grey-control arguments

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+
View previous topic :: View next topic  
Author Message
simon



Joined: 05 Jul 2006
Posts: 268

PostPosted: Fri Dec 03, 2021 2:39 am    Post subject: Logical arguments to %rb, and grey-control arguments Reply with quote

%rb uses an integer control variable for a value that is recognised as either 0 or 1. Similarly, there is an optional control variable that works in a similar way. Other format codes, such as %mn, take similar grey control variables. Is it possible to use logical variables for these controls instead?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Fri Dec 03, 2021 9:30 am    Post subject: Reply with quote

Simon

At the moment logical values are rejected both by the compiler FTN95 and by the ClearWin+ library at runtime.

It would be possible to change the compiler and the library to allow logical values. This should be a simple task but it may take more time than it warrants.

I am not a fan of EQUIVALENCE statements but one option is illustrated in this short sample...

Code:
winapp
program main
integer iw,ictrl
logical ctrl
equivalence (ctrl,ictrl)
ctrl=.false.
iw = winio@("%~6bt[OK]", ictrl)
end
Back to top
View user's profile Send private message AIM Address
wahorger



Joined: 13 Oct 2014
Posts: 1217
Location: Morrison, CO, USA

PostPosted: Sat Dec 04, 2021 3:10 am    Post subject: Reply with quote

This is what I use.

The following is a code snippet that will compile and give the appropriate value for a %rb (as a check box), and a grey control on the %rb.

Code:

LOGICAL BUTTON_VAL,BUTTON_GREY
INTEGER I

I = WINIO@('%~`rb[This is a check box]',core4(loc(button_val)),core4(loc(button_grey)))



This syntax of core4(loc(x)) says "take the location of variable x and use that address as if it is an integer*4 address".

This works very well for me. You can "noodle out" how this has other uses for both ClearWin and other purposes.
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Sat Dec 04, 2021 9:15 am    Post subject: Reply with quote

You could do something similar using the TRANSFER intrinsic...

Code:
winapp
program main
integer iw
logical ctrl
ctrl=.true.
iw = winio@("%~6bt[OK]", transfer(ctrl,iw))
end
Back to top
View user's profile Send private message AIM Address
simon



Joined: 05 Jul 2006
Posts: 268

PostPosted: Fri Dec 10, 2021 7:39 am    Post subject: Reply with quote

Many thanks, both. I think I could get something working with these suggestions.
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Fri Dec 10, 2021 8:47 pm    Post subject: Reply with quote

Simon,

I often pondered the substance of your question (although never more than fleetingly), especially as 0 and 1 integers have exactly the same bit patterns as .false. and .true. Indeed, some FTN95 functions can be fed either INTEGERs or LOGICALs, provided that you do it consistently, with my example being USE_RGB_COLOURS@. So why not the usages you adduce?

My theory is that at some stage in the development of ClearWin, a check on variable type was introduced to catch user-errors in the type of parameters, and that removed the interchangeability. I may be wrong.

As for me, I am quite happy with it the way it is, probably because I like IMPLICIT type, and LOGICAL always needs a type declaration. I suppose that one benefit of LOGICAL is that you can operate on it with .NOT. to select the alternate state. You can do something with IABS ( 1 – IVALUE) – effectively the INTEGER version of a .NOT. operator.

As well as being happy with the way ClearWin works, I am usually happy with the way things are, and don’t always want them changed. In this, I differ strongly from Professor Higgins and his plaintive complaint (in song) about why things are the way they are, and not as he would prefer!

Eddie
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+ All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group