Results 1 to 17 of 17

Thread: [RESOLVED] Add text file to project

  1. #1

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Resolved [RESOLVED] Add text file to project

    Is there a way to store a large amount (816,000 characters) of text in my project that can easily be used? I need it to be loaded into a text box at startup, but if I copy+paste it in @ design time, it only holds the first 32,000 or so characters (though funny enough it can hold all the data if added at run-time). I tried storing the text in a module, but I would have to add a hell of a lot of '& _' s to it and I want it to be more easily edited/overwritten. I then tried adding it to a resource file as a binary data, but when I try to show that in the text box it all turns into ?'s and boxes. Is there a way to simply 'add' this file to the project so it can either be loaded into a string variable array or a text box?
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  2. #2
    Banned learning c's Avatar
    Join Date
    Mar 2007
    Location
    canberra (australia's capital)
    Posts
    198

    Re: Add text file to project

    this is a good startpoint:http://vb-helper.com/howto_read_write_binary_file.html

    once you get it up and running you need to buffer the binary read and write into smaller chunks so that if you have a large file it doesn't try and load all of the file into ram at once and slow down or kill your pc.

  3. #3

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Re: Add text file to project

    Hmmm, I never thought of temporary files, but I think this would be a last resort (i hate using temp files). Is there a way to read it right from the resource to the text box?
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  4. #4
    Banned learning c's Avatar
    Join Date
    Mar 2007
    Location
    canberra (australia's capital)
    Posts
    198

    Re: Add text file to project

    what's a resource file?

  5. #5

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Post Re: Add text file to project

    like a file that holds all your files and you can get your fies from it whenever you need them, however it's not storing/retrieving a text file as text. I need to know how to store it as text in a resource file or read the text file from it as text. This sound's easy, but is being hard, is ther a mod or experienced user on this subject? RobDog? Pino? Hack? RinoBull?
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  6. #6

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Unhappy Re: Add text file to project

    So does anyone have an idea?
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  7. #7

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Re: Add text file to project

    Please? I just think it's too slow to write such large tmp files. Perhaps I'm wrong, I will try when I get a free moment. Is there not a way to open the text file from a res file to a text box? Do I need to put it in a string first then encode/decode it? The best case scenario in my mind is to be able to change the max length of a string in a text box @ design time
    Last edited by ididntdoit; May 26th, 2007 at 10:11 PM.
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  8. #8
    Addicted Member
    Join Date
    Mar 2007
    Posts
    203

    Re: Add text file to project

    Is there any reason that you can't just include the text file in your .cab file and read it from wherever you tell the .cab file to place it on the hd?

  9. #9

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Re: Add text file to project

    1) I don't want extra files lying around - there is only the executable, nothing else for my entire program

    2) it'a a standalone. No installation = no .cab = it must be in the exe
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  10. #10
    Banned learning c's Avatar
    Join Date
    Mar 2007
    Location
    canberra (australia's capital)
    Posts
    198

    Re: Add text file to project

    i'd just load the text into the app and xor it for some protection, but this link may suit your needs?
    http://visualbasic.about.com/od/usevb6/a/ResVB6_3.htm

  11. #11

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Re: Add text file to project

    pls read my post - I don't want an external file. I know how to read fies, but I don't know haw to read them out of a res file!
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  12. #12
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Add text file to project

    No installation = guaranteed failure on many PCs.

    VB programs require several specific files (DLL's, etc), and if they aren't installed (Windows 2000 or earlier, unless they were installed by other programs/service packs), your program will fail to even start.

    If the wrong versions have been installed (if somebody else installed the 'wrong' ones with their program, or you use different versions to XP's pre-installed ones), your program will be likely to have random errors.

  13. #13

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Re: Add text file to project

    O.K., there might end up being an installation, but I don't want extra files lying around - especially ones that could become accidentally modified or moved or something. Is it really that hard to just read the text file form the .res file? I opened the .res file in notepad and it was identical to the text file but had some extra junk at the beginning. How can I load the data form the .res file into a text box/string (as text)?
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  14. #14
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Add text file to project

    If a user moves/deletes a file from your programs directory, they shouldn't be surprised when your program fails. As to modifying, you could easily encrypt the file and add a checksum (or similar) to ensure that your program refuses to accept their modifications.

    As to actually loading a file from a resource into a string, this is what I use:
    Code:
    strTemp = LoadResData("MyFile", 256)

  15. #15

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Re: Add text file to project

    I tried this, but I got a text box full of ?'s and lines and odd characters and it was MUCH MUCH shorter than the regular text file. This seemed very funny to me since if I rename pd.res to pd.txt and open it in notepad it's identical to the text file that I put in it (excluding some junk at the top). Is it somehow encoded or compressed? I haven't changed any default settings of notepad, should I?

    BTW, thx for the resopnses

    also - I'm not worried that the file will be modified to purposely harm my program, it's sort of like a huge database in text format and my program makes that data useful and comparable for analysis. However, reading the text into variables and arrays is kind of tricky since it's designed to be visually nice (ascii art, etc.) that can be hard to make out. Any changes would simply cause my program to go nuts and probably crash. I'm seeing a general trend here - an external text file MIGHT be more usefull. However, I would like to be able to do it from a res file and be able to decide that better.
    Last edited by ididntdoit; May 28th, 2007 at 09:31 PM.
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  16. #16

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Talking Re: Add text file to project

    MUAHAHAHAH! HEHEHAHAHAH! YEAH! I fixed it!!!!! I saved the text file as unicode instead of the default ANSI and it works perfectly!!! AWSOME! (sorry for shouting, I'm just happy - this has been bugging me for a while). I knew the answer was simple, I just couldn't find it. It was a combo of info in the MSDN, a good guess, and rechecking the facts. I realised that the fact that it was shorter in the res file meant that either it wan't all their or it was being partially skipped. I checked with ResHacker and it was all there, but when I thought about it, I realized it could be shorter by reading too much data at once (a problem i had making this program). I remembered that Unicode is 2 bytes instead of 1, and I remember reading comething about this in MSDN, so I tried string conversion, but when it failed I assumed I was wrong. I guess I just wasn't converting right! Thanx guys! (if you get me ranting long enough, I usually can answer my own questions )


    Resolved
    Visit here to learn to make the VB interface fit you!.
    "I have not failed 10,000 times. I have successfully identified 10,000 ways that will not work" Thomas Edison
    "The day Microsoft makes something that doesn't suck is probably the day they start making vacuum cleaners" -- Ernst Jan Plugge

  17. #17
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: [RESOLVED] Add text file to project

    I don't think I had to do that in my case, but good work in solving it!

    Thanks for sharing the solution!

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