Silverfrost Forums

Welcome to our forums

Display problem with \"%ls\" and \"%rs\"

22 Jan 2009 4:26 #4223

Hi,

I'm using a licensed version of FTN95 (4.6.0.0) with Windows 2000 Professional (office PC) and Windows XP (home laptop), respectively. In both environments, the following problem occurs.

I'm using a couple of '%ls' commands in several places to display some data for the user to choose from. However, in many of these drop down boxes, there appears only a bunch of random data strings, probably taken from some abitrary memory locations. I should add that I'm in the middle of a major program change, so the program hasn't been compiled in a long time, and that some of these boxes worked fine before the change, which opens up a variety of possible causes for the problem.

In the current version, I have found that for very simple cases, such as using static data fields and hard-coded size descriptors, it works fine. However, as soon as I try to make anything about it dynamic, even if it's only a variable giving the size of the displayed array, the mentioned problem appears.

I'm having problems putting my finger on just what exactly I did differently when it worked. But I will continue to look for differences in working and non-working versions of the situation.

My question now is if anyone has experienced something like that before and can point me in a direction that I might have missed.


On another note, I'm experiencing a similar problem with the '%rs' command: Even though the string is initialized, the 'text field' is actually just a see-through area that displays whatever was visible at that location in the most recently opened other view (such as the desktop or browser). This problem I have just experience today on the mentioned work PC (with Win 2000 Pro), but I assume it's going to be the same on my home laptop.

I just mention this here because these two problems seem similar enough that they might be connected.

Thank you. Rainer

23 Jan 2009 9:05 #4229

This sounds like a programming error. If you post some code for me to look at please make it short and embed it in a complete working program.

23 Jan 2009 3:11 #4230

Hello again.

Here is a short sample program that displays a similar behaviour to what I described yesterday. The only difference is that one of the displayed strings includes the actual string ('DEF') and then adds some apparently random symbols. However, the rest is still totally random or empty.

If I replace the line including '%ls' with either of the currently outcommented lines, the drop down box works normally.

winapp  5000000,5000000

PROGRAM TEST
  use clrwin

  character (len = 5) :: spe(5)
  integer :: nr_spe, sel, in

  spe = (/ 'ABC  ', 'DEF  ', 'GHI  ', 'JKL  ', 'MNO  ' /)
  nr_spe = 5
  sel = 1

  in=winio@('%`ls&', spe(1:nr_spe), nr_spe, sel)
!  in=winio@('%`ls&', spe, 5, sel)
!  in=winio@('%`ls&', spe(1:5), 5, sel)
  in=winio@('')

END PROGRAM TEST
23 Jan 2009 5:57 #4233

The problem is that the text string array that is passed, only needs to have the address of the first element you want to use, and the variable nr_spe specifies how many elements of this array to use.

If you had passed spe(1) and nr_spe=5 then it would also work. You could also pass spe(2) and nr_spe=4, and this would display the list from the second element.

I tried passing your text string to a subroutine, but the routine knew the length of the elements, so perhaps the %ls routine is programmed in another language which is not as clever as Fortran.

Regards

Ian

24 Jan 2009 3:04 #4234

winio@ is written in C. I am not sure if what you experience constitutes a bug or is simply a limitation when passing Fortran arrays.

If you need to use the form spe(1:nr_spe) then you will also need to store it as temporary array before using it.

winapp
PROGRAM TEST 
  character (len = 5) :: spe(5)
  integer :: nr_spe, sel, in, winio@ 
  character (len = 5),allocatable :: tmp(:)
  spe = (/ 'ABC  ', 'DEF  ', 'GHI  ', 'JKL  ', 'MNO  ' /) 
  nr_spe = 5 
  sel = 1
  allocate(tmp(1:nr_spe))
  tmp = spe(1:nr_spe)
  in=winio@('%`ls', tmp, nr_spe, sel) 
END PROGRAM TEST
24 Jan 2009 3:59 #4235

Paul,

I don't think it is a problem, because one would never want to pass the array in the form 'spe(1:nr_spe)' because this is identical to passing either 'spe' or 'spe(1)' and 'nr_spe' as the two required parameters. This is the documented requirements of the Clearwin+ function.

If 'nr_spe' was not a parameter, then maybe it would be an OK method.

Regards

Ian

24 Jan 2009 6:52 #4236

Hi there. Thanks everyone. It's working now. I guess I never really understood where Fortran differentiates between variable and address, so maybe that's the reason I didn't think of this. The examples for %ls and other commands in the book or online reference use the complete string array, so I always thought it was an array being passed. Since in my actual application I placed the strings I wanted to use inside a new data type, I had to specifically insert a ':' at some point anyway, so that it looked something like 'datatype( : )%name'. When the ':' alone didn't work, I guess I was stuck with the explicit array idea. But now I know what to watch out for.

Still, when I used a local array where I just copied the data into, like 'localstrings = datatype(1:N)%name' it didn't work. But now I'm just using a global string array to store the names and it works.

So, thanks again. Rainer

Please login to reply.