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
Who is Participating?
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
TimCotteeHead of Software ServicesCommented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

i have no problem to run your code.

Just make sure you define I as long
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:
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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.