By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,025 Members | 2,118 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,025 IT Pros & Developers. It's quick & easy.

Resource files and string arrays

P: n/a
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
Oct 27 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
> 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.


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(CombinedArray, Delimiter)

Rick
Oct 27 '05 #2

P: n/a

"Adam Parkin" <pz*****@hotmail.com> wrote in message
news:ho78f.62395$Io.5074@clgrps13...
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.


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(101)
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!

Oct 28 '05 #3

P: n/a
Steve Gerrard wrote:
7. To use a string, use code like this:

Private Sub Command1_Click()
Dim S As String

S = LoadResString(101)
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!

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
Oct 28 '05 #4

P: n/a
Rick Rothstein [MVP - Visual Basic] wrote:
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(CombinedArray, Delimiter)

Sweet, I didn't know VB had Perl-like split & join functions. Thanks!

Adam
Oct 28 '05 #5

P: n/a
> >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 inVB6.

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(CombinedArray, Delimiter)

Sweet, I didn't know VB had Perl-like split & join functions.

Thanks!

Prior to Version 6, it didn't.

Rick
Oct 28 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.