Help with visual basic

Search This thread

fujirio

Senior Member
Feb 10, 2011
190
23
can some one help me find the errors on this program

Public Class DemoUpper

Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
Const strLowerCase As String = "visual basic"
strLowerCase = strLowerCase.ToUpper
txtOutput.Text = strLowerCase
End Sub
End Class
 

fujirio

Senior Member
Feb 10, 2011
190
23

kibermaster

Member
Oct 13, 2010
16
1
Moscow
http://pastebin.com/0Qw1kKJ0#

Code:
Public Class DemoUpper

    Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles   btnDisplay.Click
        Const strLowerCase As String = "visual basic"
        strLowerCase = strLowerCase.ToUpper
        txtOutput.Text = strLowerCase
    End Sub
      End Class

You've declared "strLowerCase" as constant, so you can't assign a value to it, you can only read it. So, the working code should look like this:

Code:
Public Class DemoUpper

    Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles   btnDisplay.Click
        Dim strLowerCase1 as string
        Const strLowerCase As String = "visual basic"
        strLowerCase1 = strLowerCase.ToUpper
        txtOutput.Text = strLowerCase1
    End Sub
      End Class

But also you can make it shorter like this:

Code:
Public Class DemoUpper

    Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles   btnDisplay.Click
        Const strLowerCase As String = "visual basic"
        txtOutput.Text = strLowerCase.ToUpper
    End Sub
      End Class
 

fujirio

Senior Member
Feb 10, 2011
190
23
You've declared "strLowerCase" as constant, so you can't assign a value to it, you can only read it. So, the working code should look like this:

Code:
Public Class DemoUpper

    Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles   btnDisplay.Click
        Dim strLowerCase1 as string
        Const strLowerCase As String = "visual basic"
        strLowerCase1 = strLowerCase.ToUpper
        txtOutput.Text = strLowerCase1
    End Sub
      End Class

But also you can make it shorter like this:

Code:
Public Class DemoUpper

    Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles   btnDisplay.Click
        Const strLowerCase As String = "visual basic"
        txtOutput.Text = strLowerCase.ToUpper
    End Sub
      End Class


wow thank you so much