Dear All expert
I could like to ask/request come help from you guy but I now sure how to ask in wording
basically I could like to know is there a way to separate/combine a code into a line?
Example
Button that trigger to sent a email the code will be like this
Possible to create another file like email.vb with all the email code inside and on the button code just call and run the code of the email.vb?
I asking this is because my school project that I going to do the coding is getting longer and longer when I try to add new function in always corrupt the old working function and I need to redo again.
Hope someone able to guide me how should I separate and call the code from another .VB instead of writing all the code in the form1. Thanks
Regards,
HB
I could like to ask/request come help from you guy but I now sure how to ask in wording
basically I could like to know is there a way to separate/combine a code into a line?
Example
Button that trigger to sent a email the code will be like this
Visual Basic:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential("username@gmail.com", "password")
Smtp_Server.Port = 587
Smtp_Server.EnableSsl = True
Smtp_Server.Host = "smtp.gmail.com"
e_mail = New MailMessage()
e_mail.From = New MailAddress(txtFrom.Text)
e_mail.To.Add(txtTo.Text)
e_mail.Subject = "Email Sending"
e_mail.IsBodyHtml = False
e_mail.Body = txtMessage.Text
Smtp_Server.Send(e_mail)
MsgBox("Mail Sent")
Catch error_t As Exception
MsgBox(error_t.ToString)
End Try
End Sub
Possible to create another file like email.vb with all the email code inside and on the button code just call and run the code of the email.vb?
Visual Basic:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Code that able to trigger/run all the code in the email.vb
End Sub
I asking this is because my school project that I going to do the coding is getting longer and longer when I try to add new function in always corrupt the old working function and I need to redo again.
Hope someone able to guide me how should I separate and call the code from another .VB instead of writing all the code in the form1. Thanks
Regards,
HB
Last edited by a moderator: