Announcement

Collapse
No announcement yet.

Can someone tell me...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can someone tell me...

    Hello all!

    Can someone tell me why so many people use SPACE$ to presize a string before a file GET or TCP RECV? Am I really supposed to do that or is this done "just in case"? If the GET/TCP RECV calls return a string of a given size then why would you need to presize the string?

    Code:
    buffer = space$(len(datablock))
    get hfile,,buffer
    
    or
    
    buffer = space$(len(datablock))
    tcp recv hsock, len(datablock), buffer
    Cheers!

  • #2
    Under Windows, many functions require a pre-initialized string, which means the string must have a length. The only way to give a string a length is to assign some characters to it. SPACE$ is handy.

    (There could be a long, drawn-out technical explanation of memory allocation and the local process workspace here, but it would put at least one of us to sleep. Just stick with the above).

    MCM


    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Gotcha! thanks for the reply...

      ------------------

      Comment

      Working...
      X