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:

SUB
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
     DoEvents
Wend
Close #nFileNum
End Sub
LVL 1
techbnjcompAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
EDDYKTCommented:
i have no problem to run your code.

Just make sure you define I as long
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

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 TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
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.
vinnyd79Commented:
Although it would override the function in the procedure I would rename the val integer as it's the name of a function.
HTorresCommented:
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

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.