Visual Basic Coding Help: Why Is This Error Here?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Visual Basic Coding Help: Why Is This Error Here?

Hybrid View

  1. #1
    Join Date
    Oct 2013
    Posts
    10

    Visual Basic Coding Help: Why Is This Error Here?

    Me again. Didn't think I was gonna have to post again so soon, but I've ran into a problem with another project of mine. What I'm trying to do is make a program that provides a text box for entering a person's first and last name (with a space in between, of course) with a Click event procedure that displays the name in reverse with a comma and a space in between the first and last name.

    I thought for sure I had this in the bag, but before I could even debug the program I get this error:
    Value of type 'String' cannot be converted to 'System.Windows.Forms.Label'. 40 21

    It's been a while since I did these so I can't, for the life, figure out how to resolve this error.

    Here's the code I'm using, and, again, I'm using Microsoft Visual Basic 2010 Express.

    Code:
    Option Explicit On
    Option Strict On
    
    Public Class MainForm
    
        Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
            Me.Close()
        End Sub
    
        Private Sub nameTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles nameTextBox.Enter
            nameTextBox.SelectAll()
        End Sub
    
        Private Sub nameTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles nameTextBox.TextChanged
            nameLabel.Text = String.Empty
        End Sub
    
        Private Sub reverseButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles reverseButton.Click
            Dim firstName As String
            Dim lastName As String
            Dim numberLast As Integer
            Dim numberFirst As Integer
            Dim input As String
            Dim isConverted As Boolean
            Dim index As Integer
    
            input = nameTextBox.Text
            Convert.ToString(input)
    
            index = input.IndexOf(" ")
    
            firstname = input.Substring(0, index)
            lastname = input.Substring(index + 1)
    
            nameLabel = lastName + ", " + firstName
    
            nameTextBox.Focus()
        End Sub
    End Class

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,091

    Re: Visual Basic Coding Help: Why Is This Error Here?

    Have you tried :

    Code:
            nameLabel.Text = lastName + ", " + firstName
    ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center