※ 引述《sakiman (MW221U)》之銘言:
: 寫了一種不是很有效率捉取ini下,所有section的處理方式
: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
: System.EventArgs) Handles Button1.Click
: sSection = vbNullString
: sKey = vbNullString
: sinifilename = Application.StartupPath & "\ERPTOP.ini"
: If Not FileExistOrNot(sinifilename) Then Exit Sub
: Dim tempStr As String
: Dim StrList = New Collection
: Dim exitFor As Integer
: exitFor = 0
: sKeyValue = Space(65536)
: lReturnLen = GetPrivateProfileString(sSection, _
: sKey, "", sKeyValue, 32768, sinifilename)
: tempStr = ""
: For i = 0 To 65536
: '連續2次值為nothing代表已讀完最後一個section
: If (exitFor = 1) And _
: (sKeyValue.ToCharArray()(i) = Nothing) Then
: MsgBox(i)
: Exit For
: Else
: exitFor = 0
: End If
: If (sKeyValue.ToCharArray()(i) <> "") And _
: (sKeyValue.ToCharArray()(i) <> Nothing) Then
: tempStr = tempStr + sKeyValue.ToCharArray()(i)
: End If
: If sKeyValue.ToCharArray()(i) = Nothing Then
: 'MsgBox(tempStr)
: StrList.Add(tempStr) '每組完一個section,就丟StrList
: tempStr = "" '清空組section的temp
: exitFor = 1
: End If
: Next
: '顯示最後一個section
: MsgBox(StrList.Item(StrList.Count)) '捉最後一個section的名稱
: End Sub
: ini內容多時候,真的挺慢的,因為一個字元一個字元去串,
: 雖然成功捉到所有section,但超級慢.
: 各位前輩們,該如何改善它呢?
VB6版,你可以自己轉為.net
Dim VntSplit() As String
VntSplit = Split(myGetPrivateProFileString(vbNullString, vbNullString, ,
GameIni, FileLen(GameIni)), Chr(0))
for i = 0 to UBound.....
以下自行變化吧~
next
'取INI檔中所有的 [ ] 字串,源自 鄭子璉
Public Function myGetPrivateProFileString(ByVal lpApplicationName As String,
ByVal lpKeyName As String, Optional ByVal lpDefault As String, Optional ByVal
lpFileName As String, Optional ByVal nSize As Long = 1024) As String
Dim IniBuffer As String
If IsMissing(lpDefault) Then
lpDefault = ""
End If
IniBuffer = String(nSize, Chr(0))
summy = GetPrivateProfileString(lpApplicationName, lpKeyName, lpDefault,
IniBuffer, nSize, lpFileName)
myGetPrivateProFileString = StrConv(MidB(StrConv(IniBuffer, vbFromUnicode),
1, summy), vbUnicode)
End Function
--
████ █ ★ ████ █ █ █
█ █ █ █ █ █ 超 級 熱 烈 歡 迎
█ ████ █ █ █ ████ █
█ █ █ █ ███★ █ █ 歡迎到嘉義版!
★███ █ █ █ █ █ █ █
訊馳電腦-路徑 → 嘉義市林森西路496號 →(05)2244-526 → 順發斜對面
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.33.214.160