Declare a global variable:
Public final As Double
Then declare a local static variable:
Static result As Double
Then you can manipulate that static variable and after that you can assign that variable to the gobal variable:
data_reader = cmd.ExecuteReader()
If data_reader.HasRows = True Then
Do While data_reader.Read()
quantity = CDbl(data_reader.Item("quantity"))
rate = CDbl(data_reader.Item("rate"))
amount = (quantity * rate)
result = result + amount
Loop
final = result
Else
MsgBox("Unit rate does not exist", vbCritical, "Bridge Construction Cost Estimate")
Exit Sub
End If
And at last you access the global variable anywhere inside a code.Thus it displays the last value of that static variable.