Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i get a Function to return a string value?

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

enter image description here

like image 683
j_fulch Avatar asked Jun 12 '26 01:06

j_fulch


1 Answers

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?

like image 82
edtheprogrammerguy Avatar answered Jun 16 '26 14:06

edtheprogrammerguy