0

What i am trying to 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)
2
  • 1
    My advice would be to rethink your solution so you don't need to do this. This seems like a really kludgy approach. Commented Sep 17, 2011 at 20:22
  • Instead of building a string to call a function to get another string, why not just build the final output string and get rid of the unnecessary middle man? Commented Sep 17, 2011 at 20:56

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

5 Comments

This is for a bigger issue i had on another program.. I just added this simple problem because it effectively showed my issue... I didn't know it would be that easy... thanks :)
The point is to store something in the list that you can use in a case block to decide which code to run. Don't intermix code and data like you are attempting.
The edit looks OK, but I'm not sure I understand exactly what you want to do.
same as last time... I took out the quotes and the simple ones with no parameters were working.. but as soon as there was a comma in the block of code it was saying it was an error
cInt and cDbl only accept a single parameter. Instead of using cInt and cDbl, you can use the Format function to accept numeric values and format them as a formatted string: msdn.microsoft.com/en-us/library/59bz1f0h(VS.90).aspx
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.