Need Help Please with VB.Net Claculator. Trying to get Text Colors to work & others

MarcusBell

Member
Joined
Feb 1, 2005
Messages
12
Programming Experience
Beginner
Need Help Please with VB.Net Claculator. Trying to get Text Colors to work & others

Hello

Hopefully some one will be able to help me? I am creating a calculator. I have zipped it and aatched it. What I am trying to do is many things. When you open it you will see two display fields. When you press the number buttons the number and the operand show appear in the big right side display box. and the number in the upper smallerer Displaybox. Every time you click a number and other operators they are shown in the big display box and the the new number.

I also have a background colors under menu format working, I don't think I have and problems there? I also have a test color, which for the most works, however when I change the color I seem to lose the function of the clalculator in respect to pressing further numbers? I have the Bold, Underline and Italic too. They work for the most, except when I do Italic and font for some reason in the large display boc to the right the underline goes through the number??.

Another problem I am having is that once I open the claculator and start doing math it seems to work, howeever once I clear and restart other calculations, it is for some reason grabbing from some where?? the last number and applying it to the new one I amd doing?

And one last thing, I am trying to get a Try Catch to work?? I have it commented out, for each operator, I really having a hard time on this one. I want to put a catch in to catch for overflows and other possible errors?

Can some please have a look? I would really appriciate it!!!


I never though doing a calculator would be so complecated LOL


Regards

Marcus Bell (Newbie)
 

MarcusBell

Member
Joined
Feb 1, 2005
Messages
12
Programming Experience
Beginner
Sorry here is the Prgram zipped

Sorry here is the Prgram zipped
 

MarcusBell

Member
Joined
Feb 1, 2005
Messages
12
Programming Experience
Beginner
Sorry zip is too big I have pasted it in sorry

Dim sum As Integer = 0

Dim num As Integer

Dim NewValue As Boolean = True

Private Sub mnuLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuLeft.Click

lblDisplay2.TextAlign = HorizontalAlignment.Left

lblDisplay1.TextAlign = HorizontalAlignment.Left

End Sub

Private Sub mnuRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuRight.Click

lblDisplay2.TextAlign = HorizontalAlignment.Right

lblDisplay1.TextAlign = HorizontalAlignment.Right

End Sub

Private Sub mnuCenter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCenter.Click

lblDisplay2.TextAlign = HorizontalAlignment.Center

lblDisplay1.TextAlign = HorizontalAlignment.Center

End Sub

Private Sub mnuEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEdit.Click

If lblDisplay1.Text = "" Then

mnuCut.Enabled = False

mnuCopy.Enabled = False

Else

mnuCut.Enabled = True

mnuCopy.Enabled = True

End If

End Sub

Private Sub mnuCut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCut.Click

Clipboard.SetDataObject(lblDisplay1.Text)

lblDisplay1.Text = ""

lblDisplay2.Text = ""

End Sub

Private Sub mnuCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCopy.Click

Clipboard.SetDataObject(lblDisplay1.Text)

Clipboard.SetDataObject(lblDisplay2.Text)

End Sub

Private Sub mnuPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPaste.Click

Dim iData As IDataObject = Clipboard.GetDataObject()

txtinfoBox.Text =
CType(iData.GetData(DataFormats.Text), String)

End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

Dim result As DialogResult

result = MessageBox.Show("Are you sure?", "Exit Program", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)

If result = DialogResult.OK Then

Application.Exit()

End If

End Sub

Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click

Dim result As DialogResult

result = MessageBox.Show("Are you sure?", "Exit Program", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)

If result = DialogResult.OK Then

Application.Exit()

End If

End Sub

Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click

If NewValue = True Then

lblDisplay1.Text = "7"

NewValue =
False

Else

lblDisplay1.Text = lblDisplay1.Text & "7"

End If

sum.ToString()

End Sub

Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click

If NewValue = True Then

lblDisplay1.Text = "8"

NewValue =
False

Else

lblDisplay1.Text = lblDisplay1.Text & "8"

End If

sum.ToString()

End Sub

Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click

If NewValue = True Then

lblDisplay1.Text = "9"

NewValue =
False

Else

lblDisplay1.Text = lblDisplay1.Text & "9"

End If

sum.ToString()

End Sub

Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click

If NewValue = True Then

lblDisplay1.Text = "4"

NewValue =
False

Else

lblDisplay1.Text = lblDisplay1.Text & "4"

End If

sum.ToString()

End Sub

Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click

If NewValue = True Then

lblDisplay1.Text = "5"

NewValue =
False

Else

lblDisplay1.Text = lblDisplay1.Text & "5"

End If

sum.ToString()

End Sub

Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click

If NewValue = True Then

lblDisplay1.Text = "6"

NewValue =
False

Else

lblDisplay1.Text = lblDisplay1.Text & "6"

End If

sum.ToString()

End Sub

Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click

If NewValue = True Then

lblDisplay1.Text = "1"

NewValue =
False

Else

lblDisplay1.Text = lblDisplay1.Text & "1"

End If

sum.ToString()

End Sub

Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click

If NewValue = True Then

lblDisplay1.Text = "2"

NewValue =
False

Else

lblDisplay1.Text = lblDisplay1.Text & "2"

End If

sum.ToString()

End Sub

Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click

If NewValue = True Then

lblDisplay1.Text = "3"

NewValue =
False

Else

lblDisplay1.Text = lblDisplay1.Text & "3"

End If

sum.ToString()

End Sub

Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click

If NewValue = True Then

lblDisplay1.Text = "0"

NewValue =
False

Else

lblDisplay1.Text = lblDisplay1.Text & "0"

End If

sum.ToString()

End Sub

Private Sub btnPlus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlus.Click

sum = sum + Convert.ToInt16(lblDisplay1.Text)

lblDisplay1.Text = sum.ToString()

NewValue =
True

If NewValue = True Then

lblDisplay2.Text = System.Convert.ToString(lblDisplay1.Text) & "+"

End If

'

'Try

' lblDisplay1.Text = Convert.ToInt16(lblDisplay1.Text) / Convert.ToInt16(lblDisplay2.Text)

' Application.DoEvents()

' Dim wm As Integer

' While True

' wm += 1

' End While

'Catch ovEx As OverflowException

' MessageBox.Show("You generated an overflow...message is :" & ovEx.Message)

'Catch ex As Exception

' MessageBox.Show(ex.Message)

'Finally

' MessageBox.Show("Goodbye")

'End Try



End Sub

Private Sub btnMinus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMinus.Click

sum = sum - Convert.ToInt16(lblDisplay1.Text)

lblDisplay1.Text = sum.ToString()

NewValue =
True

If NewValue = True Then

lblDisplay2.Text = System.Convert.ToString(lblDisplay1.Text) & "-"

End If

'Try

' lblDisplay1.Text = Convert.ToInt16(lblDisplay1.Text) / Convert.ToInt16(lblDisplay2.Text)

' Application.DoEvents()

' Dim wm As Integer

' While True

' wm += 1

' End While

'Catch ovEx As OverflowException

' MessageBox.Show("You generated an overflow...message is :" & ovEx.Message)

'Catch ex As Exception

' MessageBox.Show(ex.Message)

'Finally

' MessageBox.Show("Goodbye")

'End Try

End Sub

Private Sub btnMultiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMultiply.Click

sum = sum * Convert.ToInt16(lblDisplay1.Text)

lblDisplay1.Text = sum.ToString()

NewValue =
True

If NewValue = True Then

lblDisplay2.Text = System.Convert.ToString(lblDisplay1.Text) & "*"

End If

'Try

' lblDisplay1.Text = Convert.ToInt16(lblDisplay1.Text) / Convert.ToInt16(lblDisplay2.Text)

' Application.DoEvents()

' Dim wm As Integer

' While True

' wm += 1

' End While

'Catch ovEx As OverflowException

' MessageBox.Show("You generated an overflow...message is :" & ovEx.Message)

'Catch ex As Exception

' MessageBox.Show(ex.Message)

'Finally

' MessageBox.Show("Goodbye")

'End Try

End Sub

Private Sub btnDivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDivide.Click

sum = sum / Convert.ToInt16(lblDisplay1.Text)

lblDisplay1.Text = sum.ToString()

NewValue =
True

If NewValue = True Then

lblDisplay2.Text = System.Convert.ToString(lblDisplay1.Text) & "/"

End If

'Try

' lblDisplay1.Text = Convert.ToInt16(lblDisplay1.Text) / Convert.ToInt16(lblDisplay2.Text)

' Application.DoEvents()

' Dim wm As Integer

' While True

' wm += 1

' End While

'Catch ovEx As OverflowException

' MessageBox.Show("You generated an overflow...message is :" & ovEx.Message)

'Catch ex As Exception

' MessageBox.Show(ex.Message)

'Finally

' MessageBox.Show("Goodbye")

'End Try

End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click

lblDisplay1.Text = ""

lblDisplay2.Text = ""

End Sub



Private Sub mnuAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAbout.Click

Dim f2 As Form2

f2 =
New Form2

f2.ShowDialog()

End Sub

Private Sub btnDecimal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDecimal.Click

num = num + Convert.ToInt16(lblDisplay1.Text)

lblDisplay1.Text = num.ToString()

NewValue =
True

If lblDisplay1.Text = True Then

lblDisplay2.Text = lblDisplay2.Text & "."

End If

'Try

' lblDisplay1.Text = Convert.ToInt16(lblDisplay1.Text) / Convert.ToInt16(lblDisplay2.Text)

' Application.DoEvents()

' Dim wm As Integer

' While True

' wm += 1

' End While

'Catch ovEx As OverflowException

' MessageBox.Show("You generated an overflow...message is :" & ovEx.Message)

'Catch ex As Exception

' MessageBox.Show(ex.Message)

'Finally

' MessageBox.Show("Goodbye")

'End Try

End Sub

Private Sub mnuBColors_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuBColors.Click

cdselectColors.ShowDialog()

lblDisplay1.BackColor = cdselectColors.Color

lblDisplay2.BackColor = cdselectColors.Color

Call UpdateMenuItems()

End Sub

Private Sub UpdateMenuItems()

If lblDisplay1.Font.Italic = True Then

mnuItalic.Checked = True

Else

mnuItalic.Checked = False

End If

If lblDisplay1.Font.Bold = True Then

mnuBold.Checked = True

Else

mnuBold.Checked = False

End If

If lblDisplay1.Font.Underline = True Then

mnuUnderline.Checked = True

Else

mnuUnderline.Checked = False

End If

'

If lblDisplay2.Font.Italic = True Then

mnuItalic.Checked = True

Else

mnuItalic.Checked = False

End If

If lblDisplay2.Font.Bold = True Then

mnuBold.Checked = True

Else

mnuBold.Checked = False

End If

If lblDisplay2.Font.Underline = True Then

mnuUnderline.Checked = True

Else

mnuUnderline.Checked = False

End If

End Sub

Private Sub mnuBold_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuBold.Click

Dim pfntCurrent As System.Drawing.Font

Dim pintstyle As Integer

If lblDisplay1.Font.Underline = True Then

pintstyle += System.Drawing.FontStyle.Underline

End If

If lblDisplay1.Font.Italic = True Then

pintstyle += System.Drawing.FontStyle.Italic

End If

If lblDisplay1.Font.Bold = False Then

pintstyle += System.Drawing.FontStyle.Bold

mnuBold.Checked =
True

Else

mnuBold.Checked = False

End If

pfntCurrent = lblDisplay1.Font

lblDisplay1.Font = _

New System.Drawing.Font(pfntCurrent.FontFamily, pfntCurrent.Size, _

CType(pintstyle, System.drawing.FontStyle))

mnuBold.Checked =
True

'

If lblDisplay2.Font.Underline = True Then

pintstyle += System.Drawing.FontStyle.Underline

End If

If lblDisplay2.Font.Italic = True Then

pintstyle += System.Drawing.FontStyle.Italic

End If

If lblDisplay2.Font.Bold = False Then

pintstyle += System.Drawing.FontStyle.Bold

mnuBold.Checked =
True

Else

mnuBold.Checked = False

End If

pfntCurrent = lblDisplay1.Font

lblDisplay2.Font = _

New System.Drawing.Font(pfntCurrent.FontFamily, pfntCurrent.Size, _

CType(pintstyle, System.drawing.FontStyle))

mnuBold.Checked =
True

End Sub

Private Sub mnuItalic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuItalic.Click

Dim pfntCurrent As System.Drawing.Font

Dim pintstyle As Integer

If lblDisplay1.Font.Underline = True Then

pintstyle += System.Drawing.FontStyle.Underline

End If

If lblDisplay1.Font.Bold = True Then

pintstyle += System.Drawing.FontStyle.Bold

End If

If lblDisplay1.Font.Italic = False Then

pintstyle += System.Drawing.FontStyle.Italic

mnuItalic.Checked =
True

Else

mnuItalic.Checked = False

End If

pfntCurrent = lblDisplay1.Font

lblDisplay2.Font = _

New System.Drawing.Font(pfntCurrent.FontFamily, pfntCurrent.Size, _

CType(pintstyle, System.drawing.FontStyle))

'

If lblDisplay2.Font.Underline = True Then

pintstyle += System.Drawing.FontStyle.Underline

End If

If lblDisplay2.Font.Bold = True Then

pintstyle += System.Drawing.FontStyle.Bold

End If

If lblDisplay2.Font.Italic = False Then

pintstyle += System.Drawing.FontStyle.Italic

mnuItalic.Checked =
True

Else

mnuItalic.Checked = False

End If

pfntCurrent = lblDisplay1.Font

lblDisplay2.Font = _

New System.Drawing.Font(pfntCurrent.FontFamily, pfntCurrent.Size, _

CType(pintstyle, System.drawing.FontStyle))

End Sub

Private Sub mnuUnderline_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuUnderline.Click

Dim pfntCurrent As System.Drawing.Font

Dim pintstyle As Integer

If lblDisplay1.Font.Italic = True Then

pintstyle += System.Drawing.FontStyle.Italic

End If

If lblDisplay1.Font.Bold = True Then

pintstyle += System.Drawing.FontStyle.Bold

End If

If lblDisplay1.Font.Underline = False Then

pintstyle += System.Drawing.FontStyle.Underline

mnuUnderline.Checked =
True

Else

mnuUnderline.Checked = False

End If

pfntCurrent = lblDisplay1.Font

lblDisplay1.Font = _

New System.Drawing.Font(pfntCurrent.FontFamily, pfntCurrent.Size, _

CType(pintstyle, System.drawing.FontStyle))

'

If lblDisplay2.Font.Italic = True Then

pintstyle += System.Drawing.FontStyle.Italic

End If

If lblDisplay2.Font.Bold = True Then

pintstyle += System.Drawing.FontStyle.Bold

End If

If lblDisplay2.Font.Underline = False Then

pintstyle += System.Drawing.FontStyle.Underline

mnuUnderline.Checked =
True

Else

mnuUnderline.Checked = False

End If

pfntCurrent = lblDisplay1.Font

lblDisplay2.Font = _

New System.Drawing.Font(pfntCurrent.FontFamily, pfntCurrent.Size, _

CType(pintstyle, System.drawing.FontStyle))

End Sub

Private Sub mnuTColors_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuTColors.Click

fdSelectFonts.ShowColor =
True

fdSelectFonts.ShowApply = True

fdSelectFonts.ShowDialog()

End Sub

Private Sub fdSelectFonts_Apply(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles fdSelectFonts.Apply

fdSelectFonts.ShowDialog()

lblDisplay2.ForeColor = fdSelectFonts.Color

lblDisplay1.ForeColor = fdSelectFonts.Color

Call UpdateMenuItems()

End Sub

End
Class

 

MarcusBell

Member
Joined
Feb 1, 2005
Messages
12
Programming Experience
Beginner
Ok I think I got the Zip small enough now

Ok I think I got the Zip small enough now



really sorry about this people !!!!!!
 

Attachments

Top Bottom