0

I have a Weight Balances, it is a Giropes GI/400, it's connected to my LAN and I can connect via HTTP using an internet browser. It's like a TCP server and send all the time the weight and show it in the browser with URL "http://someip:3000".

I want to read these values and write into a SQL table but a don't know how. I am using an access project and VBA. I have been looking for examples on the internet but only found using comm ports or USB adapters. Please, would you help me?

braX
  • 11,506
  • 5
  • 20
  • 33
pfigueredo
  • 91
  • 7
  • I think your best bet would be scraping the little website that you connect to at `http://someip:3000` using VBA. [here's a nice how-to-get-started](https://stackoverflow.com/questions/27066963/scraping-data-from-website-using-vba) – JNevill May 16 '19 at 14:27
  • I'd start by finding out if your balance exposes any kind of API for programmatic access, before trying to scrape the information from the web page. – Tim Williams May 16 '19 at 17:02
  • Thanks, i used more than 2 examples but the issue is that browser witht the url http://someip:3000 send continuously the value of weights. I used the WinHttpRequest,WebBrowser control, InternetExplorer.Application object,etc, and don't know how to stop the request using for example send(). I have been trying one simple code in vb.net with "Imports System.Net.Sockets" and get the values. – pfigueredo May 21 '19 at 10:43
  • Hi Tim, I followed your advice and the device has a menu, is possible to change the way to send data, one choice is only one time when the weight is stable. – pfigueredo May 21 '19 at 11:35

1 Answers1

0

If the page is simple, and you easily could parse it for the displayed weight, you can use a function like this to download the full page to a string to parse:

Option Compare Database
Option Explicit

' API declarations.
'
Private Declare Function URLDownloadToFile Lib "Urlmon" Alias "URLDownloadToFileA" ( _
    ByVal pCaller As Long, _
    ByVal szURL As String, _
    ByVal szFileName As String, _
    ByVal dwReserved As Long, _
    ByVal lpfnCB As Long) _
    As Long

' Download a file or a page with public access from the web. 
' Returns 0 if success, error code if not. 
' 
' If parameter NoOverwrite is True, no download will be attempted 
' if an existing local file exists, thus this will not be overwritten. 
' 
' Examples: 
' 
' Download a file: 
'   Url = "https://www.codeproject.com/script/Membership/ProfileImages/%7Ba82bcf77-ba9f-4ec3-bbb3-1d9ce15cae23%7D.jpg" 
'   FileName = "C:\Test\CodeProjectProfile.jpg" 
'   Result = DownloadFile(Url, FileName) 
' 
' Download a page: 
'   Url = "https://www.codeproject.com/Tips/1022704/Rounding-Values-Up-Down-By-Or-To-Significant-Figur?display=Print" 
'   FileName = "C:\Test\CodeProject1022704.html" 
'   Result = DownloadFile(Url, FileName) 
' 
' Error codes: 
' -2146697210   "file not found". 
' -2146697211   "domain not found". 
' -1            "local file could not be created." 
' 
' 2004-12-17. Gustav Brock, Cactus Data ApS, CPH. 
' 2017-05-25. Gustav Brock, Cactus Data ApS, CPH. Added check for local file. 
' 2017-06-05. Gustav Brock, Cactus Data ApS, CPH. Added option to no overwrite the local file. 
' 
Public Function DownloadFile( _ 
    ByVal Url As String, _ 
    ByVal LocalFileName As String, _ 
    Optional ByVal NoOverwrite As Boolean) _ 
    As Long 

    Const BindFDefault  As Long = 0 
    Const ErrorNone     As Long = 0 
    Const ErrorNotFound As Long = -1

    Dim Result  As Long

    If NoOverwrite = True Then 
        ' Page or file should not be overwritten. 
        ' Check that the local file exists. 
        If Dir(LocalFileName, vbNormal) <> "" Then 
            ' File exists. Don't proceed. 
            Exit Function 
        End If 
    End If     

    ' Download file or page. 
    ' Return success or error code. 
    Result = URLDownloadToFile(0, Url & vbNullChar, LocalFileName & vbNullChar, BindFDefault, 0)   

    If Result = ErrorNone Then 
        ' Page or file was retrieved. 
        ' Check that the local file exists. 
        If Dir(LocalFileName, vbNormal) = "" Then 
            Result = ErrorNotFound 
        End If 
    End If   

    DownloadFile = Result 

End Function

It is described in detail in my article:

Show pictures directly from URLs in Access forms and reports

which also has a demo to download.

Full code is also at GitHub: VBA.PictureUrl

Gustav
  • 53,498
  • 7
  • 29
  • 55