lara400
lara400

Reputation: 4736

how to combine multiple lines into one?

I am trying to figure out a way of combining the below Dim statements into one line and maybe also combining Return dblResult into there. currently it is three lines and I have been told that it is possible but kind of lost of how to do it - can anyone lend a hand please?

` Private Function CalcAreaFromRadius(ByVal radius As Double) As Double

    Dim dblRadiusSquared As Double = radius * radius
    Dim dblResult As Double = dblRadiusSquared * Math.PI

    Return dblResult

End Function`

Thanks

Upvotes: 0

Views: 1268

Answers (3)

Kamyar
Kamyar

Reputation: 18797

Return (radius * radius) * Math.PI

Upvotes: 2

Dexter
Dexter

Reputation: 18452

Given this is a relatively simple calculation, there's no reason why you can't simplify this down to one line like so:

Private Function CalcAreaFromRadius(ByVal radius As Double) As Double

    Return radius * radius * Math.PI

End Function

Upvotes: 2

Mehrdad Afshari
Mehrdad Afshari

Reputation: 421988

While it's not a good idea to put a large number of stuff on one line, you can always use : to put two lines of code in one line in VB:

Canonical example:

Class Test
     Inherits BaseClass

is equivalent to:

Class Test : Inherits BaseClass

Of course, as long as you are declaring variables on a single type without an explicit initialization expression, you can do that in one Dim statement:

Dim a, b as Integer

Upvotes: 2

Related Questions