Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
ciao!
stavolta non ho un problema...
Vb6 ha la funzione di convertire un numero in esadecimale con la funzione Hex(). Ma non è ha una per farlo tornare normale. Questo in varie occasioni mi ha seccato molto ma ho fatto una funzione Dec() che converte un esadecimale in decimale. Ve la posto in modo che se qualcuno ne avrà bisogno saprà che esiste un post in cui è scritta. La funzione la potete usare liberamente anche se preferirei che metteste un commento nel vostro progetto che mi citi.
Codice sorgente - presumibilmente VB.NET
PrivateFunction Dec(ByVal Number AsString)'Created by GrG
Dim temp AsString
Dim tmp AsString
Dim i AsInteger
Dim x AsInteger
Dim c AsLong
i =Len(CStr(Number))
temp =CStr(Number)
For x = 1 To i
tmp =Left(temp, 1)
temp =Right(temp, Len(temp)- 1)
If x = i Then
Dec = Dec & tmp
Else
Dec = Dec & tmp &"|"
EndIf
Next x
Dec =Replace(Dec, "A", "10")
Dec =Replace(Dec, "B", "11")
Dec =Replace(Dec, "C", "12")
Dec =Replace(Dec, "D", "13")
Dec =Replace(Dec, "E", "14")
Dec =Replace(Dec, "F", "15")
Dim d()AsString
d =Split(Dec, "|")
Dim f AsInteger
Dim m AsInteger
m =UBound(d())
Dec =""
For f = 0 ToUBound(d())
c = c +(d(f)*(16 ^ m))
m = m - 1
Next f
Dec = c
EndFunction
PrivateSub Form_Load()'esempio sull'utilizzo
MsgBox Dec("7B")
EndSub
Per richiamare la funzione basta che scriviate:
Dec ("numero esadecimale")
tra virgolette perchè all'inizio il numero viene trattato come una stringa...
altro esempio di utilizzo:
Codice sorgente - presumibilmente VB.NET
PrivateSub Form_Load()'esempio sull'utilizzo
Dim k
k =Hex(123)'valore = 7B
MsgBox Dec(k)'valore = 123
EndSub
p.s. Mi raccomando le lettere (A,B,C,D,E,F) del numero esadecimale DEVONO essere MAIUSCOLE, perchè il programma è CASESENSITIVE e darebbe errore.
Spero vi sia utile
Ultima modifica effettuata da GrG il 28/08/2008 alle 20:58