2017-01-07 121 views
-1

我有一个非常简单的Visual Basic的Winform应用程序,它只是一个计数器。我怎样才能在网页上看到这些数据?通过互联网的实时数据

这里是我的代码:

Public Function GetTime(Time as Integer) As String 
    Dim Hrs  As Integer 'number of hours ' 
    Dim Min  As Integer 'number of Minutes ' 
    Dim Sec  As Integer 'number of Sec  ' 

    'Seconds' 
    Sec = Time Mod 60 

    'Minutes' 
    Min = ((Time - Sec)/60) Mod 60 

    'Hours' 
    Hrs = ((Time - (Sec + (Min * 60)))/3600) Mod 60 

    Return Format(Hrs, "00") & ":" & Format(Min, "00") & ":" & Format(Sec, "00") 
End Function 

回答

1

我会做一个网页,使用HTTP请求从Excel

把它按照本网站上的步骤:https://codingislove.com/http-requests-excel-vba/

下面是一个例子POST请求可能看起来像发送上面的数据(我没有测试过,但看起来是正确的):

Public Sub sendRunTime(min as Integer, sec as Integer, hrs as Integer) 
    Dim xmlhttp As New MSXML2.XMLHTTP, myurl As String 
    myurl = "http://url/15oxrjh1" 
    xmlhttp.Open "POST", myurl, False 
    xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
    xmlhttp.Send "min="&min&"&sec="&sec&"&hrs="&hrs 
End Sub 

另一种选择不是活的,但仍然非常快,可以让VBA更新SQL数据库中的一个条目,然后网页可以读取。如果您希望将应用程序运行时发送到网站,这不是最好的选择,但是如果您每分钟更新一次以了解应用程序仍在远程运行,则可能会有效。

+0

为你的回复赢得了很多。那么http代码呢? –

+0

我建议看看这个网站,并学习如何做一些编码,如果这是你想要做的类型或事情。 http://www.w3schools.com/php/default.asp –