
Converting decimals to fractions
I used this VB6 code (which was suggested to me) to convert Decimals to fractions which I call in the body by<BR><BR>DecToFrac(DataBinder.Eval (Container.DataItem, "ShredSizeWidth"), a, b) so it an convert,<BR><BR>for example 0.125 to 1/8"<BR><BR>but I get the following error:<BR><BR>Compiler Error Message: BC30451: Name 'a' is not declared.<BR><BR>The subs are:<BR><BR>Sub DecToFrac(DecimalNum As Double, Numerator As Long, Denom As Long)<BR> ' The BigNumber constant can be adjusted to handle larger fractional parts<BR> Const BigNumber = 50000<BR> Const SmallNumber = 1E16<BR><BR> Dim Inverse As Double, FractionalPart As Double<BR> Dim WholePart As Long, SwapTemp As Long<BR> <BR> Inverse = 1 / DecimalNum<BR> WholePart = Int(Inverse)<BR> FractionalPart = Frac(Inverse)<BR> <BR> If 1 / (FractionalPart + SmallNumber) < BigNumber Then<BR> ' Notice that DecToFrac is called recursively. <BR> Call DecToFrac(FractionalPart, Numerator, Denom)<BR> Numerator = Denom * WholePart + Numerator<BR> <BR> SwapTemp = Numerator<BR> Numerator = Denom<BR> Denom = SwapTemp<BR><BR> Else ' If 1 / (FractionalPart + SmallNumber) > BigNumber<BR> ' Recursion stops when the final value of FractionalPart is 0 or<BR> ' close enough. SmallNumber is added to prevent division by 0.<BR><BR> Numerator = 1<BR> Denom = Int(Inverse)<BR> End If<BR>End Sub<BR><BR>' This function is used by DecToFrac and DecToProperFact<BR><BR>Function Frac(x As Double) As Double<BR> Frac = Math.Abs(Math.Abs(x)  Int(Math.Abs(x))) <BR>End Function<BR><BR>' This additional procedure handles "improper" fractions and returns<BR>' them in mixed form (a b/c) when the numerator is larger than the denominator<BR><BR>Sub DecToProperFrac(x As Double, a As Long, b As Long, c As Long)<BR> If x > 1 Then a = Int(x)<BR> If Frac(x) <> 0 Then <BR> Call DecToFrac(Frac(x), b, c)<BR> End If<BR>End Sub<BR><BR><BR>Please Help.

I'm full of "one thoughts" this morning
One thought  <BR>You pass 'a' into your DecToProperFrac by Value and then you try to set the value of it which you shouldn't be able to do. Try stricking ByRef in front of it like Sub DecToProperFrac(ByRef a As Long) If that is what you acutally want to do.<BR>

RE: I'm full of
I placed it in the sub<BR><BR>Sub DecToProperFrac(x As Double, ByRef a As Long, ByRef b As Long, c As Long)<BR><BR>and it still didn't work, but thanks!!!

On further analysis
Didn't notice your subroutine call in your original message. The error is probally on that line. Where do you declare 'a' above there?

RE: On further analysis
DecToFrac(DataBinder.Eval (Container.DataItem, "ShredSizeWidth"), a, b) this is the specific call (correct?)<BR><BR>Are you tellin me to declare it like this?<BR><BR>Dim a As Long<BR>Dim B As Long<BR><BR>I'm new to ASP.Net, so I apologize for the elementry questions, and thank you for your help!!!<BR><BR>And I'm calling it in this IIF statement:<BR><BR><%# IIf (DataBinder.Eval(Container.DataItem, "ShredSizeWidth") Is DBNull.Value, "<tr><td width=""285""><font size=""2"" face=""Verdana, Arial, Helvetica, sansserif""> Shred Size</strong></font></td><td width=""285""><font size=""2"" color=""#FF0000""face=""Verdana, Arial, Helvetica, sansserif""> EMPTY</font></td></tr>", "<tr><td width=""285""><font size=""2"" face=""Verdana, Arial, Helvetica, sansserif""><strong> Shred Size</strong></font></td><td width=""285""><font size=""2"" face=""Verdana, Arial, Helvetica, sansserif""> " & DecToFrac(DataBinder.Eval(Container.DataItem, "ShredSizeWidth"), a, b) & "</font></td></tr>") %>

RE: On further analysis
Ok it appears you are calling the function with a bound item, and then two black variables but you dont declare the variables any where before you pass them to the function. I'm pretty sure that is what the problem is. It doesn't appear that you need to pass them either.
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

