VB6.0でコモンダイアログを操作しています。
ボタンが2つあって、1を押したときと2を押したときに開くフォルダを変更したいんです。
現状、以下のコードで作ったんですが、上手く動作しません。
ボタン1を押して、その次にボタン2を押すと、ボタン1で開けたフォルダが開かれます。
どうしたらよいでしょうか?
FormAngle.CommonDialog1.DialogTitle = title
FormAngle.CommonDialog1.filter = filter
'EXEファイルのパス取得
gstrMyPath = App.Path
If Right$(gstrMyPath, 1) <> "\" Then 'パス名の最後に"\"が無い場合
'パス名の最後に"\"を付加する
gstrMyPath = gstrMyPath & "\"
End If
'フォルダ選択
If FormGetFile.GetFileType = 1 Then ' 左用ファイル選択の場合
FormAngle.CommonDialog1.InitDir = gstrMyPath & "Left\"
Else ' 右用ファイル選択の場合
FormAngle.CommonDialog1.InitDir = gstrMyPath & "Right\"
End If
FormAngle.CommonDialog1.CancelError = True
On Local Error Resume Next
If showtype = 0 Then
FormAngle.CommonDialog1.ShowOpen
Else
FormAngle.CommonDialog1.ShowSave
End If
提示されたコードは完結されていないのでどこがいけないのか判断できません。
とりあえずこんなことをすると問題なく動きますが。
Const FILEOPEN As Integer = 1
Const FILESAVE As Integer = 2
Private Sub Command1_Click()
OpenDialog App.Path & "\Left", FILEOPEN
End Sub
Private Sub Command2_Click()
OpenDialog App.Path & "\Right", FILESAVE
End Sub
Private Sub OpenDialog(strIniPath As String, intOpenMode As Integer)
On Error GoTo errHandler
With CommonDialog1
.CancelError = True
.InitDir = strIniPath
If intOpenMode = FILEOPEN Then
.ShowOpen
Else
.ShowSave
End If
End With
Exit Sub
errHandler:
MsgBox Err.Number & ": " & Err.Description, vbOKOnly, Me.Caption & " フィルエラー"
End Sub
ツイート | ![]() |