Hello,
I am not sure what is wrong with the code for this error to happen when the program is being executed via an exe file.
The code is below:
If anyone knows what's wrong then please tell me.
Thanks.
I am not sure what is wrong with the code for this error to happen when the program is being executed via an exe file.
The code is below:
Code:
Public Class frmMain
' Declare a number of variables
Dim height1 As Single
Dim height2 As Single
Dim height3 As Single
Dim height4 As Single
Dim width1 As Single
Dim width2 As Single
Dim width3 As Single
Dim width4 As Single
Dim TotalArea As Single
Dim PaintPrice As Single
Dim UndercoatPrice As Single
Dim TotalCost As Single
Private Sub grpTotalArea_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles grpTotalArea.Enter
End Sub
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
' Sent the Prinout to Print Preview
PrintPreviewDialog.Document = PrintDocument
' Show Print Preview
PrintPreviewDialog.ShowDialog()
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument.PrintPage
' The code to print is below...
' Define local cariables
Dim x, y, size, FontHeight As Integer
Dim MyFont As New Font("Arial", 12, FontStyle.Regular)
' Define Display Line ... used to build the line to be printed
Dim DLine As String
Dim DLine2 As String
Dim DLine3 As String
Dim DLine4 As String
' Calculate the font height
FontHeight = MyFont.GetHeight(e.Graphics)
' Set X and Y
x = 50
y = 50
' Print Heading
e.Graphics.DrawString("Paint Calculator", MyFont, Brushes.Black, x, y)
y = y + FontHeight
' Print a blank line
e.Graphics.DrawString("", MyFont, Brushes.Black, x, y)
y = y + FontHeight
' Build the line to be printed
DLine = "Total Area = " & txtTotalArea.Text
DLine2 = "Paint = " & txtPaint.Text
DLine3 = "Undercoat = " & txtUndercoat.Text
DLine4 = "Grand Total = " & txtTotal.Text
' Print line
e.Graphics.DrawString(DLine, MyFont, Brushes.Black, x, y)
y = y + FontHeight
' Print line
e.Graphics.DrawString(DLine2, MyFont, Brushes.Black, x, y)
y = y + FontHeight
' Print line
e.Graphics.DrawString(DLine3, MyFont, Brushes.Black, x, y)
y = y + FontHeight
' Print line
e.Graphics.DrawString(DLine4, MyFont, Brushes.Black, x, y)
y = y + FontHeight
End Sub
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
On Error GoTo ERRORMESSAGE
' This will calculate the Total Area
TotalArea = (txtHeight1.Text * txtWidth1.Text) + (txtHeight2.Text * txtWidth2.Text) + (txtHeight3.Text * txtWidth3.Text) _
+ (txtHeight4.Text * txtWidth4.Text)
' This will display the Total Area in the textbox txtTotalArea
txtTotalArea.Text = TotalArea
' This will check to see if the radio button radEconomy is checked and if it is then give the PaintPrice 1.75
If radEconomy.Checked = True Then
PaintPrice = 0.45
End If
' This will check to see if the radio button radEconomy is checked and if it is then give the PaintPrice 1.0
If radStandard.Checked = True Then
PaintPrice = 1.0
End If
' This will check to see if the radio button radEconomy is checked and if it is then give the PaintPrice 0.45
If radLuxury.Checked = True Then
PaintPrice = 1.45
End If
' This will check to see if the radio button radEconomy is checked and if it is then give the PaintPrice 0.5 or if it isn't checked give it 0
If chkUndercoat.Checked = True Then
UndercoatPrice = 0.5
Else
UndercoatPrice = 0
End If
' This will put the paint price in the textbox txtPaint
txtPaint.Text = PaintPrice
' This will put the undercoat price in the textbox txtUndercoat
txtUndercoat.Text = UndercoatPrice
TotalCost = (TotalArea * PaintPrice) + (TotalArea * UndercoatPrice)
txtTotal.Text = TotalCost
btnBill.Show()
ERRORMESSAGE:
MsgBox("Sorry, you've entered something that shouldn't have been entered.", MsgBoxStyle.Critical)
End Sub
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' When the program executes do the following:
btnBill.Hide()
' This sets whatever is in txtHeight1.Text to height1 and this applies for all of the height values where appropiate
height1 = txtHeight1.Text
height2 = txtHeight2.Text
height3 = txtHeight3.Text
height4 = txtHeight4.Text
' This sets whatever is in txtWidth1.Text to width1 and this applies for all of the width values where appropiate
width1 = txtWidth1.Text
width2 = txtWidth2.Text
width3 = txtWidth3.Text
width4 = txtWidth4.Text
' This sets whatever is in txtPaint.Text to PaintPrice
PaintPrice = txtPaint.Text
' This sets whatever is in txtUndercoat.Text to UndercoatPrice
UndercoatPrice = txtUndercoat.Text
End Sub
Private Sub grpTotal_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles grpTotal.Enter
End Sub
Private Sub btnBill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBill.Click
' This means show the form frmBill
frmBill.Show()
End Sub
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
' The following will reset the form back to its original settings where "" means fill the textboxes blank
' This hides the button btnBill
btnBill.Hide()
txtHeight1.Text = ""
txtHeight2.Text = ""
txtHeight3.Text = ""
txtHeight4.Text = ""
txtWidth1.Text = ""
txtWidth2.Text = ""
txtWidth3.Text = ""
txtWidth4.Text = ""
txtTotalArea.Text = ""
txtTotal.Text = ""
txtPaint.Text = ""
txtUndercoat.Text = ""
' This sets the radio buttons and checkbox back to False so that they are unticked/unchecked
radEconomy.Checked = False
radLuxury.Checked = False
radStandard.Checked = False
chkUndercoat.Checked = False
End Sub
End Class
Thanks.