J'ai trouvé un code pour obtenir l'IP du PC mais j'ai un problème de fonction:
Je ne sais pas bien utiliser les fonctions, surtout quoi mettre dans les (). et oui, je débute...![]()
Quelqu'un peut regarder le code et me dire ce qui ne va pas. MERCI
Ce que j'ai rajouté est une procédure Click Bouton pour afficher l'IP dans un Txt à la fin
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103 Option Explicit Private Const MAX_ADAPTER_NAME_LENGTH As Long = 256 Private Const MAX_ADAPTER_DESCRIPTION_LENGTH As Long = 128 Private Const MAX_ADAPTER_ADDRESS_LENGTH As Long = 8 Private Const ERROR_SUCCESS As Long = 0 Private Type IP_ADDRESS_STRING IpAddr(0 To 15) As Byte End Type Private Type IP_MASK_STRING IpMask(0 To 15) As Byte End Type Private Type IP_ADDR_STRING dwNext As Long IpAddress As IP_ADDRESS_STRING IpMask As IP_MASK_STRING dwContext As Long End Type Private Type IP_ADAPTER_INFO dwNext As Long ComboIndex As Long 'reserved sAdapterName(0 To (MAX_ADAPTER_NAME_LENGTH + 3)) As Byte sDescription(0 To (MAX_ADAPTER_DESCRIPTION_LENGTH + 3)) As Byte dwAddressLength As Long sIPAddress(0 To (MAX_ADAPTER_ADDRESS_LENGTH - 1)) As Byte dwIndex As Long uType As Long uDhcpEnabled As Long CurrentIpAddress As Long IpAddressList As IP_ADDR_STRING GatewayList As IP_ADDR_STRING DhcpServer As IP_ADDR_STRING bHaveWins As Long PrimaryWinsServer As IP_ADDR_STRING SecondaryWinsServer As IP_ADDR_STRING LeaseObtained As Long LeaseExpires As Long End Type Private Declare Function GetAdaptersInfo Lib "iphlpapi.dll" _ (pTcpTable As Any, pdwSize As Long) As Long Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _ (dst As Any, src As Any, ByVal bcount As Long) Private Function TrimNull(item As String) Dim pos As Integer pos = InStr(item, Chr$(0)) If pos Then TrimNull = Left$(item, pos - 1) Else TrimNull = item End If End Function Public Function LocalIPAddress() As String Dim cbRequired As Long Dim buff() As Byte Dim Adapter As IP_ADAPTER_INFO Dim AdapterStr As IP_ADDR_STRING Dim ptr1 As Long Dim sIPAddr As String Dim found As Boolean GetAdaptersInfo ByVal 0&, cbRequired If cbRequired > 0 Then ReDim buff(0 To cbRequired - 1) As Byte If GetAdaptersInfo(buff(0), cbRequired) = ERROR_SUCCESS Then ptr1 = VarPtr(buff(0)) Do While (ptr1 <> 0) CopyMemory Adapter, ByVal ptr1, LenB(Adapter) With Adapter sIPAddr = TrimNull(StrConv(.IpAddressList.IpAddress.IpAddr, vbUnicode)) If Len(sIPAddr) > 0 Then found = True Exit Do End If ptr1 = .dwNext End With Loop End If End If LocalIPAddress = sIPAddr End Function 'Problème ici Private Sub CmdLireIP_Click() Dim IP As Variant LocalIPAddress() = IP TxtIP.Text = IP End Sub
Partager