• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

Writing Binary maximum size file

I want to write a binary file that is compact to use for ftp testing.  What I "think" I want is a file full of binary 1's.   I tried writing code and when run it seems that run okay but the final file is zero bytes.  below is an experiment which I would of thought would of had 50000 "HELLO" 's in it.  in reallity it has one and file size is small.  What am I doing wrong:

codeDim nFileNum As Integer
nFileNum = FreeFile
Open App.Path & "example.bin" For Binary Access _
 Write Lock Read Write As #nFileNum
I = 0
While i <> 500000
     Put #nFileNum, , "1"
     I=I+ 1
    Text1.Text = i
Close #nFileNum
End Sub
1 Solution
Hi techbnjcomp,

Dim nFileNum As Integer
nFileNum = FreeFile
Open "c:\example.bin" For Binary Access _
 Write Lock Read Write As #nFileNum
 Put #nFileNum, , String(50000, "1")
Close #nFileNum

Is easier and quicker (and seems to work).

Tim Cottee
techbnjcompAuthor Commented:
Is a "1" what I want? or is that going to put in an equvalent of 50000 "00110001"'s in file
i have no problem to run your code.

Just make sure you define I as long
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

techbnjcompAuthor Commented:
i have no problems with code.   sorry must of misworded my question.  I want to know if I want a file with the most possible bits turned on (i.e. all 1's) do I want a "1" in my put statement or is that one a asci character which is going to be converted to binary.?  does that make sense?
Mike TomlinsonMiddle School Assistant TeacherCommented:
You want:

Private Sub Command1_Click()
    Dim i As Long
    Dim val As Integer
    Dim ff As Integer
    val = -1 ' Hex "FF"
    ff = FreeFile
    Open "c:\someFile.dat " For Binary Access Write As #ff
    For i = 1 To 50000
        Put #ff, , val
    Next i
    Close #ff
End Sub
Mike TomlinsonMiddle School Assistant TeacherCommented:
If you open the file in a hex editor you will see all "FF"s...which is every bit turned on...or all binary 1s.
Although it would override the function in the procedure I would rename the val integer as it's the name of a function.
hi Tech

seems the file is fine, so  ensure you are using "binary transfer" in the ftp program you are using.... ... if I understand correctly the fine is fine untill you ftp it.

that happens.

hope this helps


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now