M
mcnewsxp
can someone help me convert this VB code so it will work? i've made
the changes and it compiles and runs, but this line always makes the
dremainder = 0 - dRemainder = dValue - (byBase * Int((dValue /
byBase))).
Public Function ConvertDecToBaseN(ByVal dValue As Double, Optional
ByVal byBase As Byte = 36) As String
Const BASENUMBERS As String =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Dim dRemainder As Double
Dim sResult As String
On Error GoTo ErrorHandler
sResult = ""
If (byBase < 2) Or (byBase > 36) Then GoTo done
dValue = Abs(dValue)
Do
dRemainder = dValue - (byBase * Int((dValue / byBase)))
sResult = Mid(BASENUMBERS, dRemainder + 1, 1) & sResult
dValue = Int(dValue / byBase)
Loop While (dValue > 0)
done:
ConvertDecToBaseN = pad(sResult, 0, 8)
Exit Function
ErrorHandler:
'Err.Raise Err.Number, "ConvertDecToBaseN", Err.Description
MsgBox "Error in Module1.ConvertDecToBaseN", Err.Number,
Err.Description
End Function
here's my conversion attempt:
internal static string ConvertDecToBaseN(double dValue, byte? byBase)
{
const string BASENUMBERS =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
double dRemainder;
string sResult;
try
{
if (!byBase.HasValue)
{ byBase = 36; }
sResult = "";
if ((byBase < 2) || (byBase > 36))
{ }
else
{
dValue = Math.Abs(dValue);
do
{
dRemainder = dValue - ((double)byBase *
((dValue / (double)byBase)));
sResult = BASENUMBERS.Substring(Convert.ToInt32
(dRemainder) + 1, 1) + sResult;
dValue = Convert.ToInt32(dValue / byBase);
} while (dValue > 0);
}
return (sResult.PadLeft(8, '0'));
}
catch (Exception err)
{
string strTmp = "";
strTmp = strTmp + "\n Freezer Inventory Error # " +
(err.ToString());
strTmp = strTmp + "\nError in
Module1.ConvertDecToBaseN";
MessageBox.Show(strTmp);
return ("");
}
}
the changes and it compiles and runs, but this line always makes the
dremainder = 0 - dRemainder = dValue - (byBase * Int((dValue /
byBase))).
Public Function ConvertDecToBaseN(ByVal dValue As Double, Optional
ByVal byBase As Byte = 36) As String
Const BASENUMBERS As String =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Dim dRemainder As Double
Dim sResult As String
On Error GoTo ErrorHandler
sResult = ""
If (byBase < 2) Or (byBase > 36) Then GoTo done
dValue = Abs(dValue)
Do
dRemainder = dValue - (byBase * Int((dValue / byBase)))
sResult = Mid(BASENUMBERS, dRemainder + 1, 1) & sResult
dValue = Int(dValue / byBase)
Loop While (dValue > 0)
done:
ConvertDecToBaseN = pad(sResult, 0, 8)
Exit Function
ErrorHandler:
'Err.Raise Err.Number, "ConvertDecToBaseN", Err.Description
MsgBox "Error in Module1.ConvertDecToBaseN", Err.Number,
Err.Description
End Function
here's my conversion attempt:
internal static string ConvertDecToBaseN(double dValue, byte? byBase)
{
const string BASENUMBERS =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
double dRemainder;
string sResult;
try
{
if (!byBase.HasValue)
{ byBase = 36; }
sResult = "";
if ((byBase < 2) || (byBase > 36))
{ }
else
{
dValue = Math.Abs(dValue);
do
{
dRemainder = dValue - ((double)byBase *
((dValue / (double)byBase)));
sResult = BASENUMBERS.Substring(Convert.ToInt32
(dRemainder) + 1, 1) + sResult;
dValue = Convert.ToInt32(dValue / byBase);
} while (dValue > 0);
}
return (sResult.PadLeft(8, '0'));
}
catch (Exception err)
{
string strTmp = "";
strTmp = strTmp + "\n Freezer Inventory Error # " +
(err.ToString());
strTmp = strTmp + "\nError in
Module1.ConvertDecToBaseN";
MessageBox.Show(strTmp);
return ("");
}
}