On 13 Lug, 17:33, Bernd Schend <bernd.off...@g mx.dewrote:
Hi Steve,
why not using an array?
In case you really need these variables, you should use reflection
for getting/setting their values.
Regards
Bernd
Bernd is right.
If you feel you need that, double check your program architecture.
Anyway that would be something like (need to add a few checks in real
world programs):
'----------------------------------------
Imports System.Reflecti on
Public Class Form1
Public Var1 As String = "Name1"
Public Var2 As String = "Name2"
Public Var3 As String = "Name3"
Public Var4 As String = "Name4"
Public Var5 As String = "Name5"
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Const Prefix As String = "Var"
For i As Integer = 1 To 5
Dim Flags As BindingFlags = BindingFlags.Ge tField Or
BindingFlags.In stance Or BindingFlags.Pu blic
Dim f As System.Reflecti on.FieldInfo =
Me.GetType.GetF ield(Prefix & i, Flags)
Dim Text As String = f.GetValue(Me)
If Text = "Name3" Then
MsgBox(Text)
End If
Next
End Sub
End Class
'----------------------------------------
Tommaso