0% found this document useful (0 votes)
19 views8 pages

PROJECT - CODES Updated

Uploaded by

musek13rus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views8 pages

PROJECT - CODES Updated

Uploaded by

musek13rus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

MICROSOFT VISUAL STUDIO 2012-2022 NET CODES

ACKNOWLEDGEMENTS
I want to first thank microsoft visual studio for providing an IDE.
Not forgetting myself Chiby Tinodaishe "@spectre"
The rest of the 2023 FCA Computer Science class up to and including GOD
My fellow FCA students ; Uncle Celtic , Uncle Drew, Quartz .....................
Hebrews 13 vs 8 "Jesus Christ is the same today , tomorrow and forever"
Not forgetting my prayerful teacher MRS A MARANGE
My distant Melinder Mukambachaza for pushing me to work.

CODE TO LOGIN AND SPEAK


PublicClasslogin_form
DimsapiAsObject'declaring a global variable for speech comments
PrivateSubbtnlogin_Click(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs) Handlesbtnlogin.Click
Iftxtusername.Text = My.Settings.usernameAndtxtpassword.Text = My.Settings.passwordThen main_menu.Show()
sapi = CreateObject("sapi.spvoice") sapi.speak("Access granted") Else
sapi = CreateObject("sapi.spvoice")
sapi.speak("access denied. please check your username and password and try again") EndIf
EndSub
CODE TO CLEAR TEXT BOXES AND PLACE THE CURSOR IN THE PASSWORD TEXTBOOK
PrivateSubbtnclear_Click(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs) Handlesbtnclear.Click
txtpassword.Focus() 'code to place the cursor txtusername.Focus()
txtusername.Text = ""'code to clear the entered text txtpassword.Text =
""
EndSub

CODE TO OPEN A FORM AND CLOSE CURRENT FORM


PrivateSubbtnchangepass_Click(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs) Handlesbtnchangepass.Click
'code to show the change password form and hide/remove the current page change_password_form.Show()
Me.Hide() EndSub

PrivateSubbtnback_Click(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs) Handlesbtnback.Click txtusername.Text


= ""'clearing data entered txtpassword.Text
= ""
Form1.Show()
Me.Hide() EndSub

CODE TO PERFORM CALCULATIONS


PrivateSub Button2_Click(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs) Handles Button2.Click
'code to calculate the change
txtchange.Text = Val(txtamtpaid.Text) - Val(txtcostofchic.Text) EndSub

CODE TO UPDATE(SAVE) A RECORD


PrivateSubAcceptance_FileBindingNavigatorSaveItem_Click(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs)
HandlesAcceptance_FileBindingNavigatorSaveItem.Click

1
'code to save a record
Iftxtaddress.Text = ""Then
MessageBox.Show("Enter your address") ElseIftxtamtpaid.Text
= ""Then
MessageBox.Show("enter amount paid")
ElseIftxtcostofone.Text = ""Then
MessageBox.Show("enter cost of one chicken")
ElseIftxtname.Text = ""Then
MessageBox.Show("enter customer name")
ElseIftxtnumberchic.Text = ""Then
MessageBox.Show("enter number of chickens bought") Else
MessageBox.Show("enter phone number") EndIf
MessageBox.Show("SORRY AN OCCURED WHILE SAVING YOUR RECORD PLEASE TRY AGAIN ", "ERROR", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Try
Me.Validate()
Me.Customer_fileBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.ProjectDataSet)
MessageBox.Show("YOU HAVE SUCCESSFULLY SAVED A NEW RECORD", "SUCCESS", MessageBoxButtons.OK, MessageBoxIcon.Information) 'a
message to inform the user that he/she has successfull saved a record
Catch ex AsException'to catch an error if there is one it displays a message
MessageBox.Show("SORRY AN OCCURED WHILE SAVING YOUR RECORD PLEASE TRY AGAIN ", "ERROR", MessageBoxButtons.OK,
MessageBoxIcon.Error) 'a message to inform the user that the record that he/she added has not been saved
because an error occured
EndTry
EndSub

CODE TO PRINT THE SCREEN


PrivateSubbtnprintscreen_Click(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs) Handlesbtnprintscreen.Click 'code
to print screen
PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
PrintForm1.Print()
EndSub

CODE TO OPEN A FORM AND CLOSE CURRENT FORM


PrivateSub btnexit_Click_1(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs) Handlesbtnexit.Click 'code to
exit the customer file
IfMessageBox.Show("Are you sure you want to exit?", "Click Yes To Exit", MessageBoxButtons.YesNo,
MessageBoxIcon.Question) = Windows.Forms.DialogResult.YesThen
Close()
ElseIfMessageBoxButtons.YesNo = Windows.Forms.DialogResult.NoThen Me.Show()
EndIf
EndSub

CODE TO MOVE TO THE FIRST RECORD


PrivateSub BindingNavigatorMoveFirstItem_Click_1(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs)
HandlesBindingNavigatorMoveFirstItem.Click

2
'code to move to the first record
Customer_fileBindingSource.MoveFirst()
EndSub

CODE TO MOVE TO THE PREVIOUS RECORD


PrivateSub BindingNavigatorMovePreviousItem_Click_1(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs)
HandlesBindingNavigatorMovePreviousItem.Click
'code to move to the previous record
Customer_fileBindingSource.MovePrevious()
EndSub

CODE TO MOVE TO ADD NEW RECORD


PrivateSub BindingNavigatorAddNewItem_Click_1(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs)
HandlesBindingNavigatorAddNewItem.Click
'code to add the new record Customer_fileBindingSource.AddNew()
EndSub

CODE TO MOVE TO THE NEXT RECORD


PrivateSubBindingNavigatorMoveNextItem_Click(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs)
HandlesBindingNavigatorMoveNextItem.Click
'code to move to the next record Customer_fileBindingSource.MoveNext()
EndSub

CODE TO MOVE TO THE LAST RECORD


PrivateSubBindingNavigatorMoveLastItem_Click(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs)
HandlesBindingNavigatorMoveLastItem.Click
'code to move to the last record
Customer_fileBindingSource.MoveLast()
EndSub

CODE TO REMOVE THE CURRENT RECORD


PrivateSubBindingNavigatorDeleteItem_Click(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs)
HandlesBindingNavigatorDeleteItem.Click 'code to delete the current viewed record
Customer_fileBindingSource.RemoveCurrent()
EndSub
CODE TO EDIT RECORD
PrivateSubedit_Click
(ByVal sender
AsSystem.Object,
ByVal e
AsSystem.EventArgs)
Handlesedit.Click
Customer_fileTableAd
apter.Fill(ProjectDa

3
taSet.customer_file)
EndSub

CODE TO REMOVE THE CURRENT RECORD


PrivateSubAcceptance_FileBindingNavigatorSaveItem_Click(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs)
HandlesAcceptance_FileBindingNavigatorSaveItem.Click
'code to save the record
Try
Me.Validate() Me.Chicken_FileBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.ProjectDataSet)
MessageBox.Show("YOU HAVE SUCCESSFULLY SAVED A NEW RECORD", "SUCCESS", MessageBoxButtons.OK, MessageBoxIcon.Information) 'a
message to inform the user that he/she has successfull saved a record
Catch ex AsException
MessageBox.Show("SORRY AN OCCURED WHILE SAVING YOUR RECORD PLEASE TRY AGAIN ", "ERROR", MessageBoxButtons.OK,
MessageBoxIcon.Error) 'a message to inform the user that the record that he/she added has not been saved because an error
occured EndTry
EndSub

CODE TO VIEW THE CURRENT RECORD


PrivateSub ToolStripLabel1_Click(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs) Handles ToolStripLabel1.Click
'code to view the current record
Customer_fileTableAdapter.Fill(ProjectDataSet.customer_file)
EndSub
PrivateSub Button3_Click(ByVal sender AsSystem.Object, ByVal e AsSystem.EventArgs) Handlesbtncurrentdata.Click
PrintPreviewDialog1.Document = currentdata PrintPreviewDialog1.PrintPreviewControl.Zoom = 1
PrintDialog1.Document = currentdata
PrintDialog1.ShowDialog()
PageSetupDialog1.Document = currentdata
PageSetupDialog1.ShowDialog()
PrintPreviewDialog1.ShowDialog() EndSub

VISUAL STUDIO 2022


To hide or show password using checkbox
Dim username, password As String
Public Property UseSystemPasswordChar As Boolean
Private Sub Guna2GradientButton1_Click(sender As Object, e As EventArgs) Handles
Guna2GradientButton1.Click
Close()
End Sub
Private Sub txtpass_TextChanged(sender As Object, e As EventArgs)
txtpass.UseSystemPasswordChar = True

4
End Sub
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles
CheckBox1.CheckedChanged
' for the checkbox to hide or unhide password
If CheckBox1.CheckState = CheckState.Checked Then
txtpass.UseSystemPasswordChar = False
Else
txtpass.UseSystemPasswordChar = True
End If
End Sub

Function to validate your file

Private Sub DoInputValidation()


'Procedure to perform validation
'Check whether the all textboxes are blank
If (String.IsNullOrEmpty(Me.Engine_numberTextBox.Text)) Then
MsgBox("Enter engine number", vbOKCancel, "Error")
Vehicle_typeTextBox.Focus() 'Returns cursor
ElseIf (String.IsNullOrEmpty(Me.Vehicle_typeTextBox.Text)) Then
MsgBox("Enter surname ", vbOKCancel, "Error")
Vehicle_typeTextBox.Focus() 'Returns cursor into the vehicle type text box
ElseIf (IsNumeric(Vehicle_typeTextBox.Text)) Then
MessageBox.Show("No numbers are allowed in the vehicle type title field", "",
MessageBoxButtons.OKCancel, MessageBoxIcon.Error)
Vehicle_typeTextBox.Focus() 'Returns cursor into the vehicle type text box
ElseIf (String.IsNullOrEmpty(Me.Make_typeTextBox.Text)) Then
MsgBox("Enter name ", vbOKCancel, "Error")
Make_typeTextBox.Focus() 'Returns cursor into the make text box
ElseIf (IsNumeric(Make_typeTextBox.Text)) Then
MessageBox.Show("No numbers are allowed in the make type feild", "",
MessageBoxButtons.OKCancel, MessageBoxIcon.Error)
Make_typeTextBox.Focus() 'Returns cursor into the make text box
ElseIf (String.IsNullOrEmpty(Me.Chassis_numberTextBox.Text)) Then
MsgBox("Enter class", vbOKCancel, "Error")

5
Chassis_numberTextBox.Focus() 'Returns cursor into the class text box
ElseIf (String.IsNullOrEmpty(Me.ModelTextBox.Text)) Then
MsgBox("Enter class", vbOKCancel, "Error")
ModelTextBox.Focus() 'Returns cursor into the model text box
ElseIf (String.IsNullOrEmpty(Me.Registration_numberTextBox.Text)) Then
MsgBox("Enter class", vbOKCancel, "Error")
Registration_numberTextBox.Focus() 'Returns cursor into the reg number text box
Else
InputDataOK = True 'Sets the InputdataOK to True. There are no errors
End If
End Sub

Circle progress bar


Note same as regular bar
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
myprogress.Increment(1) 'to increment the progress bar
Dim percentage As String
percentage = myprogress.Value
myprogresslb.Text = percentage & " %" 'for the label to countdown the percentage
If myprogress.Value = 100 Then
selection.Show() 'to show the selection form
Me.Hide() 'to hide the loading form
End If
End Sub
Double click on your file and type timer1.enabled

To validate if an email entered is correct


Dim email As String = txtemail.Text
Dim pattern As String = "^[A-Za-z0-9]+\@[A-Za-z0-9]+\.[A-Za-z0-9]+$"
Dim emailMatch As Match = Regex.Match(email, pattern)
Dim number As Integer
number = txtnumber.Text
If emailMatch.Success = True And number = "078101816" Then
MessageBox.Show("This is a valid email format")

6
MsgBox("Your username is QUEST and your password is motors")
selection.Show()
Me.Hide()
Else
MessageBox.Show("This is an invalid email format")
End If

End Sub

Code to search a record


Me.Table1BindingSource.Filter = "Firstname Like '" & txtname.Text & "%'"

7
===========S e i h k t c u s n las o 2023=========
------------------------------------------------------------------------------------------------------------------------------

You might also like