VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 300,579 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,234 people online right now. Registration is fast and FREE... Join Now!




Calculator program problem

 

Calculator program problem, Decimal problem and adaption.

AdamR

23 Sep, 2008 - 08:05 AM
Post #1

D.I.C Head
**

Joined: 23 Sep, 2008
Posts: 144



Thanked: 7 times
My Contributions
Hey,

Using the tutorial posted by PyschoCoder i re-wrote the scripting used, using a module, to create the calculator. Gaining some practise within using modules to hold cases, variables etc.

I also adapted ina dding a memory function, memory store, recall, m+ and clear.

The problem i am having is with the decimal point button.
The way i have it is;
CODE

        If Status Then
            If Not Deccontain Then
                If Screen.Text.Length > 0 Then
                    If Not Screen.Text = "0" Then
                        Screen.Text = Screen.Text + Dec.Text
                        Deccontain = True
                    Else
                        Screen.Text = "0."
                    End If
                End If
            End If
        End If


Now the problem is, when the Screen Inputbox holds no value, no decimal point will add, so i cannot use 0. decimals.

All help is highly appreciated.

User is offlineProfile CardPM
+Quote Post


AdamR

RE: Calculator Program Problem

23 Sep, 2008 - 08:36 AM
Post #2

D.I.C Head
**

Joined: 23 Sep, 2008
Posts: 144



Thanked: 7 times
My Contributions
Ah ok i have figured this out myself.

For those it could be helpful to, following the tutorial here on DIC to make the calculator, the solution is.

On the Add, Minus, Div etc (Not SQR) add to set the status of input.text to falsee (showing it empty) and the decimal contain to false.

CODE

    Private Sub Add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Add.Click
        If Screen.Text.Length <> 0 Then
            If Func = String.Empty Then
                Hold1 = CDbl(Screen.Text)
                Screen.Text = String.Empty
                Status = False
                Deccontain = False
            Else


Above is not whole code, but to show where to change the two boolean values to false.
The in the Decimal button click itself, use:

CODE

        If Status Then
            If Not Deccontain Then
                If Screen.Text.Length > 0 Then
                    If Not Screen.Text = "0" Then
                        Screen.Text = Screen.Text + Dec.Text
                        Deccontain = True
                    End If
                End If
            End If
        Else
            Screen.Text = "0."
            Deccontain = True
            Status = True
        End If



As i re-wrote the code form scratch for practise, my variable and case names are different to those found in the tutorial. It will be easy to change the names to your own variable names.

I hope this can be of some use to others.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 08:25AM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month