Erreur de compilation , argument non facultatif
Bonjour à tous, j'ai un problème de compilation comme inscris dans le titre. Pourtant je rentre bien un argument dans ma fonction, je ne comprends pas trop pourquoi ça ne fonctionne pas. Si qqn pourrait m'aiguiller ce serait cool :)
Mon variable check me renvoie bien 8, ce qui correspond bien à un string, mais j'arrive pas à rentrer dans ma fonction "Function hex_string_to_ulong(MyString As String) As Long"
Merci d'avance :)
Private Sub test()
Dim toto As String
Dim tata As Long
toto = "ffffffff"
MyCheck = VarType(toto)
Debug.Print "variable de type :" & MyCheck
tata = hex_string_to_ulong(toto)
Debug.Print "test: " & tata
End Sub
Function hex_string_to_ulong(MyString As String) As Long
default_val = 0
Debug.Print "My string : " & MyString
'on récupère la valeur du premier caractère héxadécimal qui contient le bit de poids fort
premierCaractereHexa = hex_string_to_ulong((Mid(MyString)), 1, 1)
'Si le dernier caractère est > 7 le bit de poids fort sera forcément = 1
'8 -> 1000, 9 -> 1001, A -> 1010, B -> 1011, C -> 1100, D -> 1101, E -> 1110, F -> 1111
If ((premierCaractereHexa > 7)) Then
'récupération de l'adresse/data sans le séparateur "_" et sans le premier caractère hexa
'et conversion en décimal grâce à la fonction ""hex_string_to_uint""
default_val = hex_string_to_ulong(Mid(Replace(MyString), "_", ""), 2, 8)
'(dernierCaractereHexa - 8) permet de retirer le bit de signe
'la multiplication par 2 ^ 28 permet de remettre ce caractère hexadécimal en premier
suppresionBitSigne = default_val + (premierCaractereHexa - 8) * 2 ^ 28
'2^31 = 8000 0000 hexa, ce qui permet d'avoir un complément à 2
'et d'avoir un nombre négatif qui ne sera pas en dépassement de capacité de la donnée de type Long
default_val = suppresionBitSigne - 2147483648#
Else
'sinon on exécute la fonction de conversion decimal to hexa classique
default_val = hex_string_to_uint(Replace(MyString), "_", "")
End If
hex_string_to_ulong = default_val
End Function
Function hex_string_to_long(data_in As String) As Long
hex_string_to_long = 0
temp_str = "" & LCase(data_in)
nb_char = Len(temp_str)
i = 1
While i <= nb_char
hex_string_to_long = hex_string_to_long * 16
Select Case Mid(temp_str, i, 1)
Case "0"
hex_string_to_long = hex_string_to_long
Case "1"
hex_string_to_long = hex_string_to_long + 1
Case "2"
hex_string_to_long = hex_string_to_long + 2
Case "3"
hex_string_to_long = hex_string_to_long + 3
Case "4"
hex_string_to_long = hex_string_to_long + 4
Case "5"
hex_string_to_long = hex_string_to_long + 5
Case "6"
hex_string_to_long = hex_string_to_long + 6
Case "7"
hex_string_to_long = hex_string_to_long + 7
Case "8"
hex_string_to_long = hex_string_to_long + 8
Case "9"
hex_string_to_long = hex_string_to_long + 9
Case "a"
hex_string_to_long = hex_string_to_long + 10
Case "b"
hex_string_to_long = hex_string_to_long + 11
Case "c"
hex_string_to_uint = hex_string_to_uint + 12
Case "d"
hex_string_to_uint = hex_string_to_uint + 13
Case "e"
hex_string_to_uint = hex_string_to_uint + 14
Case "f"
hex_string_to_long = hex_string_to_long + 15
Case Else
hex_string_to_long = hex_string_to_long
End Select
i = i + 1
Wend
End FunctionBonjour,
A première vue, il y a un souci au niveau de la syntaxe de la fonction replace, avec une parenthèse fermante saisie trop tôt, avant les 2 derniers arguments obligatoires.
Donc replace(mystring), "_", "" devrait devenir replace(mystring, "_", "").
Ce problème a lieu à plusieurs endroits dans le code, avec la fonction Mid également.
De manière générale, il y a un souci avec les parenthèses, parfois un abus.
Cdlt,
Merci bcp ça m'a bcp aidé, effectivement la syntaxe avec Mid et Replace n'était pas du tout bonne.