Resource files and string arrays

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adam Parkin

    #1

    Resource files and string arrays

    Hello all, I am seeking some help with the following problem. I'm
    working on an application where I have a resource file, and in this
    resource file what I want to store is a list of file names (that is,
    essentially a string array).

    The potential solutions I see are:

    1) Convert the string array into one big string with each element
    separated by some special value, store that string into the resource
    file's string table as a single entry, and then when I load the string
    from the resource file parse it into a regular string array. The
    problem with this is the obvious kludgy-ness of having to generate the
    string, and then re-parse it whenever I want to read it from the
    resource file. But its certainly doable.

    2) To make a custom resource, and store the string array as a custom
    resource, and re-load it back into my application. This seems the more
    elegant solution, but I have no idea how to go about doing this. I
    found a tutorial online to do something similar with an array of longs
    via the CopyMemory API call, but the sample code caused VB to crash on
    me (and I want a solution that's not buggy/unstable).

    3) To use an external file to my application. This is however
    unacceptable for my specific application.

    Any suggestions/tips would be appreciated.

    Thanks,

    Adam
  • Rick Rothstein [MVP - Visual Basic]

    #2
    Re: Resource files and string arrays

    > 1) Convert the string array into one big string with each
    element[color=blue]
    > separated by some special value, store that string into the[/color]
    resource[color=blue]
    > file's string table as a single entry, and then when I load the[/color]
    string[color=blue]
    > from the resource file parse it into a regular string array.[/color]
    The[color=blue]
    > problem with this is the obvious kludgy-ness of having to[/color]
    generate the[color=blue]
    > string, and then re-parse it whenever I want to read it from the
    > resource file. But its certainly doable.[/color]

    I've not worked with Resource File personally, so I can't help you
    out with questions related to it directly. However, combining a
    one-dimensional array into a single String and recovering the
    array back again from the String are very simple things to do in
    VB6.

    Array to String
    =============== =
    Dim YourArray() As String
    Dim Delimiter As String
    Dim CombinedArray As String
    Delimiter = vbTab
    CombinedArray = Join(YourArray, Delimiter)

    String to Array
    =============== ==
    Dim YourArray() As String
    Dim Delimiter As String
    Dim CombinedArray As String
    Delimiter = vbTab
    YourArray = Split(CombinedA rray, Delimiter)

    Rick


    Comment

    • Steve Gerrard

      #3
      Re: Resource files and string arrays


      "Adam Parkin" <pzelnip@hotmai l.com> wrote in message
      news:ho78f.6239 5$Io.5074@clgrp s13...
      [color=blue]
      > The potential solutions I see are:
      >
      > 2) To make a custom resource, and store the string array as a custom resource,
      > and re-load it back into my application. This seems the more elegant
      > solution, but I have no idea how to go about doing this.[/color]

      1. Activate the Resource Editor, by going to Add-Ins, Add In Manager... Find VB
      6 Resource Editor in the list, and check the Loaded/Unloaded checkbox. Close the
      manager form.

      2. Click on Tools, Resource Editor.

      3. In the resource editor, click the "abc" button, with tooltip "Edit String
      Tables..."

      4. For ID 101, enter "First One". Press Enter. For ID 102, enter "Second One".
      etc.

      5. Close the string editor. Click the Save button in the resource editor. Use
      any file name you like.

      6. This will add a resource file to your project, listed under "Related
      Documents". It will be compiled into your executable.

      7. To use a string, use code like this:

      Private Sub Command1_Click( )
      Dim S As String

      S = LoadResString(1 01)
      MsgBox S

      End Sub

      If all is well, you should get the message "First One".

      The big deal with string tables is that you can add a second string table,
      selecting "French (France)" as the locale ID. Then for 101, you enter "Premier".
      If users run your program in France, they will get the message "Premier" instead
      of "First One". Automagically!



      Comment

      • Adam Parkin

        #4
        Re: Resource files and string arrays

        Steve Gerrard wrote:
        [color=blue]
        >7. To use a string, use code like this:
        >
        >Private Sub Command1_Click( )
        > Dim S As String
        >
        > S = LoadResString(1 01)
        > MsgBox S
        >
        >End Sub
        >
        >If all is well, you should get the message "First One".
        >
        >The big deal with string tables is that you can add a second string table,
        >selecting "French (France)" as the locale ID. Then for 101, you enter "Premier".
        >If users run your program in France, they will get the message "Premier" instead
        >of "First One". Automagically!
        >
        >[/color]
        Thanks, but that part I already knew. The problem with this version is
        that if I have 100 entries in the array, I have to create 100 strings in
        the table, which isn't a problem code-size wise but is certainly a data
        entry pain in the #@$@.

        Adam

        Comment

        • Adam Parkin

          #5
          Re: Resource files and string arrays

          Rick Rothstein [MVP - Visual Basic] wrote:
          [color=blue]
          >I've not worked with Resource File personally, so I can't help you
          >out with questions related to it directly. However, combining a
          >one-dimensional array into a single String and recovering the
          >array back again from the String are very simple things to do in
          >VB6.
          >
          >Array to String
          >============== ==
          >Dim YourArray() As String
          >Dim Delimiter As String
          >Dim CombinedArray As String
          >Delimiter = vbTab
          >CombinedArra y = Join(YourArray, Delimiter)
          >
          >String to Array
          >============== ===
          >Dim YourArray() As String
          >Dim Delimiter As String
          >Dim CombinedArray As String
          >Delimiter = vbTab
          >YourArray = Split(CombinedA rray, Delimiter)
          >
          >
          >[/color]
          Sweet, I didn't know VB had Perl-like split & join functions. Thanks!

          Adam

          Comment

          • Rick Rothstein [MVP - Visual Basic]

            #6
            Re: Resource files and string arrays

            > >I've not worked with Resource File personally, so I can't help
            you[color=blue][color=green]
            > >out with questions related to it directly. However, combining a
            > >one-dimensional array into a single String and recovering the
            > >array back again from the String are very simple things to do[/color][/color]
            in[color=blue][color=green]
            > >VB6.
            > >
            > >Array to String
            > >============== ==
            > >Dim YourArray() As String
            > >Dim Delimiter As String
            > >Dim CombinedArray As String
            > >Delimiter = vbTab
            > >CombinedArra y = Join(YourArray, Delimiter)
            > >
            > >String to Array
            > >============== ===
            > >Dim YourArray() As String
            > >Dim Delimiter As String
            > >Dim CombinedArray As String
            > >Delimiter = vbTab
            > >YourArray = Split(CombinedA rray, Delimiter)
            > >
            > >
            > >[/color]
            > Sweet, I didn't know VB had Perl-like split & join functions.[/color]
            Thanks!

            Prior to Version 6, it didn't.

            Rick


            Comment

            Working...