Just playing about with some vb.net and i dont understand why when i enter Dog into the text box the label continues to say not dog?
Public Class Form1
Dim dogAnswer As Boolean
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
Public Function getText() As Boolean
dogAnswer = False
If TextBox1.Text = "Dog" Then
Return dogAnswer = True
End If
Return dogAnswer
End Function
Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If dogAnswer = True Then
Label1.Text = "dog"
Else
Label1.Text = "Not dog"
End If
End Sub
End Class
There are three problems:
1) You never call GetText
2) Even if you did call GetText, it will always return false.
3) You are performing a case-sensitive comparison, so value of dog and DOG, for example, will return false.
Changing your code to be something like the following will get what you are looking for:
Note that getText can eliminated and you don’t need the dogAnswer member: