matlab代码

以后再补充这是干嘛的,现在只是先整理下代码

Sub cnft_click()
    Dim arrAllData, arrb
    Range("A:F").ClearContents
    arrAllData = GetStockAllData(Range("H4"))
    Application.ScreenUpdating = False
    On Error Resume Next
    arrb = Array("日期", "开盘价", "最高价", "成交价", "最低价", "成交量")
    Dim i As Long
    For i = 0 To 5
        Range("A1").Offset(0, i).Value = arrb(i)
    Next i


    For i = 0 To UBound(arrAllData)
        For j = 0 To 5
            Range("a2").Offset(i, j).Value = arrAllData(i, j)
        Next j
    Next i
    On Error GoTo 0
    Application.ScreenUpdating = True


End Sub
Function GetStockAllData(ByRef StockCode As String)
     On Error Resume Next
     If Len(StockCode) <> 6 Then Exit Function
    '判断上证还是深证
    If Left(StockCode, 2) = 60 Or Left(StockCode, 2) = 58 Then
        StockCode = "sh" & StockCode
    ElseIf Left(StockCode, 2) = 0 Or Left(StockCode, 2) = 3 Then
        StockCode = "sz" & StockCode
    Else
        StockCode = "sh600000"
    End If


    Dim iData As String
    iData = Format(Month(Date), "00")
    iData = iData & Format(Day(Date), "00")
    iData = Year(Date) & iData
    StockCode = "http://biz.finance.sina.com.cn/stock/flash_hq/kline_data.php?symbol=" & StockCode
    StockCode = StockCode & Chr(38) & "end_date=" & iData
    StockCode = StockCode & Chr(38) & "begin_date=20080101"
    '开始读取XML内容
    Dim XML, objNode, objAtr As Object
    Dim nCntChd, nCntAtr As Long
    Set XML = CreateObject("Microsoft.XMLDOM")
    With XML
        .async = False
        .Load (StockCode)
    End With
    Set objNode = XML.documentElement
    nCntChd = objNode.ChildNodes.Length - 1 'XML的记录个数
    Dim arrA
    ReDim arrA(0 To nCntChd, 0 To 6)
    '开始遍历
    For i = 0 To nCntChd
        Set objAtr = objNode.ChildNodes.Item(i)
        nCntAtr = objAtr.Attributes.Length - 1
        For j = 0 To nCntAtr '遍历一条记录里面的所有的记录项,记录是从0开始的
            arrA(i, j) = objAtr.Attributes.Item(j).Text
        Next j
    Next i
    Set objAtr = Nothing
    Set objNode = Nothing
    Set XML = Nothing
    If Err.Number > 0 Then MsgBox ("查不到股票信息")
    Err.Clear
    On Error GoTo 0
    GetStockAllData = arrA
End Function

你可能感兴趣的:(matlab代码)