473,320 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How do I extend My.Resources

I am using My.Resources (VS2005) to build all messages that my application
displays to the user. Often I like to embed a new line character in the
middle of the string to make it more readable. Currently I do this by typing
a place holder in the string value when I type it into the resource editor
(e.g. <NL>), and then when I use the string I replace the place holder like
this:

MsgBox(My.Resources.SomeCustomMessage.Replace("<NL >", vbNewLine)

This works, but of course I need to remember to do the Replace each time. I
could wrap all my calls to My.Resources in a function like this:

MsgBox(ReplaceNL(My.Resources.SomeCustomMessage))

but this appears very clusy to me. Is there some better way to handle this
that you .Net gurus can see that I can't.
Apr 11 '06 #1
4 1351
You can use shift+enter to enter a NewLine,

Hope this helps,

Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"David" <Da***@discussions.microsoft.com> schreef in bericht
news:CD**********************************@microsof t.com...
I am using My.Resources (VS2005) to build all messages that my application
displays to the user. Often I like to embed a new line character in the
middle of the string to make it more readable. Currently I do this by typing a place holder in the string value when I type it into the resource editor
(e.g. <NL>), and then when I use the string I replace the place holder like this:

MsgBox(My.Resources.SomeCustomMessage.Replace("<NL >", vbNewLine)

This works, but of course I need to remember to do the Replace each time. I could wrap all my calls to My.Resources in a function like this:

MsgBox(ReplaceNL(My.Resources.SomeCustomMessage))

but this appears very clusy to me. Is there some better way to handle this
that you .Net gurus can see that I can't.

Apr 11 '06 #2
Peter,

Thanks for the response, that certainly helps solve the new line problem,
but there's actually a bit more to this problem that I left out so as not to
overly complicate my question. I have also spent a bit more time on it so
here is an update.

As well as the new line placeholders, some of my resource strings also
include placeholders that need to be replaced with a value at run time. For
example:

"The file '<filename>' already exists. Do you want to replace it?"

At run time I would then call:

MsgBox(My.Resources.FileExistsPrompt.Replace("<fil ename>", FileNameVariable))

I thought the best way to solve this problem would be to create my own class
that inherits from My.Resources and then provide an override to any resource
items that included replaceable parameters. Then I would be prompted to
provide the parameter whenever I used that resource item. Eg.

Public Overrides ReadOnly Property FileExistsPrompt(Byval FileName as
String) As String
Get
Return FileExistsPrompt.Replace("<filename>", FileName)
End Get
End Property
....

Then I would simply call:

MsgBox(My.Resources.FileExistsPrompt(FileNameVaria ble))

However, I am not able to inherit from My.Resources because it has been
implemented as a module. Is there any way around this?

BTW, I am relatively new to .Net and often find myself stuck in the old
(procedural) way of doing things. If there is a simpler approach to this
issue a pointer in the right direction would be greatly appreciated.
"Peter Proost" wrote:
You can use shift+enter to enter a NewLine,

Hope this helps,

Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"David" <Da***@discussions.microsoft.com> schreef in bericht
news:CD**********************************@microsof t.com...
I am using My.Resources (VS2005) to build all messages that my application
displays to the user. Often I like to embed a new line character in the
middle of the string to make it more readable. Currently I do this by

typing
a place holder in the string value when I type it into the resource editor
(e.g. <NL>), and then when I use the string I replace the place holder

like
this:

MsgBox(My.Resources.SomeCustomMessage.Replace("<NL >", vbNewLine)

This works, but of course I need to remember to do the Replace each time.

I
could wrap all my calls to My.Resources in a function like this:

MsgBox(ReplaceNL(My.Resources.SomeCustomMessage))

but this appears very clusy to me. Is there some better way to handle this
that you .Net gurus can see that I can't.


Apr 12 '06 #3
Hi again, I haven't got vs2005 sot I can't test with the my namespace but I
would use a general function something like this

Private Function ReplaceInString ( yourMessage as String, parameter as
String, myValue as string) as String
return replace(yourMessage, parameter, myValue)
End Function

this way you only have got one Function, but as you said before you don't
need to forget to call it, but again I haven't got VS2005 so I can't tell
you if there is a better solution in 2005

Greetz Peter
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"David" <Da***@discussions.microsoft.com> schreef in bericht
news:92**********************************@microsof t.com...
Peter,

Thanks for the response, that certainly helps solve the new line problem,
but there's actually a bit more to this problem that I left out so as not to overly complicate my question. I have also spent a bit more time on it so
here is an update.

As well as the new line placeholders, some of my resource strings also
include placeholders that need to be replaced with a value at run time. For example:

"The file '<filename>' already exists. Do you want to replace it?"

At run time I would then call:

MsgBox(My.Resources.FileExistsPrompt.Replace("<fil ename>", FileNameVariable))
I thought the best way to solve this problem would be to create my own class that inherits from My.Resources and then provide an override to any resource items that included replaceable parameters. Then I would be prompted to
provide the parameter whenever I used that resource item. Eg.

Public Overrides ReadOnly Property FileExistsPrompt(Byval FileName as
String) As String
Get
Return FileExistsPrompt.Replace("<filename>", FileName)
End Get
End Property
...

Then I would simply call:

MsgBox(My.Resources.FileExistsPrompt(FileNameVaria ble))

However, I am not able to inherit from My.Resources because it has been
implemented as a module. Is there any way around this?

BTW, I am relatively new to .Net and often find myself stuck in the old
(procedural) way of doing things. If there is a simpler approach to this
issue a pointer in the right direction would be greatly appreciated.
"Peter Proost" wrote:
You can use shift+enter to enter a NewLine,

Hope this helps,

Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"David" <Da***@discussions.microsoft.com> schreef in bericht
news:CD**********************************@microsof t.com...
I am using My.Resources (VS2005) to build all messages that my application displays to the user. Often I like to embed a new line character in the middle of the string to make it more readable. Currently I do this by

typing
a place holder in the string value when I type it into the resource editor (e.g. <NL>), and then when I use the string I replace the place holder

like
this:

MsgBox(My.Resources.SomeCustomMessage.Replace("<NL >", vbNewLine)

This works, but of course I need to remember to do the Replace each time.
I
could wrap all my calls to My.Resources in a function like this:

MsgBox(ReplaceNL(My.Resources.SomeCustomMessage))

but this appears very clusy to me. Is there some better way to handle

this that you .Net gurus can see that I can't.


Apr 12 '06 #4
David,
In addition to the other comments:

Instead of:

| "The file '<filename>' already exists. Do you want to replace it?"

Consider:

| "The file '{0}' already exists. Do you want to replace it?"

Then you can use:

| MsgBox(String.Format(My.Resources.FileExistsPrompt , FileNameVariable))
Some advantages of String.Format over Replace include but are not limited
to:

- String.Format is built into the Framework & more importantly leveraged by
formatable types such as Integer & Decimal.

For example, you can format currency types:

Dim format As String = "Total: {0:C}"

Dim value As String = String.Format(format, 123.3456D)

- Other types, such as Console.Write & StringBuilder.AppendFormat also
understand the formatting.

Console.Write(format, 123.3456D)

Dim sb As New StringBuilder
sb.AppendFormat(format, 123.3456D)
- Multiple place holders are supported in a single pass:

Dim format As String = "Total: {0:C}, {1}, {2}"

Dim value As String = String.Format(format, 123.3456D, "a", "b")
For details on formatting in .NET see:

http://msdn2.microsoft.com/en-us/lib...9x(VS.80).aspx

For composite formatting (the {0} syntax above) see:

http://msdn2.microsoft.com/en-us/lib...wd(VS.80).aspx
--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"David" <Da***@discussions.microsoft.com> wrote in message
news:92**********************************@microsof t.com...
| Peter,
|
| Thanks for the response, that certainly helps solve the new line problem,
| but there's actually a bit more to this problem that I left out so as not
to
| overly complicate my question. I have also spent a bit more time on it so
| here is an update.
|
| As well as the new line placeholders, some of my resource strings also
| include placeholders that need to be replaced with a value at run time.
For
| example:
|
| "The file '<filename>' already exists. Do you want to replace it?"
|
| At run time I would then call:
|
| MsgBox(My.Resources.FileExistsPrompt.Replace("<fil ename>",
FileNameVariable))
|
| I thought the best way to solve this problem would be to create my own
class
| that inherits from My.Resources and then provide an override to any
resource
| items that included replaceable parameters. Then I would be prompted to
| provide the parameter whenever I used that resource item. Eg.
|
| Public Overrides ReadOnly Property FileExistsPrompt(Byval FileName as
| String) As String
| Get
| Return FileExistsPrompt.Replace("<filename>", FileName)
| End Get
| End Property
| ...
|
| Then I would simply call:
|
| MsgBox(My.Resources.FileExistsPrompt(FileNameVaria ble))
|
| However, I am not able to inherit from My.Resources because it has been
| implemented as a module. Is there any way around this?
|
| BTW, I am relatively new to .Net and often find myself stuck in the old
| (procedural) way of doing things. If there is a simpler approach to this
| issue a pointer in the right direction would be greatly appreciated.
|
|
| "Peter Proost" wrote:
|
| > You can use shift+enter to enter a NewLine,
| >
| > Hope this helps,
| >
| > Greetz Peter
| >
| > --
| > Programming today is a race between software engineers striving to build
| > bigger and better idiot-proof programs, and the Universe trying to
produce
| > bigger and better idiots. So far, the Universe is winning. (Rich Cook)
| >
| > "David" <Da***@discussions.microsoft.com> schreef in bericht
| > news:CD**********************************@microsof t.com...
| > > I am using My.Resources (VS2005) to build all messages that my
application
| > > displays to the user. Often I like to embed a new line character in
the
| > > middle of the string to make it more readable. Currently I do this by
| > typing
| > > a place holder in the string value when I type it into the resource
editor
| > > (e.g. <NL>), and then when I use the string I replace the place holder
| > like
| > > this:
| > >
| > > MsgBox(My.Resources.SomeCustomMessage.Replace("<NL >", vbNewLine)
| > >
| > > This works, but of course I need to remember to do the Replace each
time.
| > I
| > > could wrap all my calls to My.Resources in a function like this:
| > >
| > > MsgBox(ReplaceNL(My.Resources.SomeCustomMessage))
| > >
| > > but this appears very clusy to me. Is there some better way to handle
this
| > > that you .Net gurus can see that I can't.
| > >
| > >
| >
| >
| >
Apr 18 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jacster | last post by:
Hi, I want to extend the functionality of my Firefox browser. Can you write mozilla plugins in Javascript; can anyone point me to some resources for doing this? If not, can I save Javascript...
10
by: Jerzy Karczmarczuk | last post by:
Gurus, before I am tempted to signal this as a bug, perhaps you might convince me that it should be so. If I type l=range(4) l.extend() l gives , what else... On the other hand, try
2
by: Boobie | last post by:
I switched to using this function to create element: ---------------------------------------------------- function elem(name, attrs, style, text) { var e = document.createElement(name); if...
3
by: jacobstr | last post by:
I've noticed Object.extend used in a few different ways and I'm having trouble distinguishing why certain usages apply to a given situation. On line 804 Ajax.Base is defined as follows: ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.