i'm new working with visual basic, and i've a problem that i can't solve...
Private Sub Submeter_Click(sender As Object, e As EventArgs) Handles Submeter.Click
Dim user As New Utilizador
Dim utilizadores = db.GetTable(Of Utilizador)()
If (ShortIDTextBox.Text = "") Then
MessageBox.Show("É necessário inserir um Username.", "Utilizador", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf (TextBox1.Text = "") Then
MessageBox.Show("É necessário inserir um Nome.", "Utilizador", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf (MoradaTextBox.Text = "") Then
MessageBox.Show("É necessário inserir uma morada.", "Utilizador", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf (PrefixoComboBox.SelectedItem = "") Then
MessageBox.Show("É necessário inserir um Prefixo.", "Utilizador", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ElseIf ((EmailTextBox.Text = "") And (TeleTextBox.Text = "")) Then
MessageBox.Show("É necessário inserir um email ou telefone.", "Utilizador", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Else
Dim query = (From Utilizador In utilizadores Where Utilizador.ShortID = ShortIDTextBox.Text Select Utilizador)
If (query.Count <> 0) Then
MessageBox.Show("Já existe um username igual.", "Utilizador", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
user.Nome = TextBox1.Text
user.morada = MoradaTextBox.Text
user.Prefixo = PrefixoComboBox.SelectedItem
user.Email.email = EmailTextBox.Text
user.Telefone.Telefone = TeleTextBox.Text
user.ShortID = ShortIDTextBox.Text
If PrefixoComboBox.SelectedItem.ToString() = "PD" Then
user.prioridadeCorrente = 1
End If
If PrefixoComboBox.SelectedItem.ToString() = "PR" Then
user.prioridadeCorrente = 2
End If
If PrefixoComboBox.SelectedItem.ToString() = "RS" Then
user.prioridadeCorrente = 3
End If
If PrefixoComboBox.SelectedItem.ToString() = "BS" Then
user.prioridadeCorrente = 3
End If
If PrefixoComboBox.SelectedItem.ToString() = "MS" Then
user.prioridadeCorrente = 3
End If
If PrefixoComboBox.SelectedItem.ToString() = "DS" Then
user.prioridadeCorrente = 3
End If
If PrefixoComboBox.SelectedItem.ToString() = "SF" Then
user.prioridadeCorrente = 3
End If
If PrefixoComboBox.SelectedItem.ToString() = "XT" Then
user.prioridadeCorrente = 3
End If
utilizadores.InsertOnSubmit(user)
db.SubmitChanges()
Form2.utilizador = user
End If
Form2.Show()
Me.Hide()
End If
End Sub
This is my code, and when i run the project , it show me no errors, but when I'm filling out the form it breaks and show me the error "An unhandled exception of type 'System.NullReferenceException' occurred" in the line "user.Email.email = EmailTextBox.Text"...
It is necessary to do a try..catch or something?
Thanks!
user.Email = New Email()
then set theemail
property of that object.