| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1191 人关注过本帖
标题:头大!VB配置文件问题 求解!
只看楼主 加入收藏
jiashie
Rank: 8Rank: 8
等 级:贵宾
威 望:10
帖 子:237
专家分:999
注 册:2009-4-30
收藏
得分:5 
用GetPrivateProfileSection读取一个section下的所有的数据
然后再自己拆分 ( split(strRet,vbnullchar) )
2011-05-17 08:58
showcdk
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2011-5-14
收藏
得分:0 
能写下代码吗?谢谢
2011-05-17 14:27
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
因为懒~加上忙~直接贴上我之前某程序中的一小段~读取的INI档的代码~~特别的是这的INI档格式是自订的~只是仿的INI~但是因为是自己写的可以自己变换格式~读取某些直让程序从手动变成自动执行....等相关程序功能皆可从此定义~

程序代码:
Public Function LoadCompareData() As Boolean
Dim FileName As String, TempString As String, Temp As String, BuffTemp() As String
Dim FileNum As Integer, count As Integer, i As Integer
Dim UISETFlag As Boolean, CompareDataFlag As Boolean, ROMAXFlag As Boolean, LegendListFlag As Boolean

    FileNum = FreeFile: FileName = App.Path & "\" & "123.ini": count = 0: TempString = ""
    UISETFlag = False: CompareDataFlag = False: ROMAXFlag = False: LegendListFlag = False
    
    Open FileName For Input As #FileNum
        Do While Not EOF(FileNum)
            Line Input #FileNum, TempString
            
            If TempString <> "" Then
                If InStr(TempString, "<") <> 0 And InStr(TempString, ">") <> 0 Then
                    Temp = Mid(TempString, InStr(TempString, "<") + 1, InStr(TempString, ">") - InStr(TempString, "<") - 1)

                    Select Case Temp
                        Case "UISET"
                            UISETFlag = True: CompareDataFlag = False: ROMAXFlag = False: LegendListFlag = False
                            count = 0
                        Case "CompareData"
                            UISETFlag = False: CompareDataFlag = True: ROMAXFlag = False: LegendListFlag = False
                            count = 0
                        Case "ROMAX"
                            UISETFlag = False: CompareDataFlag = False: ROMAXFlag = True: LegendListFlag = False
                            count = 0
                        Case "LegendList"
                            UISETFlag = False: CompareDataFlag = False: ROMAXFlag = False: LegendListFlag = True
                            count = 0
                    End Select
                End If
                
                If UISETFlag = True Then
                    If AutoMode = True Then
                        If InStr(TempString, "MaxBin") <> 0 Then
                            If Len(TempString) > InStr(TempString, "=") Then
                                frmMain.txtMaxBin.Text = Mid(TempString, InStr(TempString, "=") + 1, Len(TempString) - InStr(TempString, "="))
                            End If
                        ElseIf InStr(TempString, "PassBin") <> 0 Then
                            If Len(TempString) > InStr(TempString, "=") Then
                                frmMain.SetPass.Text = Mid(TempString, InStr(TempString, "=") + 1, Len(TempString) - InStr(TempString, "="))
                            End If
                        ElseIf InStr(TempString, "Target") <> 0 Then
                            If Len(TempString) > InStr(TempString, "=") Then
                                frmMain.txtTargetPath.Text = Mid(TempString, InStr(TempString, "=") + 1, Len(TempString) - InStr(TempString, "="))
                            End If
                        End If
                    End If
                    
                    If InStr(TempString, "OperatingMode") <> 0 Then
                        If Len(TempString) > InStr(TempString, "=") Then
                            If Mid(TempString, InStr(TempString, "=") + 1, Len(TempString) - InStr(TempString, "=")) = 0 Then
                                AutoMode = False
                            Else
                                AutoMode = True
                            End If
                        End If
                    ElseIf InStr(TempString, "UsePath") <> 0 Then
                        If Len(TempString) > InStr(TempString, "=") Then
                            If Mid(TempString, InStr(TempString, "=") + 1, Len(TempString) - InStr(TempString, "=")) = 0 Then
                                UsePath = False
                            Else
                                UsePath = True
                            End If
                        End If
                    End If
                ElseIf CompareDataFlag = True Then
                    If InStr(TempString, "=") <> 0 And Len(TempString) > InStr(TempString, "=") Then
                        BuffTemp = Split(TempString, "=")
                        ReDim Preserve Path1(count): ReDim Preserve Path2(count)
                        Path1(count) = BuffTemp(0): Path2(count) = BuffTemp(1)
                        count = count + 1
                        Erase BuffTemp
                    End If
                ElseIf ROMAXFlag = True Then
                    If InStr(TempString, ",") <> 0 And Len(TempString) > InStr(TempString, ",") Then
                        If Trim(TempString) <> "" Then
                            BuffTemp = Split(TempString, ",")
                            For i = 0 To 2
                                ROMAX(i, count) = BuffTemp(i)
                            Next i
                            count = count + 1
                        End If
                        Erase BuffTemp
                    End If
                ElseIf LegendListFlag = True Then
                    If InStr(TempString, "[") <> 0 And InStr(TempString, "]") <> 0 And InStr(TempString, "__") <> 0 Then
                        If Trim(TempString) <> "" Then
                            ReDim Preserve LegendList(count)
                            LegendList(count) = TempString
                            count = count + 1
                        End If
                    End If
                End If
            End If
        Loop
    Close #FileNum
    
End Function

不要選我當版主
2011-05-17 22:07
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:15 
必须要解释的是这个仿的INI格式档是我自己写的~把程序设定和要互相比较的资料~和一些杂七杂八的全写在一起~
再用类似读取的INI的方式把它读出来~在程序启动的那一瞬间~表格还没开出来之前就做好初始化的动作~整支程序也不大~
也才2~3000行而已~这只是开始读档的一小段~重点是~方法类似~但是照抄一定不行~
唯一不一样的是~我是读我写的设定档~你们要读的是未知的档案~这很难形容~小弟表达能力差~请多包涵~

不要選我當版主
2011-05-18 01:10
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
再贴另一支程序的其中一段~这支用途是自动帮新安装出来的的电脑~设定公司研发部门网域的DNS+++使用者帐号信箱....等的程序稍微大一点~
因为牵扯到的WMI的部份~不过总共也才3000行以内吧~顺便附上的INI档~也许可以试试看能不能用~这的INI最后是显示在MSFlexGrid的这个控制项的其中一页~
可依照使用者需求~执行不同功能的程序~因为要几次重新开关机~所以程序进度必须写在程式外的档案中~以便每次开机时读取~才能得知还有哪些步骤没做~
当然也同时会和WMI的撷取出来的资料做相互比对~个人觉得读取的INI的档案很简单~要不要用的API是看个人喜好而定~我是都自己写代码~

程序代码:
Public Function SelectCheckItem(ItemName As String) As Boolean
Dim FileName As String, TempString As String, Temp As String
Dim FileN As Integer, i As Integer
Dim SetAll As Boolean, JoinDomain As Boolean, SetOffice2003 As Boolean
    
    FileName = Trim(App.Path): FileN = FreeFile
    i = 0: ReDim Project.ProjectList(0)
    
    If Right(FileName, 1) = "\" Then
        FileName = FileName & "ProgressNow.ini"
    Else
        FileName = FileName & "\ProgressNow.ini"
    End If
    
    Open FileName For Input As #FileN
        Do While Not EOF(FileN)
            Line Input #FileN, TempString
            TempString = Trim(TempString)
            
            If InStr(TempString, "[") <> 0 And InStr(TempString, "]") <> 0 Then
                Temp = Mid(TempString, InStr(TempString, "[") + 1, InStr(TempString, "]") - InStr(TempString, "[") - 1)
                Select Case Temp
                    Case "SetAll"
                        SetAll = True: JoinDomain = False: SetOffice2003 = False
                    Case "JoinDomain"
                        SetAll = False: JoinDomain = True: SetOffice2003 = False
                    Case "SetOffice2003"
                        SetAll = False: JoinDomain = False: SetOffice2003 = True
                End Select
            End If
            
            If SetAll = True And ItemName = "SetAll" Then
                If InStr(TempString, "=") <> 0 Then
                    If Len(TempString) > InStr(TempString, "=") Then
                        ReDim Preserve Project.ProjectList(i)
                        Project.ProjectList(i) = Trim(Mid(TempString, 1, InStr(TempString, "=") - 1)) & "," & _
                                                 Trim(Mid(TempString, InStr(TempString, "=") + 1, Len(TempString) - InStr(TempString, "=")))
                        i = i + 1
                    End If
                Else
                    ReDim Preserve Project.ProjectList(i)
                    Project.ProjectList(i) = ""
                    i = i + 1
                End If
            ElseIf JoinDomain = True And ItemName = "JoinDomain" Then
                If InStr(TempString, "=") <> 0 Then
                    If Len(TempString) > InStr(TempString, "=") Then
                        ReDim Preserve Project.ProjectList(i)
                        Project.ProjectList(i) = Trim(Mid(TempString, 1, InStr(TempString, "=") - 1)) & "," & _
                                                 Trim(Mid(TempString, InStr(TempString, "=") + 1, Len(TempString) - InStr(TempString, "=")))
                        i = i + 1
                    End If
                Else
                    ReDim Preserve Project.ProjectList(i)
                    Project.ProjectList(i) = ""
                    i = i + 1
                End If
            ElseIf SetOffice2003 = True And ItemName = "SetOffice2003" Then
                If InStr(TempString, "=") <> 0 Then
                    If Len(TempString) > InStr(TempString, "=") Then
                        ReDim Preserve Project.ProjectList(i)
                        Project.ProjectList(i) = Trim(Mid(TempString, 1, InStr(TempString, "=") - 1)) & "," & _
                                                 Trim(Mid(TempString, InStr(TempString, "=") + 1, Len(TempString) - InStr(TempString, "=")))
                        i = i + 1
                    End If
                Else
                    ReDim Preserve Project.ProjectList(i)
                    Project.ProjectList(i) = ""
                    i = i + 1
                End If
            End If
        Loop
    Close #FileN
    
End Function


ProgressNow.rar (810 Bytes)


语言问题可能你们要自己简化~

不要選我當版主
2011-05-18 01:27
快速回复:头大!VB配置文件问题 求解!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.044263 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved