Bonjour à tous,
Alors tout d'abord, je précise que je suis débutant en VB .Net, jusqu'à maintenant, j'ai plutôt fait du VB6...
Le but final est d'avoir une DLL qui me permette d’accéder à différentes class en vb6 à priori plus simples à coder en vb.net qu'en vb6
Donc d'un côté j'ai mon début de bibliothèque :
Et de l'autre j'ai mon appli de test avec le windows form qui va bien, c'est-à-dire des champs textes et des boutons, rien de bien compliqué à priori...
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231 Imports System.Net.Mail Imports System.Text.RegularExpressions Imports System.Net Imports System.Text <ComClass(communicationsNET.ClassId, communicationsNET.InterfaceId, communicationsNET.EventsId)> _ Public Class communicationsNET #Region "GUID COM" ' Ces GUID fournissent l'identité COM pour cette classe ' et ses interfaces COM. Si vous les modifiez, les clients ' existants ne pourront plus accéder à la classe. Public Const ClassId As String = "6b33c85a-4df9-4fff-9026-83ee06c91391" Public Const InterfaceId As String = "01b2cf8f-bcdd-4a5f-9eeb-a1116db44b67" Public Const EventsId As String = "6b57c641-bd88-4df7-a513-236e77f38c8f" #End Region ' Une classe COM pouvant être créée doit avoir Public Sub New() ' sans paramètre, sinon, la classe ne sera pas ' inscrite dans le Registre COM et ne pourra pas être créée ' via CreateObject. Public Sub New() MyBase.New() End Sub #Region "EMAILING" Private _hostSMTP As String Private _portSMTP As Integer = 25 Private _adrExpediteur As String Private _adrDestinataire As String Private _adrCC As String Private _mailObject As String Private _mailContent As String Private _enclosedFile As String Public Property hostSMTP() As String Get Return _hostSMTP End Get Set(ByVal value As String) _hostSMTP = value End Set End Property Public Property portSMTP() As Integer Get Return _portSMTP End Get Set(ByVal value As Integer) _portSMTP = value End Set End Property Public Property adrExpediteur() As String Get Return _adrExpediteur End Get Set(ByVal value As String) _adrExpediteur = value End Set End Property Public Property adrDestinataire() As String Get Return _adrDestinataire End Get Set(ByVal value As String) _adrDestinataire = value End Set End Property Public Property adrCC() As String Get Return _adrCC End Get Set(ByVal value As String) _adrCC = value End Set End Property Public Property mailObject() As String Get Return _mailObject End Get Set(ByVal value As String) _mailObject = value End Set End Property Public Property mailContent() As String Get Return _mailContent End Get Set(ByVal value As String) _mailContent = value End Set End Property Public Property enclosedFile() As String Get Return _enclosedFile End Get Set(ByVal value As String) _enclosedFile = value End Set End Property ''' <summary> ''' Fonction permettant l'envoi d'un email ''' </summary> ''' <returns>Un n° d'erreur</returns> ''' <remarks>Les paramètres de la fonction sont définis par les propriétés</remarks> Public Function SendEmail() As Integer Dim email As MailMessage, smtp As SmtpClient ' If Trim(hostSMTP) = "" Then Return 1 : Exit Function If portSMTP = 0 Then Return 2 : Exit Function If Trim(adrExpediteur) = "" Then Return 3 : Exit Function If Trim(adrDestinataire) = "" Then Return 4 : Exit Function If Trim(mailObject) = "" Then Return 5 : Exit Function If Not IsEmail(adrDestinataire) Then Return 6 : Exit Function ' smtp = New SmtpClient() '/ Serveur SMTP smtp.Host = Trim(hostSMTP) smtp.Port = portSMTP ' email = New MailMessage '/ Message email With email .From = New MailAddress(adrExpediteur) '/ FROM .To.Add(New MailAddress(adrDestinataire)) '/ TO If Trim(adrCC) <> "" Then .CC.Add(New MailAddress(adrCC)) '/ CC End If If Trim(enclosedFile) <> "" Then '/ Pièce jointe .Attachments.Add(New Attachment(enclosedFile)) End If .Subject = mailObject '/ Objet du message .Body = mailContent '/ Corps du message End With ' Try '/ Envoi du message smtp.Send(email) Return 0 Catch exSMTP As SmtpFailedRecipientException Dim status As New SmtpStatusCode status = exSMTP.StatusCode Return status Catch ex As Exception Return -1 Finally email.Dispose() End Try End Function ''' <summary> ''' Fonction permettant de vérifier le formatage d'un email ''' </summary> ''' <param name="email">La chaine de caractère à vérifier comme étant un email valide</param> ''' <returns>Retourne vrai si la chaine est formatée en tant qu'email correct, faux sinon</returns> ''' <remarks></remarks> Public Shared Function IsEmail(ByVal email As String) As Boolean Dim bMail As Boolean = False Dim regex As New Regex("^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$") If regex.IsMatch(email) Then bMail = True End If Return bMail End Function #End Region #Region "TVA_VIES" Private _countryCode As String Private _vatNumber As String Private _valid As Boolean Private _name As String Private _address As String Public Property countryCode() As String Get Return _countryCode End Get Set(ByVal value As String) _countryCode = value End Set End Property Public Property vatNumber() As String Get Return _vatNumber End Get Set(ByVal value As String) _vatNumber = value End Set End Property Public Property valid() As Boolean Get Return _valid End Get Set(ByVal value As Boolean) _valid = value End Set End Property Public Property name() As String Get Return _name End Get Set(ByVal value As String) _name = value End Set End Property Public Property address() As String Get Return _address End Get Set(ByVal value As String) _address = value End Set End Property Public Function check_NIF() As Date Dim check As New checkVatService check_NIF = check.checkVat(countryCode, vatNumber, valid, name, address) End Function #End Region End Class
Voici le code :
Quand je génère la solution, je n'ai aucune erreur, quand je compile non plus, mais quand je lance l'appli dans mon Visual Studio 2008 avec la touche F5, le windows form apparaît, je remplis le champ texte qui va bien et quand je clique sur le bouton "Check", j'ai systèmatiquement (et quoi que je fasse) le message d'erreur suivant :
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 Imports trucNet Public Class MENGEN Private Sub SendCmd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendCmd.Click Dim clsMail As New communicationsNET, rslt As Integer ' clsMail.hostSMTP = ZhostSMTP.Text.Trim clsMail.portSMTP = CInt(ZportSMTP.Text) clsMail.adrExpediteur = ZadrExpediteur.Text.Trim clsMail.adrDestinataire = ZadrDestinataire.Text.Trim clsMail.mailObject = ZmailObject.Text.Trim clsMail.mailContent = ZmailContent.Text.Trim ' rslt = clsMail.SendEmail If rslt <> 0 Then Select Case rslt Case 1 : MsgBox("Serveur SMTP manquant", MsgBoxStyle.Critical, "Erreur") Case 2 : MsgBox("Port SMTP manquant", MsgBoxStyle.Critical, "Erreur") Case 3 : MsgBox("Adresse expéditeur manquante", MsgBoxStyle.Critical, "Erreur") Case 4 : MsgBox("Adresse destinataire manquante", MsgBoxStyle.Critical, "Erreur") Case 5 : MsgBox("Sujet de l'email manquant", MsgBoxStyle.Critical, "Erreur") Case 6 : MsgBox("L'adresse email du destinataire n'est pas formaté correctement", MsgBoxStyle.Critical, "Erreur") Case -1 : MsgBox("Erreur générale", MsgBoxStyle.Critical, "Erreur") Case Else : MsgBox("Erreur de communication avec le serveur SMTP", MsgBoxStyle.Critical, "Erreur") End Select Else MsgBox("Envoi terminé avec succés", MsgBoxStyle.Information, "Terminé") End If ' End Sub Private Sub CheckNIF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckNIF.Click Dim pays As String, TVA As String, name As String, adresse As String, valide As Boolean Dim NIF As New communicationsNET, result As Date If txCodeNIF.Text <> "" Then pays = txCodeNIF.Text.Substring(0, 2).Trim TVA = txCodeNIF.Text.Substring(2, (txCodeNIF.Text.Length) - 2).Trim Else MsgBox("Donnez un code NIF valide!", MsgBoxStyle.Exclamation, "Champ vide...") Exit Sub End If valide = False name = "" adresse = "" NIF.countryCode = pays NIF.vatNumber = TVA NIF.valid = valide NIF.name = name NIF.address = adresse result = NIF.check_NIF MsgBox(name & vbLf & adresse) End Sub End Class
Argh!!!Méthode introuvable : 'Void negoNet.communicationsNET.set_countryCode(System.String)'.
Sachant que pour info, la partie que vous pouvez voir dans la région "EMAILING" fonctionne très bien avec son bouton "SendCmd", mais la nouvelle région "TVA_VIES" pas du tout!!!
Je suppose que j'ai loupé quelquechose mais quoi???
Merci d'avance de votre aide!!!
Partager