Announcement

Collapse
No announcement yet.

Random Write - Variable - Example Bug

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

  • #21
    Borje,
    Im so sorry, you are right. I was having difficulty seeing what you did. This will work great. I rewrote it a little for my needs and for anyone following this thread later.

    Thank you all so much. I got there - eventually!

    #COMPILE EXE "Random.exe"
    GLOBAL Header AS STRING * 10 '<- determins length of header line
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤'
    FUNCTION PBMAIN
    Local I AS LONG, Contents AS STRING
    '---------------------------------'Create a file
    OPEN "RANDOM.DTA" FOR OUTPUT AS #1
    Header = "Header-to-be-overwritten" '<- Only first 10 chars will be written
    PRINT #1, Header
    FOR I = 1 TO 13
    WRITE #1, I,0,0,454,22,0,0,34,54,1,1,0,0
    NEXT
    CLOSE #1
    '------------------------------' Show file Contents
    OPEN "RANDOM.DTA" FOR BINARY AS #1
    Contents = SPACE$(LOF(1))
    GET #1,, Contents
    CLOSE #1
    MSGBOX Contents
    '---------------------------------'Change header
    OPEN "RANDOM.DTA" FOR BINARY AS #1 BASE = 0
    Header = FORMAT$(I-1)+"-Lines-in-this-file" '<- New text - Only first 10 chars will be written
    SEEK #1, 0 '<- set position to Beginning of first record
    PUT #1,, Header '<- put the new string (Must be the same length! - 10 Chars)
    CLOSE #1
    '------------------------------' Show file Contents
    OPEN "RANDOM.DTA" FOR BINARY AS #1
    Contents = SPACE$(LOF(1))
    GET #1,, Contents
    CLOSE #1
    MSGBOX Contents

    END FUNCTION
    '-------------------------------------------

    ------------------
    Kind Regards
    Mike

    Comment

    Working...
    X