老师好,我采用以下代码,采集股piao数据;但是有些股piao因为停牌,退市;会查找不到数据,这样的话用这个代码采集数据会出现“索引超出了数组界限。”这样的错误;
请问怎么修改代码,让采集的数据为空时,自动返回0;
==========================================================
Dim obj_down As New System.Net.WebClient()
Dim drs As List(Of DataRow) = DataTables("表A").Select("股piao代码 is not null")
For Each dr As DataRow In drs
Dim data As String = obj_down.DownloadString("http://hq.sinajs.cn/list=" & dr("股piao代码"))
Dim start As Integer = data.IndexOf("""") + 1
Dim en As Integer = data.IndexOf(""";")
Dim datas() As String = data.SubString(start, en - start).Split(",")
dr("股piao名字") = datas(0)
dr("今日开盘") = datas(1)
dr("昨日收盘") = datas(2)
dr("当前价格") = datas(3)
Next
=============================================================
正常时:
var hq_str_sh603916="苏博特,14.900,14.900,14.910,15.050,14.730,14.900,14.910,1994900,29789704.000,13600,14.900,39800,14.890,13700,14.880,1400,14.870,2700,14.860,4100,14.910,2300,14.920,7100,14.930,2000,14.940,4400,14.950,2018-08-31,10:08:49,00";
异常时: