Home > Software engineering >  My WriteConcatenated method doesn't work because of BC30491
My WriteConcatenated method doesn't work because of BC30491

Time:12-19

Imports System

Module Program
    Sub WriteConcatenated(ByVal ParamArray TextArr As String())
        For I As Integer = 0 To TextArr.Length - 1
            For J As Integer = 0 To TextArr.Length - 1
                Dim ConcatenatedText = TextArr(I)   TextArr(J)

                For Each Text As String In TextArr
                    If Text = ConcatenatedText Then
                        Console.WriteLine(Text)
                    End If
                Next
            Next
        Next
    End Sub

    Sub Main(args As String())
        Console.WriteLine(WriteConcatenated("five", "cents" "twenty", "twentycents"))
        Console.ReadLine()
    End Sub
End Module

If there is a element which formed by the concatenation of other elements of the parameter array, I wanted to print them to the screen.

For example: "twentycents" which is at 3rd index in above-mentioned parameter array is concatenation of "twenty" which is at 2nd index and "cents" which is at 1st index in the array. Then the 3rd element of the array will be printed to the screen.

There is no error in code as far as I am concerned but, compiler of Visual Basic gives me

BC30491: Expression does not produce a value

https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/error-messages/expression-does-not-produce-a-value?f1url=?appId=roslyn&k=k(BC30491) (Document of the error)

How should I correct this error?

CodePudding user response:

WriteConcatenated() is a subroutine that does not "return" a value.

Change:

Console.WriteLine(WriteConcatenated("five", "cents" "twenty", "twentycents"))

to:

WriteConcatenated("five", "cents" "twenty", "twentycents")

And it will work.

On the other hand, if WriteConcatenated() was a function declared using the Function keyword that returned a value using the Return keyword, passing the value returned by it to Console.WriteLine() like you've done would have worked.

  • Related