Cerbrus,

Thanks for your reply.

Some of the issues I asked about I have managed to find the answers to, one 
of which was the textbox property you spoke of.

Only issue I have left is with the digits in the display.  The user can now 
only enter 11 digits, however the result will over rub the textbox.  I have 
found how to set the digits after the decimal to be a maximum of three but 
can not find how to keep the overall digits to a max of 11.

I have pasted some of the code below.  Please make sure you are sitting down 
when you view the code so you do not fall down due to laughing so hard at me 
coding.  It is not to a high standard yet, partly because I am new, partly 
due requirements for the class.

Thanks again for your help


Private Sub Tbox_Display_TextChanged(ByVal sender As System.Object, ByVal e 
As System.EventArgs) Handles Tbox_Display.TextChanged
        Tbox_Display.BackColor = Color.White
        On Error GoTo UserError
        Memory_2 = CDbl(Tbox_Display.Text)
        'End If
ErrQuit:
        Exit Sub
UserError:
        Select Case Err.Number
            Case 13
                MsgBox("Please enter number." & vbCrLf & _
               "Error:" & Err.Number & vbCrLf & Err.Description, , "Input 
Error")
            Case 6
                MsgBox("Please check your data and re-enter a value between" 
& vbCrLf & _
                      "1.79769313486231570 E308 and -1.79769313486231570 
E308" & vbCrLf & _
                     "Error: " & Err.Number & vbCrLf & Err.Description, , 
"Input Error")
            Case Else
                If Err.Number <> 0 Then
                    MsgBox("Unexpected Error." & vbCrLf & "If error reoccurs 
please contact the developer with the following information" _
                & vbCrLf & "Error: " & Err.Number & vbCrLf & 
Err.Description, , "Input Error")
                End If
        End Select
        Tbox_Display.Text = "0"
        Resume ErrQuit
    End Sub

    Private Sub btn_Calculate_Click(ByVal sender As System.Object, ByVal e 
As System.EventArgs) Handles btn_Calculate.Click
        On Error GoTo CalError
        Select Case f
            Case 1
                If Memory_2 = 0 Then
                    Throw New DivideByZeroException
                End If
                Tbox_Display.Text = CStr(Memory_1 / Memory_2)
            Case 2
                Tbox_Display.Text = CStr(Memory_1 * Memory_2)
            Case 3
                Tbox_Display.Text = CStr(Memory_1 + Memory_2)
            Case 4
                Tbox_Display.Text = CStr(Memory_1 - Memory_2)
            Case 5
                Tbox_Display.Text = CStr(ResultSci)
        End Select
        Tbox_Display.Text = CStr(Math.Round(CDbl(Tbox_Display.Text), 3))
        If Tbox_Display.Text = "Infinity" Then
            Throw New OverflowException
        End If
CalError:
        Select Case Err.Number
            Case 11
                MsgBox("Division by zero is not allowed" & vbCrLf & _
                       "ERROR: " & Err.Number & vbCrLf & Err.Description, , 
"Calculation Error")
                Tbox_Display.Text = "0" : Memory_1 = 0 : Memory_2 = 0 : 
ResultSci = 0
            Case 6
                MsgBox("Your calculation has caused an over flow error." & 
vbCrLf & "Please check your data and try again." _
                       & vbCrLf & "Error: " & Err.Number & vbCrLf & 
Err.Description, , "Calculation Error")
                Tbox_Display.Text = "0" : Memory_1 = 0 : Memory_2 = 0 : 
ResultSci = 0
            Case Else
                If Err.Number <> 0 Then
                    MsgBox("Unexpected Error." & vbCrLf & "If error reoccurs 
please contact the developer with the following information" _
                           & vbCrLf & "Error: " & Err.Number & vbCrLf & 
Err.Description, , "Calculation Error")
                    Tbox_Display.Text = "0" : Memory_1 = 0 : Memory_2 = 0 : 
ResultSci = 0
                End If
        End Select
        c = 1
        a = 0
        Rbtn_Sin.Checked = False : Rbtn_Cos.Checked = False : 
Rbtn_Tan.Checked = False : Rbtn_Sqrt.Checked = False : Rbtn_Abs.Checked = 
False
        Rbtn_Abs.ForeColor = Color.Empty : Rbtn_Cos.ForeColor = Color.Empty 
: Rbtn_Sqrt.ForeColor = Color.Empty : Rbtn_Tan.ForeColor = Color.Empty : 
Rbtn_Sin.ForeColor = Color.Empty
    End Sub

** I am only including code for one button.

 Private Sub btn_8_Click(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles btn_8.Click
        If c = 1 Then
            c = 0 : Tbox_Display.Text = "0"
        End If
        If Tbox_Display.Text <> "0" Then
            Tbox_Display.Text = Tbox_Display.Text & "8"
        Else
            Tbox_Display.Text = "8"
        End If
    End Sub


--------------------------------------------------
From: "Cerebrus" <[EMAIL PROTECTED]>
Sent: Friday, November 07, 2008 10:51 PM
To: "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web 
Services,.NET Remoting" <[email protected]>
Subject: [DotNetDevelopment] Re: New to VB with three easy questions that 
still seem to have the  better of me

>
> 1. You will need to validate the current length of the number in the
> button click event. I'm assuming you have a single handler for all
> keypad buttons.
> 2. Show us the code you use to append the value of a button press and
> display the number in the textbox of the Calculator.
> 3. You might need to set the RightToLeft property of the Textbox to
> True. Again, it's difficult to be sure without seeing (the relevant
> part of) your code.
>
> On Nov 8, 12:29 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>> Hello all,
>> As the subject states I am now to VB, have been “playing” with it for
>> a whole 4 weeks now.
>> The three questions I have I know are going to be easy, but I cannot
>> find the answer. Just hoping someone here can point me in the right
>> direction.
>> And yes, this is for a project in a class I am taking.
>> The project is to build a calculator, for the most part, I have
>> everything working, my issues are:
>> 1. I have set the textbox properties for Maximum Length to 11.
>> However, my answers still come out with more than 11 digits. If I use
>> the keyboard to enter digits it will stop at 11, but I can enter as
>> many digits as I like when using the program keypad.
>> 2. My decimal point always starts to the left of my number, but moves
>> to the correct place when I enter the next digit. For example, if I
>> want to enter 3.6, my display will show .3 until I enter the 6 then it
>> will read 3.6.
>> 3. Finally, when I change the number from positive to negative the
>> negative sign is on the right hand side of the display.
>> If anyone can help my find the answers I would be very grateful.
>>
>> Doug{C}
> 

Reply via email to