Un programme en langage VBA qui convertit un nombre décimal U da
Fermé
advilcaps
-
20 nov. 2015 à 02:16
pijaku
pijaku
- Messages postés
- 12259
- Date d'inscription
- jeudi 15 mai 2008
- Statut
- Modérateur
- Dernière intervention
- 9 août 2022
A voir également:
- Un programme en langage VBA qui convertit un nombre décimal U da
- Convertir un nombre décimal en binaire langage c - Forum - Programmation
- Vba excel convertir en nombre ✓ - Forum - VB / VBA
- VBA convertir texte en nombre ✓ - Forum - Bureautique
- Convertir un entier binaire en decimal (Langage C) ?? ✓ - Forum - C
- Convertir nombre decimal à binaire ✓ - Forum - Programmation
1 réponse
pijaku
20 nov. 2015 à 08:28
- Messages postés
- 12259
- Date d'inscription
- jeudi 15 mai 2008
- Statut
- Modérateur
- Dernière intervention
- 9 août 2022
20 nov. 2015 à 08:28
Bonjour,
Ce code réalise ce que tu souhaites.
Ce code réalise ce que tu souhaites.
'********************************************************************************
' NAME: DecToBase
'********************************************************************************
' FUNCTION: Converts a base n number to a decimal one. Base can be between 2 and
' 36. Number can be up to 15 digits as a number, longer as a string.
' Outputs a string value.
'********************************************************************************
' AUTHOR: Jeff Jenkins - February 2011
'********************************************************************************
Function DecToBase(ByVal strBaseNumberToConvert As String, ByVal intBase As Integer) As String
'********************************************************************************
' Declare variables
'********************************************************************************
Dim dblRemainder As Double
Dim strRemainderChar As String
Dim dblLeftToDivide As Double
'********************************************************************************
' Initialise variables
'********************************************************************************
dblLeftToDivide = Val(strBaseNumberToConvert)
DecToBase = ""
'********************************************************************************
' Raise error if base 36 or number is greater than 15 digits
'********************************************************************************
If intBase > 36 Or Len(strBaseNumberToConvert) > 15 Then Err.Raise 5
'********************************************************************************
' Loop around building the number converted to base n as we go
'********************************************************************************
While dblLeftToDivide > 0
dblRemainder = dblLeftToDivide - Int(dblLeftToDivide / intBase) * intBase
strRemainderChar = Mid$("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", dblRemainder + 1, 1)
DecToBase = Trim(strRemainderChar) & DecToBase
dblLeftToDivide = Int(dblLeftToDivide / intBase)
Wend
End Function