简体   繁体   中英

Using a passed string as part of a resource name

I find myself writing a function like this:

Public Shared Function RiskBarTitle(ByVal passedWord As String) As String
Dim returnText As String = ""

Try
Select Case passedWord.ToLower
 Case "tobacco"
  returnText = My.Resources.rptPfr9Common.wTobacco     
Case "alcohol"
  returnText = My.Resources.rptPfr9Common.wAlcohol
 Case Else
  returnText = "Oops, no graph title available."
End Select
...

Rather then repeating the case statement is there some way to use the passed variable 'passedWord' to complete the resource name so that it can be used directly? So it would look something like:

My.Resources.rptPfr9Common.passedWord

I have searched widely but evidently I do not know how to describe it sufficiently to find a solution.

Thanks,

Matthew

As the_lotus mentionned above, this works (in C#)

 MessageBox.Show(ResFile.ResourceManager.GetObject("resourceName").ToString());

Sorry I don't have VB installed but you should easily find your way to adapt this in VB.

马修(Mathew),这样做是否可以为您解决问题:

My.Resources.ResourceManager.GetObject("nameOfResource")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM