| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 539 人关注过本帖
标题:请高手进行程序解释
取消只看楼主 加入收藏
粘土
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2009-9-4
结帖率:80%
收藏
已结贴  问题点数:20 回复次数:2 
请高手进行程序解释
下面有一段原代码,很多不知道什么意思,请高手解释,不胜感激!最好能给每句注释.
'代替指定的串
'从一个源串(rStr)中寻找到 子串(vSource),然后用目标串(vDes)代替子串(vSource)
Private Sub subReplaceStr(ByRef rStr As String, ByVal vSource As String, _
    ByVal vDes As String)
   
    Dim i As Integer
   
    On Error Resume Next
    If Len(vSource) = 0 Or Len(rStr) = 0 Then Exit Sub
    i = 1
    i = InStr(i, rStr, vSource)
    Do While i > 0
        rStr = Left(rStr, i - 1) & vDes & Right(rStr, Len(rStr) - i - Len(vSource) + 1)
        i = InStr(i + Len(vDes), rStr, vSource)
        DoEvents: DoEvents: DoEvents
    Loop
End Sub


'解释参数
'参数存储在para.dat中
Private Sub subPara(ByVal vStr As String)
    Dim tCmd As String
    Dim tStr As String
    Dim i As Long
    Dim j As Long
   
    On Error Resume Next
    If vStr = "" Then Exit Sub
    If Right(vStr, 2) = vbCrLf Then vStr = Left(vStr, Len(vStr) - 2)
   
    tCmd = vStr
   
    j = 1: i = InStr(j, tCmd, ",")
    Do While i > 0
        tStr = Mid$(tCmd, j, i - j)
        funCmdLine tStr
        j = i + 1: i = InStr(j, tCmd, ",")
    Loop
    tStr = Right(tCmd, Len(tCmd) - j + 1)
    funCmdLine tStr
End Sub
'解释命令行参数  vStr:传递来的参数,一般为Command
Private Function funCmdLine(ByVal vStr As String) As Byte
    Dim i As Integer
    Dim tLeft As String                     ' = 左边是属性名,或命令
   
    On Error GoTo ErrPos
    funCmdLine = 0
    DoEvents: DoEvents: DoEvents: DoEvents
    vStr = Trim(vStr)           ': subReplaceStr vStr, vbTab, ""          '去掉全部Tab
    If vStr = "" Then Exit Function             '空行,退出
   
    i = InStr(vStr, "=")
    If i > 0 Then tLeft = Left(vStr, i - 1): vStr = Right(vStr, Len(vStr) - i) Else tLeft = vStr: vStr = ""
    tLeft = Trim(tLeft): vStr = Trim(vStr)
   
    Select Case LCase(tLeft)                '关键字,不区分大小写
    Case "txtsfile": txtSFile.Text = vStr
    Case "txtdfile": txtDFile.Text = vStr
    End Select
   
    Exit Function
ErrPos:
    subDealError "funCmdLine," & vStr & ",Code:" & Err & ";Descr:" & Error
End Function
'快速读入文本文件
Private Function funReadFile(ByVal vFileName As String) As String
    Dim tFileNum As Long
    Dim tF As String
    Dim tL As Long
    Dim tByte() As Byte
   
    On Error GoTo DealError
    funReadFile = "": tF = ""
    If Dir(vFileName) = "" Then
        subDealError "不能找到 " & vFileName & " !"
        Exit Function
    End If
   
    tL = FileLen(vFileName): ReDim tByte(1 To tL)
   
    tFileNum = FreeFile
    Open vFileName For Binary Access Read As tFileNum
    Get tFileNum, , tByte
    Close tFileNum: DoEvents
    tF = StrConv(tByte, vbUnicode)
    funReadFile = tF
    Exit Function
DealError:
    'MsgBox "注意:读文件" & vFileName & "出错,不能取得相关信息!", 48
    subDealError "ReadFile " & vFileName & ",Code:" & Err & ",Descr:" & Error
    On Error Resume Next
    Close tFileNum
End Function
'统一处理错误,记入日志文件
Private Sub subDealError(ByVal vStr As String)
    Dim tStr As String
    Static sI As Integer
   
    On Error Resume Next
    If Len(vStr) > 0 Then
        lblNote.Caption = vStr: DoEvents
        sI = sI + 1
        mError = mError & CStr(Now) & "," & vStr & vbCrLf
    End If
    If (sI = 50 Or Len(vStr) = 0) And Len(mError) > 0 Then
        tStr = App.Path & "\log.txt"
        subSaveTextFile mError, tStr, True
        mError = "": sI = 0
    End If
End Sub

'窗体载入部分的代码
Private Sub Form_Load()
    Dim tStr As String
    Dim tB(-7 To 14) As Byte
    Dim i As Integer
   
    On Error Resume Next
    m_FXJ_PRP3_RecBytes = 36
   
   
    '取系统参数
    tB(-7) = 33: tB(-6) = 61:  tB(-5) = 36: tB(-4) = 46: tB(-3) = 45: tB(-2) = 46: tB(-1) = 54: tB(0) = 32
    tB(1) = 88: tB(2) = 89: tB(3) = 90: tB(4) = 50
    tB(5) = 92: tB(6) = 89: tB(7) = 91: tB(8) = 87: tB(9) = 76: tB(10) = 85
    tB(11) = 57: tB(12) = 90: tB(13) = 82: tB(14) = 98
   
    tStr = ""
    For i = -7 To 14:        tStr = tStr & Chr$(tB(i) - i):   Next
    lblWStock.Caption = tStr
   
    tStr = ""
    For i = 1 To 14:        tStr = tStr & Chr$(tB(i) - i):   Next
    lblWStock.Tag = tStr
   
    '解释存储的参数
    tStr = App.Path & "\wsPara.dat"
    If Dir(tStr) <> "" Then
        tStr = funReadFile(tStr)
        subPara tStr
    End If
   
    tStr = Command
    If Len(tStr) > 0 Then
        subPara tStr
    End If
End Sub

'程序退出时的代码
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Dim tStr As String
    Dim i As Integer
   
    On Error Resume Next
   
    If cmdExit.Enabled Then
        If Len(Command) = 0 Then    '带参数启动不存储参数
            tStr = "txtSFile=" & txtSFile.Text & ",txtDFile=" & txtDFile.Text
            subSaveTextFile tStr, App.Path & "\wsPara.dat", False
        End If
      
        subDealError ""         '强制保存日志文件
        End
    Else
        Cancel = 1
    End If
End Sub
搜索更多相关主题的帖子: 解释 
2009-09-04 10:48
粘土
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2009-9-4
收藏
得分:0 
很期待答案的!
2009-09-04 10:53
粘土
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2009-9-4
收藏
得分:0 
回复 3楼 风吹过b
这个程序是找人写的,但现在人找不到了.你说系统带了这个功能的函数,那为什么还需要单独写呢?特别是窗体装载对 Dim tB(-7 To 14) As Byte进行赋值是什么意思?
2009-09-04 11:37
快速回复:请高手进行程序解释
数据加载中...
 
   



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

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