From: Mike Williams on
On 8 Jun, 02:54, John wrote:

> I cannot see that these would be causing the
> problems. The VBP files in both puters appear
> to be identical and show the same modification
> dates of 23 Feb 2005.
> They show:
> Type=Exe
> Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\WINDO­WS\system32\stdole2.tlb#OLE
> Automation
> Object={F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0; COMDLG32.OCX
> Object={6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0; comctl32.ocx
> Object={5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0; MSFLXGRD.OCX
> Module=MLotto1; MLotto1.bas
> Form=frmMain.frm
> etc etc

First make a backup copy of your project to a different folder (just
in case). Then go to the original folder containing your project files
and open the .vbp file in a text editor, such as NotePad. Delete the
lines which start with "Object =" and which refer to the ComDlg
control. Then click the Save button in Notepad to save the amended
file.

Now open the .frm file in Notepad (of the Form that contains your
CommonDialog Control) and do the same. Make sure you only delete the
lines referring to the Cdlg control that start with "Object =". Leave
all other references to the CommonDialog control alone (the lines that
refer to the code you have written regarding how your program is going
to use the control).

Now open up the amended project (the .vbp file) in the normal way so
that it starts up in the VB IDE. As it loads you will get some error
messages, which you can ignore, and the Form that previously contained
the CommonDialog Control will instead contain a VB PictureBox called
CommonDialog1. Delete this object (the PictureBox) from the Form.

Now use the VB Project / Components menu and click the Controls tab
(if it is not already selected) and remove any tick that might be in
the little box entitled "selected items only" so that all available
items are shown in the list. Scroll down to Microsoft CommonDialog
Control 6.0 (SP3) or whatever it is called on your system and select
it.

You should now see the CommonDialog Control available again in your
toolbox, and you can place a copy of it onto the Form. Save your
project, allowing VB to overwrite the existing project files. Now open
up your VB project again and hopefullly it should be working?

Mike



From: John on
Thanks Mike
I will give this a go in a short while.
I am sure that if anyone can sort out my mess it will be you.
Regards
John
On Sat, 7 Jun 2008 21:55:23 -0700 (PDT), Mike Williams
<gagamomo(a)yahoo.co.uk> wrote:

>On 8 Jun, 02:54, John wrote:
>
>> I cannot see that these would be causing the
>> problems. The VBP files in both puters appear
>> to be identical and show the same modification
>> dates of 23 Feb 2005.
>> They show:
>> Type=Exe
>> Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\WINDO�WS\system32\stdole2.tlb#OLE
>> Automation
>> Object={F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0; COMDLG32.OCX
>> Object={6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0; comctl32.ocx
>> Object={5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0; MSFLXGRD.OCX
>> Module=MLotto1; MLotto1.bas
>> Form=frmMain.frm
>> etc etc
>
>First make a backup copy of your project to a different folder (just
>in case). Then go to the original folder containing your project files
>and open the .vbp file in a text editor, such as NotePad. Delete the
>lines which start with "Object =" and which refer to the ComDlg
>control. Then click the Save button in Notepad to save the amended
>file.
>
>Now open the .frm file in Notepad (of the Form that contains your
>CommonDialog Control) and do the same. Make sure you only delete the
>lines referring to the Cdlg control that start with "Object =". Leave
>all other references to the CommonDialog control alone (the lines that
>refer to the code you have written regarding how your program is going
>to use the control).
>
>Now open up the amended project (the .vbp file) in the normal way so
>that it starts up in the VB IDE. As it loads you will get some error
>messages, which you can ignore, and the Form that previously contained
>the CommonDialog Control will instead contain a VB PictureBox called
>CommonDialog1. Delete this object (the PictureBox) from the Form.
>
>Now use the VB Project / Components menu and click the Controls tab
>(if it is not already selected) and remove any tick that might be in
>the little box entitled "selected items only" so that all available
>items are shown in the list. Scroll down to Microsoft CommonDialog
>Control 6.0 (SP3) or whatever it is called on your system and select
>it.
>
>You should now see the CommonDialog Control available again in your
>toolbox, and you can place a copy of it onto the Form. Save your
>project, allowing VB to overwrite the existing project files. Now open
>up your VB project again and hopefullly it should be working?
>
>Mike
>
>

From: BeastFish on
Mike's suggestion should get you going with the CommonDialog OCX.

Just wanted to inquire... What are you using the CommonDialog OCX for? Just
asking because it's actually quite easy to do file open/save, etc. common
dialogs the "API way", and you won't need to bother with the OCX (and there
would be no need to include the OCX in your Setup package).

Here's a little sample that demonstrates the Open (single file and
multi-select) and Save file dialogs using comdlg32 APIs (no need for the
OCX!). If you need a different dialog (i.e., Font, etc.), post back and
I'll see if I can dig up a sample.

Paste this in a new bas module (watch for word wrapping)...

(General)(Declarations)
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Private Declare Function GetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Declare Function GetSaveFileName Lib "comdlg32.dll" _
Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long

Dim OFName As OPENFILENAME

Private Const OFN_OVERWRITEPROMPT = &H2
Private Const OFN_HIDEREADONLY = &H4
Private Const OFN_PATHMUSTEXIST = &H800
Private Const OFN_FILEMUSTEXIST = &H1000
Private Const OFN_LONGNAMES = &H200000
Private Const OFN_ALLOWMULTISELECT = &H200
Private Const OFN_EXPLORER = &H80000

Private oInitDir As String
Private sInitDir As String
Public Function ShowSave(ByVal hWnd As Long, _
Optional ByVal dlgFilter As String, _
Optional ByVal dlgCaption As String) _
As String

If Len(sInitDir) = 0 Then sInitDir = Left$(App.Path, 1) & ":\"
If Len(dlgCaption) = 0 Then dlgCaption = "Save File"
If Len(dlgFilter) = 0 Then dlgFilter = "All Files (*.*)" & Chr$(0) +
"*.*" & Chr$(0)

With OFName
.lStructSize = Len(OFName) ' set structure size
.hwndOwner = hWnd ' owner winder
.hInstance = App.hInstance ' the app's instance
' file filter
.lpstrFilter = dlgFilter
.lpstrFile = Space$(254) ' create a buffer
.nMaxFile = 255 ' max size in chars
.lpstrFileTitle = Space$(254) ' create a buffer
.nMaxFileTitle = 255 ' max size in chars
.lpstrInitialDir = sInitDir ' initial directory
.lpstrTitle = dlgCaption ' dialog title
.flags = OFN_HIDEREADONLY _
Or OFN_LONGNAMES _
Or OFN_OVERWRITEPROMPT _
Or OFN_PATHMUSTEXIST
End With

'Show the 'Save File'-dialog
If GetSaveFileName(OFName) Then
ShowSave = Trim$(OFName.lpstrFile)
Dim sl As Integer
For sl = Len(ShowSave) To 1 Step -1
If Mid$(ShowSave, sl, 1) = "\" Then
sInitDir = Left$(ShowSave, sl)
If Right$(sInitDir, 1) <> "\" Then sInitDir = sInitDir & "\"
Exit For
End If
Next sl
Else
ShowSave = ""
End If
End Function
Public Function ShowOpen(ByVal hWnd As Long, _
Optional ByVal dlgFilter As String, _
Optional ByVal dlgCaption As String, _
Optional ByVal MultiSelect As Boolean = False) _
As String

If Len(oInitDir) = 0 Then oInitDir = Left$(App.Path, 1) & ":\"
If Len(dlgCaption) = 0 Then dlgCaption = "Open File"
If Len(dlgFilter) = 0 Then dlgFilter = "All Files (*.*)" & Chr$(0) +
"*.*" & Chr$(0)

Dim OpenFlags As Long, BuffSize As Long
If MultiSelect Then
BuffSize = 5254
OpenFlags = OFN_HIDEREADONLY _
Or OFN_LONGNAMES _
Or OFN_FILEMUSTEXIST _
Or OFN_EXPLORER _
Or OFN_ALLOWMULTISELECT
Else
BuffSize = 254
OpenFlags = OFN_HIDEREADONLY _
Or OFN_LONGNAMES _
Or OFN_FILEMUSTEXIST _
Or OFN_EXPLORER
End If

With OFName
.lStructSize = Len(OFName) ' structure size
.hwndOwner = hWnd ' owner winder
.hInstance = App.hInstance ' app instance
' file filter
.lpstrFilter = dlgFilter
.lpstrFile = Space$(254) ' create buffer
.nMaxFile = 255 ' max length in chars
.lpstrFileTitle = BuffSize ' create buffer
.nMaxFileTitle = (BuffSize + 1) ' max length in chars
.lpstrInitialDir = oInitDir ' set initial directory
.lpstrTitle = dlgCaption ' dialog title
'flags
.flags = OpenFlags
End With

'Show the 'Open File'-dialog
If GetOpenFileName(OFName) Then
ShowOpen = Trim$(OFName.lpstrFile)
Dim sl As Integer
For sl = Len(ShowOpen) To 1 Step -1
If Mid$(ShowOpen, sl, 1) = "\" Then
oInitDir = Left$(ShowOpen, sl)
If Right$(oInitDir, 1) <> "\" Then oInitDir = oInitDir & "\"
Exit For
End If
Next sl
Else
ShowOpen = ""
End If
End Function


=========================================================
On a form, place 3 command buttons and paste this into its
(General)(Declarations)...

Private Sub Form_Load()
Command1.Caption = "Open"
Command2.Caption = "Open (multi)"
Command3.Caption = "Save"
End Sub

Private Sub Command1_Click()
' OPEN DIALOG (single file)
Dim FileFilter As String
Dim sFile As String

FileFilter = "Text Files (*.txt)" & Chr$(0) & "*.txt" & Chr$(0) _
& "All Files (*.*)" & Chr$(0) + "*.*" & Chr$(0)

sFile = ShowOpen(Me.hWnd, FileFilter, "Open File: Test Caption")
If sFile <> "" Then
Debug.Print "You chose this file: " & sFile
Else
Debug.Print "Canceled"
End If
End Sub

Private Sub Command2_Click()
' OPEN DIALOG (multiple file select)
Dim FileFilter As String
Dim sFile As String

FileFilter = "Text Files (*.txt)" & Chr$(0) & "*.txt" & Chr$(0) _
& "All Files (*.*)" & Chr$(0) + "*.*" & Chr$(0)

' Last parameter True means multi-select...
sFile = ShowOpen(Me.hWnd, FileFilter, "Open Multiple Files: Test
Caption", True)
If sFile = "" Then
Debug.Print "Canceled"
Else
Dim rtnArray () As String
rtnArray = Split(sFile, Chr$(0))
Dim CC As Integer
Debug.Print rtnArray(0) ' 1st one's the path
For CC = 1 To UBound(rtnArray)
Debug.Print CStr(CC) & ": " & rtnArray(CC)
Next CC
End If
End Sub

Private Sub Command3_Click()
' SAVE DIALOG
Dim FileFilter As String
Dim sFile As String

FileFilter = "Text Files (*.txt)" & Chr$(0) & "*.txt" & Chr$(0) _
& "All Files (*.*)" & Chr$(0) + "*.*" & Chr$(0)

sFile = ShowSave(Me.hWnd, FileFilter, "Save File: Test Caption")
If sFile <> "" Then
Debug.Print "You chose/entered this file: " & sFile
Else
Debug.Print "Canceled"
End If
End Sub

From: BeastFish on
Ack! I thought I cleaned up the filter lines in that sample, replacing all
the "+" with "&" (the basic AllAPI sample used the plus signs). But I see I
missed a "+" in some filter lines. That's what I get for quick copy/paste
<g> Doesn't matter, will still work. Just that "&" is better for string
concatenation. So you can just replace the "+" between Chr$(0) + "*.*" with
an "&" ampersand like the others.

And I see a couple lines word wrapped (those filter lines, etc.), so keep a
lookout for that.

From: John on
Mike
You are agenius !
I think this has fixed it.
Got to do other things for now.
Will have a thorough look tomorrow.

Can you explain to me in words of one syllable what we actually did
and why ?
My vb programming is very rusty these days but I like to use a few old
legacy programs and occassionally write a new simple one.

John

On Sat, 7 Jun 2008 21:55:23 -0700 (PDT), Mike Williams
<gagamomo(a)yahoo.co.uk> wrote:

>On 8 Jun, 02:54, John wrote:
>
>> I cannot see that these would be causing the
>> problems. The VBP files in both puters appear
>> to be identical and show the same modification
>> dates of 23 Feb 2005.
>> They show:
>> Type=Exe
>> Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\WINDO�WS\system32\stdole2.tlb#OLE
>> Automation
>> Object={F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0; COMDLG32.OCX
>> Object={6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0; comctl32.ocx
>> Object={5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0; MSFLXGRD.OCX
>> Module=MLotto1; MLotto1.bas
>> Form=frmMain.frm
>> etc etc
>
>First make a backup copy of your project to a different folder (just
>in case). Then go to the original folder containing your project files
>and open the .vbp file in a text editor, such as NotePad. Delete the
>lines which start with "Object =" and which refer to the ComDlg
>control. Then click the Save button in Notepad to save the amended
>file.
>
>Now open the .frm file in Notepad (of the Form that contains your
>CommonDialog Control) and do the same. Make sure you only delete the
>lines referring to the Cdlg control that start with "Object =". Leave
>all other references to the CommonDialog control alone (the lines that
>refer to the code you have written regarding how your program is going
>to use the control).
>
>Now open up the amended project (the .vbp file) in the normal way so
>that it starts up in the VB IDE. As it loads you will get some error
>messages, which you can ignore, and the Form that previously contained
>the CommonDialog Control will instead contain a VB PictureBox called
>CommonDialog1. Delete this object (the PictureBox) from the Form.
>
>Now use the VB Project / Components menu and click the Controls tab
>(if it is not already selected) and remove any tick that might be in
>the little box entitled "selected items only" so that all available
>items are shown in the list. Scroll down to Microsoft CommonDialog
>Control 6.0 (SP3) or whatever it is called on your system and select
>it.
>
>You should now see the CommonDialog Control available again in your
>toolbox, and you can place a copy of it onto the Form. Save your
>project, allowing VB to overwrite the existing project files. Now open
>up your VB project again and hopefullly it should be working?
>
>Mike
>
>