2017-01-07 128 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 –