[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

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!!

Thnaks
0
LuckyLucks
Asked:
LuckyLucks
  • 3
  • 2
  • 2
  • +1
1 Solution
 
YZlatCommented:
data type Double is a number and you are trying to assign a string to it
0
 
YZlatCommented:
For example FirstInitialLetter will contain a value "R_score". What value do you expect to get in a variable "score"?
0
 
bruintjeCommented:
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
bruintje
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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?

Thanks
0
 
bruintjeCommented:
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
0
 
Fernando SotoCommented:
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

Fernando
0
 
bruintjeCommented:
ah, that should be it :)
0
 
LuckyLucksAuthor Commented:
Thanks to everyone for contributing
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now