开发者

How to run a function from a string vb.net

开发者 https://www.devze.com 2023-04-06 02:33 出处:网络
What i am trying t开发者_运维知识库o do is call functions from a string that I created The example would be:

What i am trying t开发者_运维知识库o do is call functions from a string that I created

The example would be: genoutput is a string I made to concatenate the function calls when a certain combo box item was selected...

   Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button2.Click
    Select Case ComboBox1.SelectedItem
        Case "First Name"
            genoutput = genoutput & randomfirstname() & vbTab
        Case "Last Name"
            genoutput = genoutput & randomlastname() & vbTab
        Case "Decimal"
            genoutput = genoutput & gendecimal(CDbl(decimal1.text,decimal2.text)) & vbtab )
        Case "Integer"
            genoutput = (genoutput & geninteger(CInt(integer1.text,integer2.text)) & vbtab)
        Case "Birthday"
            genoutput = (genoutput & birthday(CInt(year1.text,year2.text)) & vbtab &)
    End Select

I am trying to get a string that looks like this and runs

 outfile.Write(randomfirstname() & vbTab & randomlastname() & vbTab & gendecimal(CDbl(decimal1.text,decimal2.text)) & vbTab & (CInt(integer1.text,integer2.text)) & vbTab & birthday(CInt(year1.text,year2.text)) & vbCrLf)


This will work if you remove the quotes from hello() & vbtab & goodbye(), but as JohnFx said, it seems like an unusual and unnecessary way to do it.


I think you might be looking for something more like:

1) ListBox1.Items.Add("Hello"), .Add("Goodbye"), ...

2) If ListBox1.ListIndex = 0 then call hello, else if ...

0

精彩评论

暂无评论...
验证码 换一张
取 消