如何不用股票软件查看当前股市行情
的有关信息介绍如下:有的朋友上班时不方便使用股票软件查看行情,这里介绍使用vbs脚本来获取即时行情的方法。
打开附件的记事本:
将以下代码复制粘贴到文件中(注意:股票代码sh600050,sh600018,sh600008可以自行更改为其他股票代码):
stocknames = "sh600050,sh600018,sh600008"
result = GetData(stocknames)
t = "股票名称 昨收盘 涨跌价(涨跌幅)" & vbTab & "最新价" & vbNewLine & " ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄" & vbNewLine
For i = 0 To UBound(result) - 1
tmp = Split(result(i), ",")
x = 3
If tmp(x) = 0 Then x = 2
If tmp(x) >= tmp(2) Then jj = "+" Else jj = "-"
g = tmp(0) & Chr(32) & FormatNumber(tmp(2)) & Chr(32) & jj & FormatNumber(Abs(tmp(x) - tmp(2)), , -1) & "(" & jj & FormatPercent(Abs(tmp(x) / tmp(2) - 1), , -1) & ")" & " " & vbTab & FormatNumber(tmp(x))
If i < UBound(result) Then t = t & g & vbNewLine
Next
CreateObject("wscript.shell").popup t, 5, "", 4096
Function GetData(StockCode)
Url = "http://hq.sinajs.cn/stock.php?rn=@RANDOM@&list=" & StockCode
Url = GetHttp(Url)
tmp = Split(Url, ";")
For i = 0 To UBound(tmp)
tmp(i) = Mid(tmp(i), InStr(1, tmp(i), """", vbTextCompare) + 1)
If Len(tmp(i)) > 3 Then tmp(i) = Left(tmp(i), Len(tmp(i)) - 3)
Next
GetData = tmp
End Function
Function GetHttp(Url)
On Error Resume Next
Set objXML = CreateObject("Microsoft.XMLHTTP")
With objXML
.Open "Get", Url, False, "", ""
.sEnd
GetHttp = .ResponseBody
End With
GetHttp = BytesToBstr(GetHttp, "GB2312")
Set objXML = Nothing
On Error GoTo 0
End Function
Function BytesToBstr(strBody, CodeBase)
Set objStream = CreateObject("Adodb.Stream")
With objStream
.Type = 1
.Mode = 3
.Open
.Write strBody
.Position = 0
.Type = 2
.Charset = CodeBase
BytesToBstr = .ReadText
End With
objStream.Close
Set objStream = Nothing
End Function
保存此文件,并命名为hq.vbs:
找到刚才保存的hq.vbs文件:
双击运行,即可看到股票行情: