trying to retreive value of a variable after contructing it as a string

 Dim FullName As String
  FirstInitialLetter = Mid(LTrim(RTrim(FullName)), 1, 1) & "_" & "score"
  Dim score As Double = FirstInitialLetter

   My program has a set of double variables A_score, B_Score,...,Z_score and I am trying to fetch the correct
   variable based on the first letter of the fullname,i.e, if FullName='Robert Dunn' then the FirtInitialLetter    reduces to R_score as a string and I was hoping to be able to extract the corresponding double variable called    R_score's value into score. But I get the error: Cant cast a string as a double in line 3. It is misinterpreting the FirstinitialLetter as a string and I want it to read it as a variable name. Please help!!

Who is Participating?
Fernando SotoRetiredCommented:
Hi LuckyLucks;

See if this is what you are looking for.

    Public A_score As Double = 12.23
    Public B_score As Double = 13.24
    Public R_score As Double = 14.25
    Public Z_score As Double = 15.26

    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click

        Dim value As String = ""
        Dim FullName As String = "  Robert Dunn  "
        Dim FirstInitialLetter As String = _
            FullName.Trim.Substring(0, 1) & "_score"

        Dim score As Double = CType(CallByName(Me, FirstInitialLetter, _
            CallType.Get), Double)
        MessageBox.Show("Score = " & score.ToString())
    End Sub

data type Double is a number and you are trying to assign a string to it
For example FirstInitialLetter will contain a value "R_score". What value do you expect to get in a variable "score"?
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Hi LuckyLucks,

if you have your scores in a array with the string R_Score as the identifier in column 1 and a second column for the value as double you can look up those values and assign them to score

hope this helps a bit
LuckyLucksAuthor Commented:
I am looking to stuff into score the double value contained in the variable R_score. So far I have only been able to get a string called R_score. How can I now get its value?

do not think you can do this 'directly' without using something like an array

in this case you have a variable name string and a variable double those are 2 different things but i could be wrong
ah, that should be it :)
LuckyLucksAuthor Commented:
Thanks to everyone for contributing
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.