Writing Binary maximum size file

Posted on 2006-04-12
Last Modified: 2010-05-01
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
Question by:techbnjcomp
    LVL 44

    Expert Comment

    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
    LVL 1

    Author Comment

    Is a "1" what I want? or is that going to put in an equvalent of 50000 "00110001"'s in file
    LVL 26

    Expert Comment

    i have no problem to run your code.

    Just make sure you define I as long
    LVL 1

    Author Comment

    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?
    LVL 85

    Accepted Solution

    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
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    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.
    LVL 28

    Expert Comment

    Although it would override the function in the procedure I would rename the val integer as it's the name of a function.
    LVL 4

    Expert Comment

    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now