Setting a global variable, object reference not set to an instance of an object - vb.net-2010

I'm trying to get ID and Pass variables to be accessed by both Actions
but returns object reference not set to an instance of an object
Dim ID As String = txt1RegisterID.Text
Dim Pass As String = txt2RegisterPass.Text
Private Sub btn1Register_Click(sender As Object, e As System.EventArgs) Handles btn1Register.Click
If ID = "" And Pass = "" Then
btn2Confirm.Enabled = False
MessageBox.Show("Register user")
Else
txt1RegisterID.PasswordChar = " "
txt2RegisterPass.PasswordChar = " "
btn2Confirm.Enabled = True
End If
End Sub
Private Sub btnConfirm_Click(sender As Object, e As System.EventArgs) Handles btn2Confirm.Click
If txt3LoginID.Text = ID And txt4LoginPass.Text = Pass Then
MessageBox.Show("Access Granted")
Else
MessageBox.Show("Access Denied")
End If
End Sub
Private Sub btn3Cancel_Click(sender As Object, e As System.EventArgs) Handles btn3Cancel.Click
Me.Close()
End Sub
End Class

Related

Access dynamically created UserControl's Public Declare - WinForms

Logic
There is Form1 with a FlowLayoutPanel 'flowItems' to be populated by UserControl 'UCItem'. For populating flowItems, an array is used. For-Loop loopes over the array and creates a new UCItem, gives it a tag name with number and adds it to flowItem. All this part works.
Issue
I want to change the public declared boolean variable 'isChecked' each time the newly created UCItem is clicked. For achieving this, I've added an event handler (UCItem.Click) which gets and sets the property.
How ever, I'm unable to access the public boolean variable in UCItem.
Code: UC_Item.vb
Public isChecked As Boolean = False
Private Sub toggle_color()
If Me.BackColor = Color.FromArgb(24, 24, 24) Then
Me.BackColor = Color.RoyalBlue
Me.txtName.BackColor = Color.RoyalBlue
Me.txtName.ForeColor = Color.Black
Me.BackgroundImage = Nothing
isChecked = True
Else
Me.BackColor = Color.FromArgb(24, 24, 24)
Me.txtName.BackColor = Color.Black
Me.txtName.ForeColor = Color.White
Me.BackgroundImage = Image.FromFile(Application.StartupPath & "/res/UCItem_Wallpaper.png")
isChecked = False
End If
End Sub
Private Sub UC_Item_Click(sender As Object, e As EventArgs) Handles MyBase.Click
toggle_color()
End Sub
Private Sub TxtName_Click(sender As Object, e As EventArgs) Handles txtName.Click
toggle_color()
End Sub
Code: Form1.vb
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim UCItem As UC_Item
flowItems.SuspendLayout()
For i As Integer = 0 To items.Count - 1
UCItem = New UC_Item
UCItem.Tag = "UCItem" & i
UCItem.txtName.Text = items(i).ToString
flowItems.Controls.Add(UCItem)
UCItem.Show() : UCItem.Visible = True
AddHandler(UCItem.Click), AddressOf UCItem_Click
Next
flowItems.ResumeLayout()
End Sub
Private Sub UCItem_Click(sender As Object, ByVal e As EventArgs)
' -- not working part --
' If sender.isChecked = True Then
' sender.isChecked = False
' else
' sender.isChecked = True
End Sub
Tried
I've tried passing 'UCItem As sender.Tag' but this doesn't work too. I can't access the .Tag and .Name property of sender in the click event.
Any help is appreciated!

'Cannot perform '=' operation on System.Int32 and System.String.'

I am using textbox as search for number, when I put number it searched but when I erased it from box I got error.
my code is:
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
SpringDataBindingSource.Filter = "SerialNumber = '" + TextBox2.Text + "'"
End Sub
the error is:
Cannot perform '=' operation on System.Int32 and System.String.
The problem is that empty string validation failed.
For empty string you should remove the filter.
It should be something like this:
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
if Trim(TextBox2.Text) = "" Then
SpringDataBindingSource.Filter = ""
Else
SpringDataBindingSource.Filter = "SerialNumber = '" + TextBox2.Text + "'"
End If
End Sub
EDIT
You can also check each inserted data with KeyUp event:
Private Sub TextBox2_KeyUp(sender As Object, e As KeyEventArgs) Handles ComboBox1.KeyUp
If NumericMode Then ' NumericMode is boolean and should be turnd On/Off elswhere
If Char.IsDigit(ChrW(e.KeyValue)) Then
'OK
Else
'ERROR
End If
End If
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
'This would work, but would consider decimals also a number
If IsNumeric(TextBox2.Text) Then
SpringDataBindingSource.Filter = String.Format("SerialNumber = '{0}'", TextBox2.Text)
Return
End If
SpringDataBindingSource.Filter = ""
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
'This would work if you want to guarantee an Int32
Dim txtInt As Integer
If Int32.TryParse(TextBox2.Text, TxtInt) Then
SpringDataBindingSource.Filter = String.Format("SerialNumber = '{0}'", txtInt)
Else
SpringDataBindingSource.Filter = ""
End If
End Sub

VB.net RGB color sensor "Integer is not valid"

I'm trying to make VB.net show the data "colors" from my Arduino,
My serial port working great but I have this massage every-time I press connect & weird data show's up
An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
Additional information: Conversion from string " = " to type 'Integer' is not valid.
Can someone help me in this?
this is my code
Public Class Form1
Private _msg As String
Dim R As String
Dim G As String
Dim B As String
Dim iR As String
Dim iG As String
Dim iB As String
Private indata As String
Dim IsConnected As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each str As String In IO.Ports.SerialPort.GetPortNames()
Ports.Items.Add(str)
Next
If (Ports.Items.Count > 0) Then
Ports.SelectedIndex = 0
End If
IsConnected = False
Status.Text = "Disconnected"
Status.BackColor = Color.MistyRose
Button1.Enabled = True
Button2.Enabled = False
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If (SerialPort1.IsOpen()) Then
Try
SerialPort1.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
IsConnected = False
Status.Text = "Disconnected"
Status.BackColor = Color.MistyRose
Button1.Enabled = True
Button2.Enabled = False
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If (SerialPort1.IsOpen = False) Then
SerialPort1.PortName = Ports.SelectedItem
SerialPort1.Open()
IsConnected = True
Status.Text = "Connected"
Status.BackColor = Color.LightGreen
Button1.Enabled = False
Button2.Enabled = True
End If
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
'user chose string
'read data waiting in the buffer
Try
Dim msg As String = SerialPort1.ReadExisting()
indata = indata + msg
'Dim where As Integer = InStr(indata, ControlChars.Lf)
Dim where As Integer = InStr(indata, "R=")
If (indata.Length > where + 18) Then
R = indata.Substring(where + 1, 3)
G = indata.Substring(where + 7, 3)
B = indata.Substring(where + 13, 3)
indata = ""
End If
'display the data to the user
_msg = msg
_msg = _msg.Replace(ControlChars.Cr, "")
: DisplayData(msg)
Catch ex As Exception
End Try
End Sub
#Region "DisplayData"
''' <summary>
''' Method to display the data to and
''' from the port on the screen
''' </summary>
''' <remarks></remarks>
<STAThread()> _
Private Sub DisplayData(ByVal msg As String)
DisplayWindow.BeginInvoke(New EventHandler(AddressOf DoDisplay))
End Sub
#End Region
#Region "DoDisplay"
Private Sub DoDisplay(ByVal sender As Object, ByVal e As EventArgs)
'DisplayWindow.SelectedText = String.Empty
'DisplayWindow.SelectionFont = New Font(_DisplayWindow.SelectionFont, FontStyle.Bold)
'DisplayWindow.SelectionColor = MessageColor(CType(_type, Integer))
DisplayWindow.AppendText(_msg)
DisplayWindow.ScrollToCaret()
End Sub
#End Region
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
RL.Text = R
GL.Text = G
BL.Text = B
iR = CInt(R) * CInt(RM.Text)
iG = CInt(G) * CInt(GM.Text)
iB = CInt(B) * CInt(BM.Text)
RF.Text = iR
GF.Text = iG
BF.Text = iB
Try
Label6.BackColor = Color.FromArgb(CType(iR, Byte), CType(iG, Byte), CType(iB, Byte))
Catch ex As Exception
End Try
End Sub
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)
System.Diagnostics.Process.Start("http://www.narzan.weebly.com/p-1049.html")
End Sub
Private Sub LinkLabel1_LinkClicked_1(sender As Object, e As LinkLabelLinkClickedEventArgs)
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
picOn.Visible = True
SerialPort1.Open()
SerialPort1.Write("^")
SerialPort1.Close()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
picOn.Visible = False
SerialPort1.Open()
SerialPort1.Write("<")
SerialPort1.Close()
End Sub
Private Sub picOn_Click(sender As Object, e As EventArgs) Handles picOn.Click
End Sub
Private Sub RL_Click(sender As Object, e As EventArgs) Handles RL.Click
End Sub
Private Sub RM_TextChanged(sender As Object, e As EventArgs) Handles RM.TextChanged
End Sub
End Class
My problem was from my Arduino code not from VB.net
the solution is to remove "=" from R,G,B
void printColour(){
Serial.print("R = ");
Serial.println(int(colourArray[0]));
Serial.print("G = ");
Serial.println(int(colourArray[1]));
Serial.print("B = ");
Serial.println(int(colourArray[2]));
//delay(2000);
}
so the code will look like that
void printColour(){
Serial.print("");
Serial.println(int(colourArray[0]));
Serial.print("");
Serial.println(int(colourArray[1]));
Serial.print("");
Serial.println(int(colourArray[2]));
//delay(2000);
}
Thanks everyone, everything work great now

VB.net Web Browser - Adding Bookmarks

I have a web browser that I am trying to keep to the minimal to keep it running fast (I have the firefox gecko browser engine even though that doesn't matter for this question I think.) but there is one thing I want to add and that is bookmarks. Right now I have a ton of messy code but I wasn't able to create a new tool strip button for each time I hit the bookmark button. So what I did is I added the appropriate settings and 6 toolstrip buttons. Now this limits me to 6 bookmarks. Which really sucks. My code is here:
Imports System.IO
Public Class tabForm
Dim ico As Image = Nothing
Private Sub goBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles goBack.Click
webBrowser.GoBack()
End Sub
Private Sub goForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles goForward.Click
webBrowser.GoForward()
End Sub
Private Sub Navigate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Navigate.Click
If urlBox.Text = "yt" Then
webBrowser.Navigate("http://www.youtube.com")
ElseIf urlBox.Text = "fb" Then
webBrowser.Navigate("http://www.facebook.com")
ElseIf urlBox.Text = "gm" Then
webBrowser.Navigate("http://www.gmail.com")
ElseIf urlBox.Text = "go" Then
webBrowser.Navigate("http://www.google.com")
Else
webBrowser.Navigate(urlBox.Text)
End If
End Sub
Private Sub webBrowser_DocumentCompleted(ByVal sender As Object, ByVal e As System.EventArgs) Handles webBrowser.DocumentCompleted
Me.Text = webBrowser.DocumentTitle
geticon()
End Sub
Private Sub webBrowser_Navigated(ByVal sender As System.Object, ByVal e As Skybound.Gecko.GeckoNavigatedEventArgs) Handles webBrowser.Navigated
Try
urlBox.Text = webBrowser.Url.ToString
Catch ex As Exception
End Try
End Sub
Private Sub urlBox_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles urlBox.KeyDown
Try
If e.KeyCode = Keys.Enter Then
If urlBox.Text = "yt" Then
webBrowser.Navigate("http://www.youtube.com")
ElseIf urlBox.Text = "fb" Then
webBrowser.Navigate("http://www.facebook.com")
ElseIf urlBox.Text = "gm" Then
webBrowser.Navigate("http://www.gmail.com")
ElseIf urlBox.Text = "go" Then
webBrowser.Navigate("http://www.google.com")
Else
webBrowser.Navigate(urlBox.Text)
End If
e.SuppressKeyPress = True
End If
Catch ex As Exception
End Try
End Sub
Private Sub geticon()
Try
Dim url As Uri = New Uri(webBrowser.Url.ToString)
If url.HostNameType = UriHostNameType.Dns Then
' Get the URL of the favicon
' url.Host will return such string as www.google.com
Dim iconURL = "http://" & url.Host & "/favicon.ico"
' Download the favicon
Dim request As System.Net.WebRequest = System.Net.HttpWebRequest.Create(iconURL)
Dim response As System.Net.HttpWebResponse = request.GetResponse()
Dim stream As System.IO.Stream = response.GetResponseStream()
Dim favicon = Image.FromStream(stream)
' Display the favicon on ToolStripLabel1
Me.favicon.Image = favicon
End If
Catch ex As Exception
Me.favicon.Image = Nothing
End Try
End Sub
Private Sub favicon_timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles favicon_timer.Tick
Try
Catch ex As Exception
End Try
End Sub
Private Sub Reload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Reload.Click
webBrowser.Reload()
End Sub
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
webBrowser.Navigate(My.Settings.mark1)
End Sub
Private Sub ToolStripButton6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton6.Click
webBrowser.Navigate(My.Settings.mark6)
End Sub
Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton5.Click
webBrowser.Navigate(My.Settings.mark5)
End Sub
Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click
webBrowser.Navigate(My.Settings.mark4)
End Sub
Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
webBrowser.Navigate(My.Settings.mark3)
End Sub
Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
webBrowser.Navigate(My.Settings.mark2)
End Sub
Private Sub Fav_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub ToolStripButton7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton7.Click
If ToolStripButton1.Text = webBrowser.DocumentTitle Then
ToolStripButton1.Text = ""
My.Settings.mark1 = ""
My.Settings.mark11 = ""
ToolStripButton1.Visible = False
End If
If ToolStripButton2.Text = webBrowser.DocumentTitle Then
ToolStripButton2.Text = ""
My.Settings.mark2 = ""
My.Settings.mark22 = ""
ToolStripButton2.Visible = False
End If
If ToolStripButton3.Text = webBrowser.DocumentTitle Then
ToolStripButton3.Text = ""
My.Settings.mark3 = ""
My.Settings.mark33 = ""
ToolStripButton3.Visible = False
End If
If ToolStripButton4.Text = webBrowser.DocumentTitle Then
ToolStripButton4.Text = ""
My.Settings.mark4 = ""
My.Settings.mark44 = ""
ToolStripButton4.Visible = False
End If
If ToolStripButton5.Text = webBrowser.DocumentTitle Then
ToolStripButton5.Text = ""
My.Settings.mark5 = ""
My.Settings.mark55 = ""
ToolStripButton5.Visible = False
End If
If ToolStripButton6.Text = webBrowser.DocumentTitle Then
ToolStripButton6.Text = ""
My.Settings.mark6 = ""
My.Settings.mark66 = ""
ToolStripButton6.Visible = False
End If
End Sub
Private Sub ToolStripButton8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton8.Click
If ToolStripButton1.Text = "" Then
ToolStripButton1.Text = webBrowser.DocumentTitle
My.Settings.mark1 = webBrowser.Url.ToString
My.Settings.mark11 = webBrowser.DocumentTitle
ToolStripButton1.Visible = True
ElseIf ToolStripButton2.Text = "" Then
ToolStripButton2.Text = webBrowser.DocumentTitle
My.Settings.mark2 = webBrowser.Url.ToString
My.Settings.mark22 = webBrowser.DocumentTitle
ToolStripButton2.Visible = True
ElseIf ToolStripButton3.Text = "" Then
ToolStripButton3.Text = webBrowser.DocumentTitle
My.Settings.mark3 = webBrowser.Url.ToString
My.Settings.mark33 = webBrowser.DocumentTitle
ToolStripButton3.Visible = True
ElseIf ToolStripButton4.Text = "" Then
ToolStripButton4.Text = webBrowser.DocumentTitle
My.Settings.mark4 = webBrowser.Url.ToString
My.Settings.mark44 = webBrowser.DocumentTitle
ToolStripButton4.Visible = True
ElseIf ToolStripButton5.Text = "" Then
ToolStripButton5.Text = webBrowser.DocumentTitle
My.Settings.mark5 = webBrowser.Url.ToString
My.Settings.mark55 = webBrowser.DocumentTitle
ToolStripButton5.Visible = True
ElseIf ToolStripButton6.Text = "" Then
ToolStripButton6.Text = webBrowser.DocumentTitle
My.Settings.mark6 = webBrowser.Url.ToString
My.Settings.mark66 = webBrowser.DocumentTitle
ToolStripButton6.Visible = True
Else
End If
End Sub
Private Sub ToolStripButton9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton9.Click
Dim newFav As New ToolStripButton
newFav.Text = webBrowser.Url.ToString
newFav.PerformClick()
End Sub
Private Sub favClick()
End Sub
Private Sub tabForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If My.Settings.mark1 <> "" And My.Settings.mark11 <> "" Then
ToolStripButton1.Text = My.Settings.mark11
ToolStripButton1.Visible = True
End If
If My.Settings.mark2 <> "" And My.Settings.mark22 <> "" Then
ToolStripButton2.Text = My.Settings.mark22
ToolStripButton2.Visible = True
End If
If My.Settings.mark3 <> "" And My.Settings.mark33 <> "" Then
ToolStripButton3.Text = My.Settings.mark33
ToolStripButton3.Visible = True
End If
If My.Settings.mark4 <> "" And My.Settings.mark44 <> "" Then
ToolStripButton4.Text = My.Settings.mark44
ToolStripButton4.Visible = True
End If
If My.Settings.mark5 <> "" And My.Settings.mark55 <> "" Then
ToolStripButton5.Text = My.Settings.mark55
ToolStripButton5.Visible = True
End If
If My.Settings.mark6 <> "" And My.Settings.mark66 <> "" Then
ToolStripButton6.Text = My.Settings.mark66
ToolStripButton6.Visible = True
End If
End Sub
End Class
That's all of it. But as I said earlier I could only add 6 bookmarks. Is there any way I can add an unlimited number of bookmarks. I tried something like this:
Private Sub Bookmark()
Dim mark As New ToolStripButton
mark.DisplayStyle = Text
mark.Parent = ToolStrip1 'This didn't work
End Sub
But if I did get that to work what would I put to make it navigate to that page? Please help.
I finally found the answer to this. If anybody wondering where here is the link:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/eebcf40a-dec9-41ae-8e8b-3d446cf93322/web-browser-bookmarks-bar
Have a nice day.
create a class called favorite and a setting called favorites of type system.collections.specialized.stringcollection
public class favorite
inherits toolstripsplitbutton
public mytitle as string
public myurl as string
public myimg as image
public mybrowser as webbrowser
public sub new(title as string, url as string, browser as webbrowser)
mybase.new()
mytitle = title
myurl = url
'create a getfavicon function - Google :)
myimg = GetFavicon(myurl)
mybrowser = browser
me.text = mytitle
me.tooltiptext = mytitle + " : " + myurl
me.image = myimg
end sub
private sub Favorite_Click(sender as object, e as eventargs) handles me.click
browser.navigate(myurl)
end sub
then in your form code add a sub
public sub AddFav() handles '>>the add favorite button<<.click
my.settings.favorites.add(webbrowser.documenttitle + "|" + webbrowser.url.tostring)
my.settings.save()
end sub
public sub RefreshFavs()
for each fav as string in my.settings.favorites
dim favarray as array = fav.split(new char() {"|"c})
dim x as new favorite(favarray(0), favarray(favarray.count - 1, webbrowser)
mytoolstrip.items.add(x)
next
end sub
simple explanation:
AddFav() - save favorites with page title and url
RefreshFavs() - splits each setting by the "|" which the title and url are seperated
Class Favorite() - allows you to add a splitbutton that navigates the linked browser to it's myurl variable.
hope this helps. sorry if its a little crude, I had to recall it from my memory.

Get InvalidOperatorException was unhandled upon compiling

Everything was compiling just fine until validation for text fields was implemented.
Why won't it compile?
An error occurred creating the form.
See Exception.InnerException for
details. The error is: External
component has thrown an exception.
The source:
Public Class frmAddStudent
Dim aryData(6) As String
Public Shared newStudentRecord As String
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.DialogResult = DialogResult.Cancel
End Sub
Private Sub btnAddStudent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddStudent.Click
'place all the student field data into the array of elements
aryData(0) = txtFirstName.Text
aryData(1) = txtLastName.Text
aryData(2) = txtMajor.Text
aryData(3) = txtPhone.Text
aryData(4) = txtEmail.Text
aryData(5) = txtGPA.Text
'join the array elements and place the result into a string variable
newStudentRecord = Join(aryData, " ")
'create a link between the form and the file with streamwriter and write to the text file
If System.IO.File.Exists(frmMain.FILE_NAME) = True Then
Dim objWriter As New System.IO.StreamWriter(frmMain.FILE_NAME, True)
objWriter.WriteLine(newStudentRecord)
objWriter.Close()
End If
Me.DialogResult = DialogResult.OK
End Sub
Private Sub txtFirstName_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtFirstName.Validating
If txtFirstName.Text.Contains(" ") Or txtFirstName.Text.Length = 0 Or Not System.Text.RegularExpressions.Regex.IsMatch(txtFirstName.Text, "[a-z|A-Z]+$") Then
ErrorProvider1.SetError(txtFirstName, "First Name can't contain spaces or be of zero length and must consist of only letters")
e.Cancel = True
Else
ErrorProvider1.SetError(txtFirstName, "")
End If
End Sub
Private Sub frmAddStudent_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ErrorProvider1.BlinkStyle = ErrorBlinkStyle.NeverBlink
End Sub
Private Sub txtLastName_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtLastName.Validating
If txtLastName.Text.Contains(" ") Or txtLastName.Text.Length = 0 Or Not System.Text.RegularExpressions.Regex.IsMatch(txtLastName.Text, "[a-z|A-Z]+$") Then
ErrorProvider1.SetError(txtLastName, "Last Name can't contain spaces or be of zero length and must consist of only letters")
e.Cancel = True
Else
ErrorProvider1.SetError(txtLastName, "")
End If
End Sub
Private Sub txtMajor_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtMajor.Validating
If txtMajor.Text.Length > 0 Then
If Not System.Text.RegularExpressions.Regex.IsMatch(Strings.Left(txtMajor.Text, 1), "[a-z|A-Z]+$") Then
ErrorProvider1.SetError(txtMajor, "Major course code is incorrect")
Else
ErrorProvider1.SetError(txtMajor, "")
End If
Else
ErrorProvider1.SetError(txtMajor, "Major cant' be zero length")
End If
End Sub
End Class
EDIT: Here's also a link to a PrtSc of the problem: http://img88.imageshack.us/i/imageqc.gif/