Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

I cant fix my InitDir when i try to load from the Open Dialog...

Hi Guys,

I suppose we are able to fix the initial directory where the Open Dialog will start when we try to load a doc.

However, for my application I cant seem to fix it. This is what happens:

When i clicked on the Load command button, the Open dialog opens up. Lets say my .InitDir = "C:\Saved Bad Images" and so the Open dialog starts from this particular "C" Drive and "Saved Bad Images" folder.

After which I decided to load a file from another directory say "C:\Saved Good Images" and it manages to load it successfully.

The problem comes:
When i try to load another doc again by clicking the same Load command button, instead of starting from the .InitDir = "C:\Saved Bad Images", it starts from the last folder ("C:\Saved Good Images") where I have just successfully loaded my last doc. Why is this happening? is it because of my coding? or is it that i have to clear any buffer or whatsoever so that this does not happen?

Guys, please help me with this...thanks a million in advance

Regards,
Justin
[1080 byte] By [ootnitsuj] at [2007-11-11 8:04:23]
# 1 Re: I cant fix my InitDir when i try to load from the Open Dialog...
if you always have
.InitDir = "C:\Saved Bad Images"
before .ShowOpen in the Load button Click event, it should work fine... can you post the button Click code?
Marco
mstraf at 2007-11-11 17:26:05 >
# 2 Re: I cant fix my InitDir when i try to load from the Open Dialog...
The following are the fragments of my program codes. Think it shld be sufficient. Hope you can help me out with this mstraf. Thanks a million bro...

Option Explicit
Const ErrCancel = 32755

Private Sub cmdLoadGB_Click()
If txtCurrentStatus.Text = "Paused" Then
LoadGoldenBoard
ctlImageDevice1.ActiveScene = ctlImageDevice1.DisplayScene
ctlImageDevice1.LoadImage dlgCommonDialog1.FileName
Exit Sub
End If
End Sub

Private Sub LoadGoldenBoard()
On Error Resume Next
With dlgCommonDialog1
.DialogTitle = "Open"
.InitDir = "C:\Saved GoldenBoard Images\"
.Filter = _
"Bitmap Files (*.bmp)|*.bmp|IR Images 8 Bits (*.img)|*.img|IR Images 16 Bits (*.img)|*.img|" & _
"All Images (*.bmp;*.img)|*.bmp;*.img|All Files (*.*)|*.*"
.ShowOpen
End With

If Err.Number = ErrCancel Then
Exit Sub
ElseIf Err.Number <> 0 Then
MsgBox "Error " & Format$(Err.Number) & _
" selecting file." & vbCrLf & _
Err.Description
Exit Sub
End If
On Error GoTo 0
End Sub
ootnitsuj at 2007-11-11 17:27:04 >
# 3 Re: I cant fix my InitDir when i try to load from the Open Dialog...
Just reset the Filename property before setting InitDir:

.FileName = ""
.InitDir = ...
mstraf at 2007-11-11 17:28:03 >
# 4 Re: I cant fix my InitDir when i try to load from the Open Dialog...
alrite mstraf....it works!!!...thanks alot dude...

btw is there any way u can help me out with my the other thread titled "How to convert a grayscale image to a pseudo colored image?" I have posted for quite a while now and no one seems to reply...

thanks a million in advance bro...
ootnitsuj at 2007-11-11 17:29:05 >
# 5 Re: I cant fix my InitDir when i try to load from the Open Dialog...
Const ErrCancel = 32755

You don't need to set a Const for pressing the Cancel button. There is already one in VB. ;)

cdlCancel

Exit Sub
ErrHandler:
If Err <> cdlCancel Then
MsgBox Err.Description
End If
Keithuk at 2007-11-11 17:30:04 >
# 6 Re: I cant fix my InitDir when i try to load from the Open Dialog...
Another nit picky item.

If Err <> cdlCancel Then

Should be:

IF Err.Number <> cdlCancel Then

Using default properties in VB Classic can get you in trouble.
edburdo at 2007-11-11 17:31:13 >
# 7 Re: I cant fix my InitDir when i try to load from the Open Dialog...
You don't need to set a Const for pressing the Cancel button. There is already one in VB. ;)

cdlCancel

Exit Sub
ErrHandler:
If Err <> cdlCancel Then
MsgBox Err.Description
End If

Thanks for the advice bro...yah i have noticed it after i have posted these codes...thanks again... :D
ootnitsuj at 2007-11-11 17:32:06 >