ElektroStudios
ElektroStudios

Reputation: 20464

How to use dynamic vars in VBNET

How I can take the text of the button to use it like a resource name?

My try:

Public Sub LlamadaButton(ByVal sender As Object, ByVal e As System.EventArgs)
   Dim ButtonN As Button = CType(sender, Button)
   Dim ResourceName = ButtonN.Text
   ReadDelimitedText(My.Resources._(ResourceName), ";")     ' The problem: My.Resources._(ResourceName)
   End Sub

Error: Identifier expected

Upvotes: 0

Views: 222

Answers (3)

Victor Zakharov
Victor Zakharov

Reputation: 26424

Assuming your resource file name is Resource1.resx, and your string in it is String1, you should be able to access it like this:

My.Resources.Resource1.String1

Upvotes: 1

Mark Hall
Mark Hall

Reputation: 54532

Use the My.Resources.ResourceManager.GetString Method.

Dim ResourceName = ButtonN.Text
ReadDelimitedText(My.Resources.ResourceManager.GetString("_" & ResourceName), ";")     

Upvotes: 3

Zeddy
Zeddy

Reputation: 2089

<script runat="server">
Public Sub LlamadaButton(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  Dim ButtonN As Button = CType(sender, Button)
  Dim ButtonText = ButtonN.Text
  MsgBox(ButtonText)
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
</head>
<body>
  <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button Bob" />
    </div>
  </form>
</body>
</html>

Is this what you mean?, clicking on the button will show the text in a messagebox, try and change the button text and click it again

Upvotes: 1

Related Questions