Re: LEN() of unallocated array

From: Rich Townsend (rhdt_at_XXXXX.udel.edu)
Date: 11/06/03


Date: Thu, 06 Nov 2003 09:41:44 -0500

David Frank wrote:
> "Rich Townsend" <rhdt@XXXXX.udel.edu> wrote in message

<snip>
>
> It has nothing to do with LEN,
> I dont believe your intention to directly output a string "hello
> world"
> into a allocatable string array is going to work..
>
> CVF compiles above ok, but has a runtime access error on execution.
> To illustrate what you are doing wrong, I rewrote your subroutine
> (see below) which DOES run ok under CVF and illustrates what you
> are doing wrong
> ( outputting a 15char string into the wrong array index.
>
> ! ---------------------------------
> program test
> character, allocatable :: a(:,:)
> call my_sub(a)
> write (*,*) a ! outputs Hello Hello Hello
>
> contains
> subroutine my_sub(a)
> character, allocatable :: a(:,:)
> character :: b(6) = ['H','e','l','l','o',' ']
> allocate ( a(6,3) )
>
> do i = 1,3
> a(:,i) = b ! note storing into left index
> end do
> end subroutine my_sub
> end program test
>
>

I can't see how this illustrates what I'm doing wrong. You've replaced
my array of character strings with a 2-D array of length-1 strings, but
beyond that I'm not sure what you are trying to demonstrate. Are you
arguing that the assignments in my original code:

b = 'Hello'

a = b

...are causing the problem? Surely the latter is handled by the rules
for broadcasting a scalar to an array?

Could you try running my original program again with CVF, but change the
declaration of b to:

character(15) :: b

This should establish whether the LEN() is causing the problem or not.

cheers,

Rich



Relevant Pages

  • Re: String Array Insert
    ... I should have renamed the second subroutine differently from the first one I posted... ... Dim Position As Long ... Dim Combined As String ... following code, albeit somewhat slower than my original one-liner (which won't matter unless you are using this in a large loop against a very large array), will insert one or more empty elements at the element index number specified in the 2nd optional argument. ...
    (microsoft.public.vb.general.discussion)
  • Help in French|Spanish|German translation.
    ... I am also an author of User-defined string functions. ... WORDTRANEX (cSearched, cArExpressionSought | cExpressionSough, ... each string of the array is searched ... If the parameter nArStartOccurrence is -1 or omitted, the replacement starts ...
    (microsoft.public.fox.helpwanted)
  • Re: passing a string to a dll
    ... Joe, I really appreciate you taking the time to demonstrate this. ... sure how I would implement indexing it for random alphanumeric codes. ... I might handle the array. ... I actually have been wondering if I could use a second string ...
    (microsoft.public.vc.mfc)
  • Re: passing a string to a dll
    ... I might handle the array. ... I actually have been wondering if I could use a second string ... look at insertion cost, organization cost, and search cost. ...
    (microsoft.public.vc.mfc)
  • Re: Array Type Mismatch
    ... Dim resultAs String ... I am still somewhat confused as to why nothing is stored in the array. ... Public Function TextBoxGetLine(....arguments... ...
    (microsoft.public.access.formscoding)