How to Make a Services Calculator and Discount in VB.Net

This tutorial is all about How to Make a Services Calculator and Discount in VB.Net. With this tutorial you can Make a Services Calculator and Discount in VB.Net. easily. So let’s get started

  • First is open the Visual Basic, Select File on the menu, then click New and create a new project.

  • Then a New Project Dialog will appear. You can rename your project, depending on what you like to name it. After that click OK

  • Design your form like this just like what I’ve shown you below.

    Add 5 TextBoxes, 8 Labels & 4 Buttons from the Toolbox.

  • After Designing your form, Add this code to the button.
  • Calculate Button Code.
[vbnet]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Label5.Text = "Sub Total: " & (Val(TextBox1.Text) + Val(TextBox2.Text) + _
Val(TextBox3.Text) + Val(TextBox4.Text))
Label7.Text = "Total: " & (Val(TextBox1.Text) + Val(TextBox2.Text) _
+ Val(TextBox3.Text) + Val(TextBox4.Text)) - (Val((Val(TextBox1.Text) _
+ Val(TextBox2.Text) + Val(TextBox3.Text) _
+ Val(TextBox4.Text))) * Val(TextBox5.Text / 100))
Label8.Text = "Discount: " & (Val((Val(TextBox1.Text) + Val(TextBox2.Text) _
+ Val(TextBox3.Text) + Val(TextBox4.Text))) * Val(TextBox5.Text / 100))
Catch ex As Exception
MsgBox("Please Enter Valid Inputs")
End Try
End Sub
[/vbnet]
<li>Clear Button Code.<br></li>
[vbnet]
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
Label5.Text = "Sub Total:"
Label8.Text = "Discount:"
Label7.Text = "Total:"
End Sub
[/vbnet]
<li>Exit Button Code.<br></li>
[vbnet]
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
End
End Sub
[/vbnet]
<li>Print Button Code<br></li>
[vbnet]
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim g As Graphics = Me.CreateGraphics()
Dim s As Size = Me.Size
formImage = New Bitmap(s.Width, s.Height, g)
Dim mg As Graphics = Graphics.FromImage(formImage)
Dim dc1 As IntPtr = g.GetHdc
Dim dc2 As IntPtr = mg.GetHdc
Dim widthDiff As Integer = (Me.Width - Me.ClientRectangle.Width)
Dim heightDiff As Integer = (Me.Height - Me.ClientRectangle.Height)
Dim borderSize As Integer = widthDiff \ 2
Dim heightTitleBar As Integer = heightDiff - borderSize
BitBlt(dc2, 0, 0, Me.ClientRectangle.Width + widthDiff, Me.ClientRectangle.Height _
+ heightDiff, dc1, 0 - borderSize, 0 - heightTitleBar, 13369376)
g.ReleaseHdc(dc1)
mg.ReleaseHdc(dc2)
pd.Print()End Sub
[/vbnet]
<li>Then, Add this Following Declarations.<br></li>
[vbnet]
Private WithEvents pd As Printing.PrintDocument
Dim formImage As Bitmap
Private Declare Function BitBlt Lib "gdi32.dll" Alias "BitBlt" _
(ByVal hdcDest As IntPtr, ByVal nXDest As Integer, _
ByVal nYDest As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc As Integer, _
ByVal nYSrc As Integer, ByVal dwRop As System.Int32) As Long
[/vbnet]
<li>After that, Add This Following Sub.<br></li>
[vbnet]
Private Sub pd_PrintPage(ByVal sender As Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pd.PrintPage
e.Graphics.DrawImage(formImage, 100, 100)
End Sub
[/vbnet]
<li>Finally, Add the Following to the Form Load Event.<br></li>
[vbnet]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
pd = New Printing.PrintDocument
Me.StartPosition = FormStartPosition.CenterScreenEnd Sub[/vbnet]
<li>Click F5 to run the Program.<br>
Output:</li>

If you have any comments or suggestion about on How to Make a Services Calculator and Discount in VB.Net, Please Feel Free to contact our webpage.

Download How to Make a Services Calculator and Discount in VB.Net Code Here

Other articles you might read also:

Frequently Asked Questions

What does this VB.NET tutorial cover?

Focused VB.NET language or library tutorial showing a single concept with working code. Use as a building block when assembling a larger system.

What Visual Studio and SQL Server versions does this VB.NET project require?

Most projects use VB.NET WinForms on .NET Framework 4.5+ with SQL Server 2012 Express or higher. To run: install Visual Studio 2019 / 2022 (Community is free) with the ‘Desktop development with .NET’ workload, install SQL Server Express + SSMS, open the .sln file, build, run.

How do I set up the database for this VB.NET project?

Open SQL Server Management Studio (SSMS) and connect to your SQL Server (e.g. localhost\SQLEXPRESS). Right-click Databases, choose Restore Database OR New Database then import the included .sql script. Update the connection string in App.config (or in code-behind Module) with your server name + credentials. Rebuild and run.

Can I use this VB.NET project for a BSIT capstone or thesis?

Yes, VB.NET is one of the most accepted languages by Philippine BSIT panels. Extend it: add role-based access (admin/staff/customer login redirect), Crystal Reports or RDLC reports, dashboards with Chart control, audit log, multi-branch support. Pair with Chapter 1-5 documentation matching your panel’s rubric.

Why am I getting ‘connection error’ or ‘cannot find SQL Server’?

Three common VB.NET issues: (1) Connection error: SQL Server isn’t running. Open SQL Server Configuration Manager and verify SQL Server (SQLEXPRESS) service is started. (2) Wrong server name in connection string. Try .\SQLEXPRESS, (local)\SQLEXPRESS, or your machine name. (3) Login failed: SQL Server is set to ‘Windows-only’ authentication. Switch to Mixed Mode in SSMS Server Properties, Security.

Where can I find more VB.NET projects with source code?

Browse the VB.NET Projects hub for the full library. For C# WinForms alternatives see C# Projects. For ASP.NET web alternatives see ASP.NET Projects. For BSIT capstone idea lists see 150 Best Capstone Project Ideas.

Leave a Comment