I'm working on another school project and I'm learning about creating a Function. In this example, I need to create a Function that will list out my 'Top Donors' who are manually entered in by me. The error I'm running into is I've created my Function, but at the end as I try and end it with Return String, I'm getting a syntax error and I'm not sure what I need to put after it.
Public Class Form1
Function GetTopDonors() As String
Dim sb As New StringBuilder()
sb.Append("Frank, $1,000,000")
sb.Append("Joe, $980,000")
Return String
End Function
Private Sub btnDisplay_Click(sender As System.Object, e As System.EventArgs) Handles btnDisplay.Click
Dim TopDonors As String = GetTopDonors()
txtDonorList.Text = TopDonors
End Sub
End Class

Change it to read: Return sb.ToString() and it should work for you. That will return the String value of the StringBuilder which is what you want since the function returns a String.
String by itself is a type so you can't return it - you have to return an instance of it.
Make sense?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With