
May 3rd, 2021, 10:11 AM
#1
Thread Starter
Registered User
Frustrating and Inaccurate Arithmetic calculator program
Hi! I am making an Arithmetic calculator using VB 6.0 and I wonder why the result is not accurate.
See, I am inputting 1 on Common Difference, 1 on Initial Term, and 100 on Term Interval. Now its result is 5,050 on the program but when it comes to 1, 1, and 6, its result is 1 now why is that?
here is the code:
Code:
Option Explicit
Private Sub btCalc_Click()
Dim A As Double
Dim N As Double
Dim D As Double
Dim R As Double
Dim F As Double
A = GetFrac(txtInitterm.Text)
N = GetFrac(txtTermint.Text)
D = GetFrac(txtFinterm.Text)
R = GetFrac(txtTermint.Text)
F = N / 2 * (2 * A + (N  1) * D)
lblOutput.Caption = F
End Sub

May 3rd, 2021, 10:33 AM
#2
Re: Frustrating and Inaccurate Arithmetic calculator program
You mention 100 on Term Interval. You have four variables which are single letters, so you leave us to guess which letter holds which value. In this case, you have both N and R getting the value from the same textbox, so N and R are the same thing. R is never used, so I assume it is a mistake.
If we take your equation, and substitute in the values:
A = 1 (Initial Term)
N = 100 (Term Interval)
D = 1 (Common Difference)
I'm just guessing on D, because there is no relationship between txtFinterm and "Common Difference", but it's the only variable left. If that's right, then the equation becomes:
F = 100/2 * (2 * 1 + (11) * 1)
F = 100/2 * (2 + 0 * 1)
F = 100/2 * 2
F = 100/4
F = 25
F = 6/2 * (2 * 1 + (1  1) * 1)
F = 6/2 * 2
F = 6/4
F = 1.5
I may have some math a bit off, but I can't come up with 5,050 for the first, or 1 for the second, based on the assumptions I made about which variables are which.
Basically: You need to explain a bit more. Which values are in A, N, and D? What is R doing there if you don't use it? Why is R the same as N? What does GetFrac() do?
My usual boring signature: Nothing

May 3rd, 2021, 10:37 AM
#3
Re: Frustrating and Inaccurate Arithmetic calculator program
Can you also share the code for GetFrac?
/edit I was a little slow it seems

May 3rd, 2021, 03:52 PM
#4
Re: Frustrating and Inaccurate Arithmetic calculator program
Yep that math is off a bit
F = 100/2 * 2
F = 100/4
F = 25
F = 6/2 * (2 * 1 + (1  1) * 1)
F = 6/2 * 2
F = 6/4
F = 1.5
100/2*2=100
6/2*2=6
it would need to be 100/(2*2) to result in 25

May 3rd, 2021, 05:02 PM
#5
Re: Frustrating and Inaccurate Arithmetic calculator program
The only thing I see that you did RIGHT, is you used the recommended naming convention for your label (lblOutput). Other than that, your use of single letter variables is one surely confusing way to do things. At least you used Option Explicit (you got THAT right too). AND, you indented your code for this forum...thank you....maybe you ARE doing some things right.
So, how about explaining a tad bit better what you are attempting to do; what your inputs are (EACH OF THEM); and what you expect to see as outputs.
Oh, do you know how to use the debugger and step through your code so you can see what each variable contains (per line/variable)?
And lastly, welcome to the forum.
Sammi
Sam I am (as well as Confused at times).

May 3rd, 2021, 11:09 PM
#6
Thread Starter
Registered User
Frustrating and Inaccurate Arithmetic calculator program
Hi! I am making an Arithmetic calculator using VB 6.0 and I wonder why the result is not accurate.
See, I am inputting 1 on Final Term, 1 on Initial Term, and 100 on Term Interval. Now its result is 5,050 on the program (yes 5,050 is correct based on the Casio Online Arithmetic Progression Calculator). but when it comes to 1, 1, and 6, its result is 1 now, why is that?
Sorry If I didn't replied. It's because I'm asleep...
EDIT: Here is a clip:
I'm uploading a clip please wait...
here is the code:
Code:
Option Explicit
Private Sub btCalc_Click()
Dim InitialTerm As Double
Dim TermInterval As Double
Dim FinalTerm As Double
Dim Equiv As Double
InitialTerm = CDbl(txtInitterm.Text)
TermInterval = CDbl(txtTermint.Text)
FinalTerm = CDbl(txtFinterm.Text)
Equiv = N / 2 * (2 * A + (N  1) * D)
lblOutput.Caption = F
End Sub

May 3rd, 2021, 11:28 PM
#7
Re: Frustrating and Inaccurate Arithmetic calculator program
Near as I can tell your terminology is wrong and/or you are potentially entering the wrong data in the wrong box.
The initial term is 1. The final term is 100. The "Term interval", which I'm assuming is what you also called the "common difference" in your initial post, is 1.
Sn = (n/2) * (a1 + an)
And an = a1 + (n  1) * d
So Sn = (n/2) * (a1 + a1 + (n  1) * d)
Sn = (n/2) * (2 * a1 + (n  1) * d)
Your formula looks correct if each variable is properly assigned the appropriate value, which I'm thinking is likely the cause. Also, the code you just posted doesn't work at all because you changed the variable names everywhere except in the actual line of code that does the calculation.
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
