Dim sFilePath As String
    On Error Resume Next
    Call GetRegistryParam("ConfStorePath", CommonCondition.ConfStorePath)
    sFilePath = CommonCondition.ConfStorePath + "\COMMON_COND.TXT"
//上面通過註冊表保存的路徑打開一個文件    Open sFilePath For Input As #1
//如果這個文件不存在,會走這個if嗎?
    If Err.Number <> 0 Then
        Text1(3).Text = App.Path
        Text1(4).Text = App.Path
        Exit Sub
    End If
//下面的這塊是我問題的關鍵
    With CommonCondition
        Input #1, .MailServerIP
        Input #1, .ReceiverEMailAddress
        Input #1, .MailSenderName
        Input #1, .LogStorePath
    End With
    Close #1
//我的目的就是把.LogStorePath賦值給Text1(3).Text,該怎麽實現? 
    Text1(3).Text = .LogStorePath
    Text1(4).Text = CommonCondition.ConfStorePath

解决方案 »

  1.   

    補充:編譯的時候Text1(3).Text = .LogStorePath出錯,錯誤是沒有變量.LogStorePath
      

  2.   

    //上面通過註冊表保存的路徑打開一個文件
    //这里加上这句能保证走下面的 IF 语句
      On Error Resume Next
        Open sFilePath For Input As #1
    //如果這個文件不存在,會走這個if嗎?
      

  3.   

    謝謝!還有一個問題,
    //下面的這塊是我問題的關鍵
        With CommonCondition
            Input #1, .MailServerIP
            Input #1, .ReceiverEMailAddress
            Input #1, .MailSenderName
            Input #1, .LogStorePath
        End With
        Close #1
    //我的目的就是把.LogStorePath賦值給Text1(3).Text,該怎麽實現? 
        Text1(3).Text = .LogStorePath
        Text1(4).Text = CommonCondition.ConfStorePath大概是怎麽個意思?
      

  4.   

    当然会出错了!
    应该改为Text1(3).Text = CommonCondition.LogStorePath才行
    你的With语句已经结束了,所以要写全,像你下一行一样
      

  5.   

    有一个函数可以实现这个功能,你可以查一下,我记不清了
    好像是dir()之类的,我曾经用过
      

  6.   

    我是vc
    現在有個程序界面是vb做的
    命令行程序是vc做的
    界面程序要有點改動
    知道改動的思路
    但不知道方法
    並且特別急
    請大家多幫幫忙
      

  7.   

    afantict(巴依老爷) ( ) 信誉:100 :
      多挣鬼子钱
      

  8.   

    弟兄们,我的问题还没有结束,如果
    Dim sFilePath As String
        On Error Resume Next
        Call GetRegistryParam("ConfStorePath", CommonCondition.ConfStorePath)
        sFilePath = CommonCondition.ConfStorePath + "\COMMON_COND.TXT"
    //上面通過註冊表保存的路徑打開一個文件    Open sFilePath For Input As #1
    //如果這個文件不存在,会走这个if吗?
    //我查看vb帮助,好像不是不存在这个文件,走这一步,若不存在,会创建新文件。
    //我的目的是在这个文件不存在的时候,走这个if,该怎么实现??????????????
        If Err.Number <> 0 Then
            Text1(3).Text = App.Path
            Text1(4).Text = App.Path
    //这一步我还想追加:创建一个新的文件,然后往文件里写Text1(3).Text 和Text1(4).Text 
            Exit Sub
        End If
    //下面的這塊是我問題的關鍵
        With CommonCondition
            Input #1, .MailServerIP
            Input #1, .ReceiverEMailAddress
            Input #1, .MailSenderName
            Input #1, .LogStorePath
        End With
        Close #1
    //我的目的就是把.LogStorePath賦值給Text1(3).Text,該怎麽實現? 
        Text1(3).Text = .LogStorePath
        Text1(4).Text = CommonCondition.ConfStorePath