-
Notifications
You must be signed in to change notification settings - Fork 6
/
CvrDemo.bas
212 lines (175 loc) · 5.82 KB
/
CvrDemo.bas
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
Attribute VB_Name = "CvrDemo"
Option Compare Text
Option Explicit
'
' Example functions for using CVRAPI at application level.
' Basic second-level example function to retrieve company info from a vat number.
'
' Vat is searched.
' If found, True is returned, Vat is returned cleaned, and other parameters are filled.
' If not found, False is returned. Other parameters are left untouched.
'
' Example usage: See GetDkCompanyInfo().
'
Public Function RetrieveCvrAddress( _
ByVal Country As CvrCountrySelect, _
ByRef VAT As String, _
ByRef Company As String, _
ByRef Address As String, _
ByRef PostalCode As String, _
ByRef City As String) _
As Boolean
Dim DataCollection As Collection
Dim Result As Boolean
Dim FullResult As CvrVat
Set DataCollection = CvrLookup(Result, VatNo, VAT, Country)
If Result = True Then
' Success.
' Purify data.
FullResult = FillType(DataCollection)
' Return cleaned VAT number.
VAT = FullResult.VAT
' Return info.
Company = FullResult.Name
Address = FullResult.Address
PostalCode = FullResult.ZipCode
City = FullResult.City
End If
Set DataCollection = Nothing
RetrieveCvrAddress = Result
End Function
' Basic second-level example function to retrieve vat number and address from company name.
'
' Company is searched.
' If found, True is returned, Company is returned cleaned, and other parameters are filled.
' If not found, False is returned. Other parameters are left untouched.
'
' LIMITATION:
' Company name must be unique as CVRAPI currently returns a first match only.
'
' Example usage: See GetDkVat().
'
Public Function RetrieveCvrVat( _
ByVal Country As CvrCountrySelect, _
ByRef VAT As String, _
ByRef Company As String, _
ByRef Address As String, _
ByRef PostalCode As String, _
ByRef City As String) _
As Boolean
Dim DataCollection As Collection
Dim Result As Boolean
Dim FullResult As CvrVat
Set DataCollection = CvrLookup(Result, CompanyName, Company, Country)
If Result = True Then
' Success.
' Purify data.
FullResult = FillType(DataCollection)
' Return cleaned VAT number.
VAT = FullResult.VAT
' Return info.
Company = FullResult.Name
Address = FullResult.Address
PostalCode = FullResult.ZipCode
City = FullResult.City
End If
Set DataCollection = Nothing
RetrieveCvrVat = Result
End Function
' Basic top-level example function to retrieve company info from a vat number.
' If found, info will be printed.
' If not found, nothing will be printed.
'
' Example:
' Call GetDkCompanyInfo("20-21-30-94")
' will print:
' VAT: 20213094
' Company: Lagkagehuset A/S
' Street: Amerikavej 21
' City: 1756 København V
'
Public Sub GetDkCompanyInfo( _
ByVal VAT As String)
Const Country As Long = CvrCountrySelect.Denmark
Dim Company As String
Dim Address As String
Dim PostalCode As String
Dim City As String
If RetrieveCvrAddress(Country, VAT, Company, Address, PostalCode, City) Then
Debug.Print "VAT:", VAT
Debug.Print "Company:", Company
Debug.Print "Street:", Address
Debug.Print "City:", PostalCode & " " & City
End If
End Sub
' Basic top-level example function to retrieve vat number and address from company name.
' If found, info will be printed.
' If not found, nothing will be printed.
'
' LIMITATION:
' Company name must be unique as CVRAPI currently returns a first match only.
'
' Example:
' Call GetDkVat("nydata")
' will print:
' VAT: 33402996
' Company: Nydata.dk v/Per Stenholt Andersen
' Street: Roskildevej 278A, st. tv.
' City: 2610 Rødovre
Public Sub GetDkVat( _
ByVal Company As String)
Const Country As Long = CvrCountrySelect.Denmark
Dim VAT As String
Dim Address As String
Dim PostalCode As String
Dim City As String
If RetrieveCvrVat(Country, VAT, Company, Address, PostalCode, City) Then
Debug.Print "VAT:", VAT
Debug.Print "Company:", Company
Debug.Print "Street:", Address
Debug.Print "City:", PostalCode & " " & City
End If
End Sub
' Basic top-level example function to verify the existence of a vat number.
' Returns True if found.
'
' Examples:
' IsCvr("20-21-30-94")
' returns True.
' IsCvr("20-21-30-94", Norway)
' returns False.
'
Public Function IsCvr( _
ByVal VAT As String, _
Optional ByVal Country As CvrCountrySelect = CvrCountrySelect.Denmark) _
As Boolean
IsCvr = RetrieveCvrAddress(Country, VAT, "", "", "", "")
End Function
' Basic top-level example function to retrieve a full set of data
' typically from a search by VAT number or company name.
'
' Returns the UDT (User Defined Type) CvrVat.
'
' Example:
' Dim CvrVatResult As CvrVat
' Dim Result As Boolean
' CvrVatResult = GetCvrData(CvrSearchKey.CompanyName, "TheUniqueCompanyName", Result)
' returns full info in CvrVatResult.
'
Public Function GetCvrData( _
ByVal SearchKey As CvrSearchKey, _
ByVal SearchValue As String, _
ByRef Result As Boolean, _
Optional ByVal CountryValue As CvrCountrySelect = CvrCountrySelect.Denmark) _
As CvrVat
Dim DataCollection As Collection
Dim FullResult As CvrVat
Set DataCollection = CvrLookup(Result, SearchKey, SearchValue, CountryValue)
If Result = True Then
' Success.
' Purify data.
FullResult = FillType(DataCollection)
End If
Set DataCollection = Nothing
GetCvrData = FullResult
End Function