Hi Michelle,
>>> should I use a ByRef ?
Tell me the difference between ByRef and ByVal.
>>> Dim A, B, C, D, E, F, S As Integer
Tell me why you did that again.
What is the data type of each of those 7 variables ?
>>> A = InputBox("Enter first
numerator")
Are you using a copy of VB-6 that provides
what is called 'Intelli-Sense', where the
Development Environment shows you what the details
of what the built-in function expects to receive
as arguments, and what data type is returned by the function
?
The 'InputBox' is a built-in function available to VB-6.
After you look over those details, think about this:
Why would you receive the function's return value with
a variable that is declared as a Variant, or as an Integer ?
Answer those questions, and think about how you answer them.
>>> for calculating the greatest common divisor
(GCD)
If I recall correctly, the GCD is obtained
by multiplying the two denominators together.
The Least Common Denominator is a bit more complicated to
code.
>>> 1 / 2 + 3 / 4
Add those two fractions together, on a piece of paper, and
pay attention to every little tiny step, so you can
see what needs to be done in your Visual Basic Code.
Couldn't your GCD Function just return the result
produced by multiplying the two denominators ?
Hint:
All of the code in your Form_Load Sub Routine.....
...put that code in the Form_Activate Sub Routine.
That way the form will be shown to the User
before they see the InputBoxes, rather than the
User seeing all of the InputBoxes ( which seem
to magically appear from the 9th dimension )
before the Form becomes visible.
All The Best,
Steve
10:20 PM EST Thursday, November 30, 2006
From: helpwithvb@yahoogroups.com
[mailto:helpwithvb@yahoogroups.com] On Behalf Of michelle
mclain
Sent: Thursday, November 30, 2006 7:24 PM
To: helpwithvb@yahoogroups.com
Subject: [helpwithvb] help again--see of this is okay
Do I need to do something different or add something ?
should I use a byref? Or relplace 4 lines with Call
InputFractions? Thanks!
Description:
* The user enters two fractions each one specified as two
integers: a
numerator and a denominator.
* Then the program adds the fractions and prints the sum
both as a
fraction and as a decimal (floating point) number.
* For example, if the user enters 1/ 2 and 3/ 4, the program
prints::
1/2
3/4
The sum in fraction is 5/4
The sum in decimal is 1.25
Implementation and restrictions:
* Use input boxes for input and print on the form.
* Use a general Sub Procedure for entering and printing a
fraction
* Use a Function Procedure for calculating the greatest
common divisor
(GCD), needed for simplification of the resulting fraction.
I have:
' Compute A/B + C/D = E/F in rational numbers (fractions)
' Use GCD to simplify the sum
Private Sub Form_Click()
Dim A, B, C, D, E, F, S As Integer
A = InputBox("Enter first numerator")
B = InputBox("Enter first denominator")
C = InputBox("Enter second numerator")
D = InputBox("Enter second denominator")
E = A * D + B * C
F = B * D
S = GCD(E, F)
E = E / S
F = F / S
Print A; " / "; B; " + "; C; " /
"; D; " = "; E; "/"; F
Print A; " / "; B; " + "; C; " /
"; D; " = "; E / F
End Sub
Public Function GCD(ByVal X As Integer, ByVal Y As Integer)
As Integer
Dim R As Integer
Do While Y > 0
R = X Mod Y
X = Y
Y = R
Loop
GCD = X
End Function
.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://grou
ps.yahoo.com/group/helpwithvb/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://
groups.yahoo.com/group/helpwithvb/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:helpwithvb-digest@yahoogroups.com
mailto:helpwithvb-fullfeatured@yahoogroups.com
<*> To unsubscribe from this group, send an email to:
helpwithvb-unsubscribe@yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.c
om/info/terms/
|