MS Access等同于Application.International(xlListSeparator)?

时间:2016-08-03 19:09:24

标签: excel vba excel-vba ms-access access-vba

我在http://analystcave.com/excel-calculate-distances-between-addresses/#Calculate_distance_between_two_addresses_using_Google_Maps_in_Excel

找到了以下代码

但是想在我的Access数据库中使用它来从表单上的2个文本框中获取值,然后计算距离并在单击命令按钮时将距离以米为单位返回到表单上的第三个文本框中。当我使用代码时,它会引发使用fn Application.International(xlListSeparator)的代码部分的错误。如何在Access中使用它?

'Calculate Google Maps distance between two addresses
Public Function GetDistance(start As String, dest As String)
    Dim firstVal As String, secondVal As String, lastVal As String
    firstVal = "http://maps.googleapis.com/maps/api/distancematrix/json?origins="
    secondVal = "&destinations="
    lastVal = "&mode=car&language=pl&sensor=false"
    Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
    URL = firstVal & Replace(start, " ", "+") & secondVal & Replace(dest, " ", "+") & lastVal
    objHTTP.Open "GET", URL, False
    objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
    objHTTP.send ("")
    If InStr(objHTTP.responseText, """distance"" : {") = 0 Then GoTo ErrorHandl
    Set regex = CreateObject("VBScript.RegExp"): regex.Pattern = """value"".*?([0-9]+)": regex.Global = False
    Set matches = regex.Execute(objHTTP.responseText)
    tmpVal = Replace(matches(0).SubMatches(0), ".", Application.International(xlListSeparator))
    GetDistance = CDbl(tmpVal)
    Exit Function
ErrorHandl:
    GetDistance = -1
End Function

1 个答案:

答案 0 :(得分:0)

如果忽略Application.International(xlListSeparator)位并使用:

tmpVal = matches (0).SubMatches (0)

它在MS Access中为我提供了诀窍。