TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
keith aranjuez
NA
7
1.4k
refactor code
Dec 29 2012 10:58 AM
hey guys..noob code here. how can i possibly refactor this long code? o_o
Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
If btnNew.Text = "New" Then
btnNew.Text = "Save"
enable()
ElseIf btnNew.Text = "Save" Then
If txtDiagnosis.Text = String.Empty Then
MessageBox.Show("Error encountered! No diagnosis.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
ElseIf pID = String.Empty Then
MessageBox.Show("Error encountered! No patient information.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
Else
If MessageBox.Show("Save information?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Try
Using dbconn As New SqlConnection(conn)
dbconn.Open()
Dim dbadd As New SqlCommand("insert into tblcheckups(checkdate, patientid, employeeid, diagnosis, comments, prescription) values(@checkdate, @patientid, @empID, @diagnosis, @comments, @prescription)")
With dbadd
.Parameters.AddWithValue("@checkdate", Now.ToShortDateString.Trim)
.Parameters.AddWithValue("@patientid", pID.Trim)
.Parameters.AddWithValue("@empID", emp.Trim)
.Parameters.AddWithValue("@diagnosis", txtDiagnosis.Text.Trim.Replace("'", "''"))
.Parameters.AddWithValue("@comments", txtComment.Text.Trim.Replace("'", "''"))
.Parameters.AddWithValue("@prescription", txtPrescribe.Text.Trim.Replace("'", "''"))
.Connection = dbconn
.ExecuteNonQuery()
End With
dbconn.Close()
End Using
MessageBox.Show("Information saved!", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
disable()
getNames()
clear()
btnNew.Text = "New"
Catch ex As Exception
Beep()
MessageBox.Show(String.Format("Error encountered! {0}. Source: {1}", ex.Message, ex.Source), "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End If
End If
End If
End Sub
Reply
Answers (
0
)
when i run code shows string was not recognized validdatetim
HOw can i Develop intelligent character recognition (icr)