我在第一次进入CommonDialog的时候,让CommonDialog.InitDir = "e:\aaa",然后showOpen.结果正确,进入了e:\aaa目录。
为什么我第二次进入CommonDialog的时候,让CommonDialog.InitDir = "e:\bbb",然后showOpen,为什么还是进入了e:\aaa目录?请帮忙解答!

解决方案 »

  1.   

    看看conmondialog控件的属性窗口是否将initdir属性值设置死了,或者e:\bbb目录不存在而e:\aaa是程序的目录?
      

  2.   

    没有啊,我试了
    Option ExplicitPrivate Sub Command1_Click()
      With Me.CommonDialog1
        .InitDir = "D:\"
        .ShowOpen
        
      End With
    End SubPrivate Sub Command2_Click()
      With Me.CommonDialog1
        .InitDir = "c:\"
        .ShowOpen
        
      End With
    End Sub
      

  3.   

    对不起各位,我刚有点事。
    我的common dialog确实是这样,我跟了一下,在给common dialog 的inidir辅值时路径也对,什么都对,但就是有问题!代码如下:Private Sub AddRec()'On Error Resume Next'新rom名稱
    newApName = InputBox("Please Enter the AP Name To Add", "ProjectTool")
    If newApName = "" Then
        MsgBox "invaild input!"
        Exit Sub
    End If
    newApPath = GetApPath("新資料 ==> 請選擇AP的路徑")
    If newApPath = "" Then
        Exit Sub
    End If
    newTracerPath = GetTracerPath("新資料 ==> 請選擇Tracer的路徑")
    If newTracerPath = "" Then
        Exit Sub
    End If
    newApRomName = GetApRomName()
    newAPDebugFile = GetApDebugFile()
    newMainDebugFile = GetMainDebugFile()
    ret = ChangePopMenu("你確定加入這筆資料?" & vbCrLf & _
                        "-----------------------------------------")
    If ret = 1 Then
        With rs
        .AddNew
        !ApName = newApName
        !appath = newApPath
        !TracerPath = newTracerPath
        !ApRomName = newApRomName
        !APDebugFile = newAPDebugFile
        !MainDebugFile = newMainDebugFile
        .Update
        End With
        newApName = ""
        newApPath = ""
        newTracerPath = ""
        newApRomName = ""
        newAPDebugFile = ""
        newMainDebugFile = ""
        SB1.Panels("Content").Text = "Add Recordset Successful!"
        Call TreeRefresh
    Else
        SB1.Panels("Content").Text = "Add Recordset Canceled!"
    End If
    End SubFunction GetApRomName() As String
    '打開rom
    On Error GoTo ErrHandler
    Dim temp As String
    CDlg.DialogTitle = "Please Select your ROM!"
    CDlg.InitDir = newApPathCDlg.Filter = "AP rom Files(*.rom)|*.rom"
    CDlg.FilterIndex = 1
    CDlg.ShowOpen
    temp = Mid(CDlg.FileName, InStrRev(CDlg.FileName, "\") + 1)
    GetApRomName = temp
    Exit Function
    ErrHandler:
        GetApRomName = ""
    End FunctionFunction GetApDebugFile() As String
    '打開Ap debug file
    On Error GoTo ErrHandlerDim temp As String
    CDlg2.DialogTitle = "Please Select your Debug File!"
    CDlg2.InitDir = newApPathCDlg2.Filter = "AP debug Files(*.dbg)|*.dbg|All Files (*.*)|*.*"
    CDlg2.FilterIndex = 1
    CDlg2.ShowOpen
    temp = CDlg2.FileName
    GetApDebugFile = temp
    Exit Function
    ErrHandler:
        GetApDebugFile = ""
    End Function
    主要代码就是这样。Private Sub AddRec()是增加要一笔资料,其中会调用GetApRomName。第一次调用AddRec时,都是好的,但第二次调用时,在GetApRomName中CDlg.initdir = 一个新的路径(路径无误),却出来的是第一次设置的路径!
    请各位帮帮忙!