fumbling with string lists

C

Christy Davids

OK, I confess. I'm really a Palm OS developer. I just
play a .NET developer on TV. :)

My problem is to programmatically create a resource with a
string list, which needs to be readable and writable.
I've been using code like this to do the reading:

Dim reader As ResXResourceReader = New ResXResourceReader
(SYS_STRINGS_FILEPATH)
Dim entry As DictionaryEntry
For Each entry In reader
tempResArray(resNum, 0) = entry.Key.ToString()
tempResArray(resNum, 1) = entry.Value.ToString()
resNum += 1
Next
reader.Close()

I get an "Object reference not set to an instance of an
object" error at entry.Key.ToString() in the first pass
through the For loop.

Stepping back to what I'm trying to do just a bit, the
reason for populating the array from the
ResXResourceReader is because when I try to add a string
to the resource list it seems to overwrite any strings
already in the file. So I am reading first, then writing
the original entries back out with a ResXResourceWriter.
Something like this:

Dim rw As ResXResourceWriter = New ResXResourceWriter
(SYS_STRINGS_FILEPATH)

resName = "System" & resNum
For i = 0 To resNum - 1
rw.AddResource(tempResArray(i, 0), tempResArray(i, 1))
Next
rw.AddResource(resName, dirName)
rw.Close()
rw.Dispose()

Is this really how you have to do it? It seems like there
must be a better approach. For example, what if I wanted
to delete a string from the list? I notice there's no
DeleteResource method for ResourceWriter or
ResXResourceWriter. All I'm trying to do is maintain and
access a simple list of strings at runtime.

TIA! :)
Christy
 
C

Christy Davids

Got it.

Not sure if I understand why I was getting that particular
error, but I switched over to using a Hashtable instead of
an array and everything seems to be working fine now. Also
cleaner code. Hashtables... what a concept! :)

I also found out from s/o at MS that you really *do* have
to write the whole resource file out again every time you
want to add, delete, or modify something in it. With all
the wonderful things you can do with XML, why aren't they
doing them? Maybe in the next rev.

Christy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top