重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
VB.NET 语句结束不需要加;(分号)
温江网站制作公司哪家好,找创新互联公司!从网页设计、网站建设、微信开发、APP开发、响应式网站建设等网站项目制作,到程序开发,运营维护。创新互联公司自2013年起到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联公司。
"integrated security=SSPI;")你这是连接数据库吗?
Dim str As String = "", temp, n As Integer
Dim str1 As String = "12,45,2,9,41,31,66,83,2,1,-9,-91,-21"
Dim a() As String = Split(str1, ",")
For i = 1 To UBound(a) Step 1
a(i) = Val(a(i))
Next
temp = 0
n = 0
For i = 1 To UBound(a)
If a(i) temp Then
temp = a(i)
End If
If a(i) 0 Then
n = n + 1
End If
Next
str = str "正数的个数为 " n
str = str "最大元素的下标为 "
For i = 1 To UBound(a)
If a(i) = temp Then
str = str i " "
End If
Next
TextBox6.Text = str
用数组呗。我是用VB6的,不过你会.NET也肯定能看懂。
不是文本文件么?先用Line Input读每行存入数组。再把每行数据用你的","分割,就可以查询了。我写个简单的例子:
'搜索函数,用法Search(标头,序号),返回数据.
Private Function Search(ByVal Section As String, ByVal Index As Integer) As String
Dim fNum%, Lines%, temp%, Str As String
ReDim Data(0)
fNum = FreeFile()
If Dir("C:\\1.txt") = "" Then Exit Function
'文件路径和文件名你自己改
Open "C:\\1.txt" For Input As #fNum
Do While Not EOF(fNum)
Lines = Lines + 1
'行数
Line Input #fNum, Str
ReDim Preserve Data(Lines)
Data(Lines) = Str
Loop
Close #fNum
If Lines 0 Then
Dim tmp() As String
For temp = 1 To UBound(Data)
tmp = Split(Data(temp), ",")
'分割
If tmp(0) = Section Then
Search = tmp(Index - 1)
'因为从0开始所以-1
Exit Function
End If
Next
End If
End Function
比如你要“gc“开头的第5个数据,就用Search("gc",5)即可返回45。