VB.NET 語句結(jié)束不需要加;(分號)
溫江網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)公司!從網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、響應(yīng)式網(wǎng)站建設(shè)等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營維護(hù)。創(chuàng)新互聯(lián)公司自2013年起到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)公司。
"integrated security=SSPI;")你這是連接數(shù)據(jù)庫嗎?
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??"正數(shù)的個(gè)數(shù)為?"??n
str?=?str??"最大元素的下標(biāo)為?"
For?i?=?1?To?UBound(a)
If?a(i)?=?temp?Then
str?=?str??i??"?"
End?If
Next
TextBox6.Text?=?str
用數(shù)組唄。我是用VB6的,不過你會(huì).NET也肯定能看懂。
不是文本文件么?先用Line Input讀每行存入數(shù)組。再把每行數(shù)據(jù)用你的","分割,就可以查詢了。我寫個(gè)簡單的例子:
'搜索函數(shù),用法Search(標(biāo)頭,序號),返回?cái)?shù)據(jù).
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
'行數(shù)
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)
'因?yàn)閺?開始所以-1
Exit Function
End If
Next
End If
End Function
比如你要“gc“開頭的第5個(gè)數(shù)據(jù),就用Search("gc",5)即可返回45。