Consulting

Results 1 to 14 of 14

Thread: Solved: Store Strings in Macro

  1. #1

    Solved: Store Strings in Macro

    I am building an app that combines a 5000 word text list in various ways outputting millions of combinations. The text list is currently stored in a .txt file, where works just fine.

    However, isn't there always a however.... I'd like to wrap this text file somehow in my project so when I lock it, the end user can't see my word list. (it would allow them to basically cheat)

    Thanks !
    Dan

  2. #2
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    In short, there isn't an "official way" to do that. VBA projects don't support resource files. (Unless someone knows something I don't). The only way I can think of to meet those parameters is non-trivial. You could encode the words in a bitmap and store the bitmap in the word file. But if you have never worked with data at a byte level you might find that one a little rough. If it were me I would just scramble the text file up a bit so it's not human-readable and then have your program unscramble it on the fly.
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  3. #3
    Darn, Shucks... All those hardend words.... I've done byte level stuff but it's been 10 years or so, noting like that, and my mind is twisted enough with this project already. I appreciate the expert advice. I suppose I should take solice in the fact that you didn't say rtfm. <smile> I've chosen an unelegent solution of creating 2 modules, one to hold 3000 words, and the other for the rest, seems there's a size limitation on modules somewhere around 3 and 4K. So now the text file is formatted like this
    ObjectData(1) = "bla-word"
    ObjectData(2) = "Sam-test"
    up to ObjectData(5030).
    And I paste it to a Module. I played with Containers, but I actually understand the array<smile> thanks again!
    Dan

  4. #4
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    That's best case really. I would have suggested it, but I wasn't sure if they would all fit (Had the same problem myself a while back and they didn't all fit)
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  5. #5
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    just scramble the text file up a bit so it's not human-readable and then have your program unscramble it on the fly.
    I've done this in the past. Shift the ASC value of each letter by the length of the word worked for me.

    Quote Originally Posted by danvanf
    So now the text file is formatted like this
    ObjectData(1) = "bla-word"
    ObjectData(2) = "Sam-test"
    up to ObjectData(5030).
    I have something simlier (but smaller) and setup a element variable.

    aCnt = 1
    ObjectData(aCnt) = "bla-word": aCnt = aCnt + 1
    ObjectData(aCnt) = "Sam-test": aCnt = aCnt + 1

    This way, if I needed to insert another line in the middle, I wouldn't have to painfully renumber everything.

    David


  6. #6
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Yah, it's easy to ad-hoc something up as "better than nothing". The only thing I would say is "Don't believe it's encryption." It just not human readable without some effort.

    The other concern, is that if you store the information in the module as string literals even if you password protect the document and the vbProject... The literals will not be encrypted. Meaning you can open up the document in notepad and read the list fairly easily. I don't know how advanced your cheaters are, but that seems like a low entry barrier to me (Which, btw, is one of the many reasons why you should never ever "hard code" a password.

    So even if you store them in the module, you might consider obfuscating them a little
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  7. #7
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Dan,

    Another alternative which is more hidden then the above alternatives is to store the values as metadata in the variables collection of the document.

    Like:
    [vba]
    ActiveDocument.Variables.Add Name:="Value1", Value:="1"
    MsgBox ActiveDocument.Variables("Value1")
    [/vba]

    HTH
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  8. #8
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Hi Joost,
    The only thing on that, is doc variables don't get encrypted either. They are still stored in the document (in plain text) for all to see. If you define a variable named "Foo" with a value of "Bar" then password protect and encrypt the document (and the vba project) it will still look like this in Notepad:
     Foo ?  Bar
    So even if you do go that route, you will still want to obfuscate the value for storage to defeat the "notepad attack"


    Edit:
    Although as someone who spends their time in Access, Excel & Outlook, I was totally unaware that of the Document.Variables collection. I'm really glad to know about it. That would totally useful for storing persistent values without using the registry. And the fact that they stay in the document is even better then the reg (IMO) because the data can go with the document instead of being lost between computers.
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  9. #9
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Aaron,
    Quote Originally Posted by Oorang
    The only thing on that, is doc variables don't get encrypted either. They are still stored in the document (in plain text) for all to see. If you define a variable named "Foo" with a value of "Bar" then password protect and encrypt the document (and the vba project) it will still look like this in Notepad:
    Sure, agreed in full there's no such thing as protection in Office so variables aren't an exception. (allthough they are a bit more hidden, when you don't know what your looking for)

    Quote Originally Posted by Oorang
    Although as someone who spends their time in Access, Excel & Outlook, I was totally unaware that of the Document.Variables collection. I'm really glad to know about it.
    Indeed, this is one of those unknown jems in MS Word that little know about. It's the best mechanisme for saving data as Metadata in the document that is transported with the document wherever it goes.

    I'm glad I could share it with you!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  10. #10
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    "It's the best mechanisme for saving data as Metadata in the document "

    Is it not really the ONLY mechanism for storing persistent data in a Word doc? That is the purpose of the Variables collection. From Help:

    "Document variables are used to preserve macro settings in between macro sessions."

    Although, really, "settings" is too narrow a word. And not specific enough. Document Variables store strings.

    Is there another way to hold persistent data? I mean, actually in a document.

  11. #11
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Gerry,

    No, it's not realy the only mechanisme to do this.
    You also have something like Customdocument properties you can set on a document. (they can hold data as well)

    But I like variables better because you can't see them. (easily) You can see custom document properties.
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  12. #12
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Ummmmm.....






    doh.

    Yes CustomDocumentProperties will persist as well. And yes, of course you are right, they can definitely be considered as containers for persistent data.

    I am like you, I prefer Variables, and for the same reason.

  13. #13
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Glad to here where on the same page Gerry! (I wonder how many Word VBA coders already use these variables)
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  14. #14
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Actually, I think a fair amount of them.

Posting Permissions

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