Results 1 to 33 of 33

Thread: Opening files...

  1. #1
    Guest
    Using this:

    Code:
    Dim strTemp As String
    
    Open "C:\Test.txt" For Binary Access Read As #1
    
    strString = Input(FileLen("C:\Text.txt"), #1)
    
    Close #1
    It is incredibly slow. I tried using the get function, but it doesn't work.

    Is there any faster way than this?

  2. #2
    Guest
    According to the kedamanologist , he would want you to use this way:

    Code:
    Dim buffer as String
    Open File for Binary as #1
       buffer = Space(LOF(1))
       Get #1 , , buffer
    Close #1
    Text1 = buffer

  3. #3
    Guest
    That's what I did, Matt, but for some reason it just doesn't put anything into the string. Maybe it's the file I am trying to access...

  4. #4
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    You may want to check out the CreateFile api.



    td.
    "One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig


    tumblingdown@hotmail.com

    "but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.

  5. #5
    Guest
    Maybe it didn't work because you're using strString instead of strTemp?

  6. #6
    Guest
    No no, that was just a typo. And that's the slow one too, I'm looking for a fast one (to open files of around 1 or 2 megs).

  7. #7
    Guest
    Well then, read data in parts. Not everything at once, read more when more is needed. I don't know what kind of program you're making but this is the fastest way.

  8. #8
    Addicted Member
    Join Date
    Feb 2000
    Location
    London, UK
    Posts
    145
    Are we talking about sequential files, like .txt, .htm and such?
    In that case, you could use the RichTextBox and Text.Loadfile MyFileName, where MyFileName is a string containing the full path and name of your file (such as "C:\Windows\Textfile.txt")
    I use it, and it takes only a few seconds for files as large as three of four Mb.

    Try it!
    Pentax
    Wilhelm Tunemyr,
    Swede in London

    wilhelm.tunemyr@swipnet.se

    "Dort, wo man Bücher verbrennt, verbrennt man am Ende auch Menschen"
    Heinrich Heine (1797-1856)

    Pravda vítezi!
    (Truth prevails!)

  9. #9
    Guest
    I sort of need to read the whole thing at once, because it looks for a certain part in the file, which seperates it from the rest. If I read the file in seperate parts, I might miss half of the seperator (which is 16 characters long).

    This is really starting to puzzle me.

  10. #10
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    this is kedaman's code as above and testing it, it works
    find for me.

    Code:
    'Open a file in binary mode and read into a textbox or string
    
        Dim sHolder As String
        Dim intNum As Integer
        Dim sFileName As String
        Dim myString As String
        
        'open for binary and read
        sFileName = "C:\My Documents\MyFile.txt"
        intNum = FreeFile
        
        Open sFileName For Binary As intNum
          sHolder = Space(LOF(1))
          Get #1, , sHolder
        Close intNum
     
        myString = sHolder
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  11. #11
    Guest

    Re: <?>

    Quite the same code as above Wayne, he said it didn't work . Works well for me though.

  12. #12
    Guest
    I still don't get it. It works fine with the input function, but when I use get it doesn't work.

    Just another question, strings can hold up to (or around) 2 gigs can't they? or was it 2 megs?

  13. #13
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Strings hold up 2 gigs, that's correct. 2^31 bytes.

    There might be a problem with your file, first check if the length of file isn't 0, put a break before the get statement and type ?lof(1) in immediate window. That would show that your file is empty.
    BTW, no error messages? The length of the string after get statement?



    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  14. #14
    Guest
    The length of the file is around 2 megs, and I don't get any error messages. The length of the string is the length of the file, but it is all spaces (due to the statement "strTemp = Space(LOF(1))").

  15. #15
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Hmm, that sounds very odd, and it works with input$? that really is strange. well theres another way though, not sure if it would change the situation but may be worth a try.
    Code:
    Dim buffer() as byte
    Open File for Binary as #1
       Get #1 , , buffer
    Close #1
    Text1 = strconv(buffer,vbunicode)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  16. #16
    Guest
    No, it must be the get function that doesn't work all together. Maybe if I reinstall VB, it might work. Problem is it takes too long and I will probably have to restart my computer 1,000 times, just like when installing Windows.

    Why does Windows need to restart lots of times when you install it. It does one little job 'Oh! Have to restart.' Then of course they have the dialog where the only button is 'restart' and if you don't push it the computer will restart in 15 seconds anyway. You'd think it would do everything, and then restart, but it does everything seperately. Must be Microsoft making little things look difficult.

  17. #17
    Addicted Member
    Join Date
    Feb 2000
    Location
    London, UK
    Posts
    145
    Just repeating...
    If you put a RichTextBox on the form, and makes it invisible, you can load the file into it and then into a string. Like this:

    Code:
    Dim filename, 2megs As String
    Text1.Visible = False
    filename = "C:\Windows\MyBigFile.txt" 'or whatever
    Text1.Loadfile filename, rtf 'I am not really sure about 
                                 'rtf, test with and without
    2megs = Text1.Text
    
    'Do whatever you want with your string, instr and so on...
    Try it out!
    Pentax
    Wilhelm Tunemyr,
    Swede in London

    wilhelm.tunemyr@swipnet.se

    "Dort, wo man Bücher verbrennt, verbrennt man am Ende auch Menschen"
    Heinrich Heine (1797-1856)

    Pravda vítezi!
    (Truth prevails!)

  18. #18
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Well Dreamlax, i'm almost sure you don't even have to restart after reinstalling vb, i had to do it once and it never asked for restart. BTW, you can abort the restarting process if you are fast enough, open notepad type a letter. It will ask you to save and press cancel

    It's very strange that Get statement is failing while input$ is working, usually the problem is the reverse case. Try pentax sample to
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  19. #19
    Addicted Member
    Join Date
    Feb 2000
    Location
    London, UK
    Posts
    145
    I checked...
    The correct commandline is
    Code:
    Text1.LoadFile filename
    You shouldn't use rtfText afterwards (while if you want to save text to a file you shall use Text1.SaveFile filename, rtfText).

    Good luck,
    Pentax
    Wilhelm Tunemyr,
    Swede in London

    wilhelm.tunemyr@swipnet.se

    "Dort, wo man Bücher verbrennt, verbrennt man am Ende auch Menschen"
    Heinrich Heine (1797-1856)

    Pravda vítezi!
    (Truth prevails!)

  20. #20
    Guest
    Pentax's code works OK, except when opening files like JPEGs. It displays the file header, and a little bit of whats inside, but it cuts it of (truncates) after about 64 bytes.

  21. #21
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I guess RTB's are sensitive to either EOFmarks or nullchars. The earlier is more probable, JPEG's are stored binary so it's very likely that it will occur. BTW, can i have a look at the file?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  22. #22
    Guest
    No problem, or is there. Hotmail doesn't let you have e-mail attachments over 1 meg or something don't they (and you have a hotmail address, well the one on your signitaure anyway)?

  23. #23
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Well yeah i know hotmail can do something really annoying when i get over 2M. Do you have ICQ or can you upload it somewhere?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  24. #24
    New Member
    Join Date
    Nov 2000
    Posts
    2

    Lightbulb Try this (though it's a bit late)

    Dim buffer (1 to 1000) As Byte
    Dim numFile
    numFile = FreeFile
    Open "patapim.file" For Random as #numfile Len=Len(buffer)


    So that you can read with a buffer of 1000 bytes.
    It's great knowing Quick Basic!

  25. #25
    Guest
    Kedaman, you can download the file here. It's not the JPEG file, but it's one which I am also have trouble loading.

    Dreamlax Entertainment Video


    That's just a little video I put at the beginning of some other videos.

  26. #26
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    seems to be no problem with the file, the first 100 bytes:

    RIFF2ó AVI LIST~" hdrlavih8     @ đ LIST” strl
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  27. #27
    Addicted Member
    Join Date
    Feb 2000
    Location
    London, UK
    Posts
    145
    Hmmm.
    I tested to open a Jpeg and save as another name, and it worked (When opening the file the picture displayed allright).

    But maybe that's not the problem?
    Wilhelm Tunemyr,
    Swede in London

    wilhelm.tunemyr@swipnet.se

    "Dort, wo man Bücher verbrennt, verbrennt man am Ende auch Menschen"
    Heinrich Heine (1797-1856)

    Pravda vítezi!
    (Truth prevails!)

  28. #28
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    seems like the right topic

    Anybody know how i can scan a folder of files and collect the bytesize of all in the directory.. do i use FileLen?

    Many Thanks

  29. #29
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Yes, you loop trough all files using dir function and add up filelen into sum:
    Code:
    dim a$,sum&
    a=dir(path)
    do while len(a)
      sum=sum+filelen(a)
      a=dir
    loop
    debug.?sum
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  30. #30
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    mmmH

    Nothing happens, whats wrong with this, a =0 so exits.

    destPath = "d:\" + "releaseCD" + "\" + "netVESPA" + "\" + "5.2.0.0" + "\" + "NTT" + "\" + "Documentation" + "\" + "Manuals" + "\"

    VALID PATH WITH FILES IN.

    a = Dir(destPath)
    Do While Len(a)
    result = result + FileLen(a)
    a = Dir
    Loop
    Debug.Print result

  31. #31
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446

    ignore last message this is problem

    I get the message file not found at:


    result = result + filelen(a)

    the a is equal to the first file but wont proceed?




  32. #32
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    a should be declared as string, to contain the filename, i'm sorry if that appeared unclear Dir returns the first file only if you specify a new path, otherways it returns the next file until theres no files left, then it returns a nullstring, and therefore the loop ends.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  33. #33
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446
    HERE IT IS. CHEERS PATH NEEDED APPEND TO FILE

    Dim result&
    Dim a$
    destPath = filePaths.CDImageLocation + "\" + curRecord.ProductDIR + "\" + curRecord.versionText + "\" + curRecord.CustomerID + "\" + "Documentation" + "\" + "Manuals" + "\"
    'destPath = "e:\" + "releaseCD" + "\" + "netVESPA" + "\" + "5.2.0.0" + "\" + "NTT" + "\" + "Documentation" + "\" + "Manuals" + "\"

    a = Dir(destPath)
    Do While Len(a)
    result = result + FileLen(destPath + a)
    a = Dir
    Loop

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width