Prev: Non-programmer - trying to get VB 6.0 installed on a Vista machine
Next: Automate Any Email Client
From: John on 8 Jun 2008 04:00 Thanks Beastfish Mikes solution seems to have worked but I do not fully understand why. Got to attend to other things now, but will have a look at your suggestion tomorrow. John On Sun, 8 Jun 2008 03:17:11 -0400, "BeastFish" <no(a)spam.com> wrote: >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: John on 9 Jun 2008 05:19 I originally used the CommonDialog control in the project for Printer Options of Printer Selection and Printer Setup. Your example of the "API way" is interesting and could I am sure be adapted for Printer Options. Thanks for the suggestion. John On Sun, 8 Jun 2008 03:17:11 -0400, "BeastFish" <no(a)spam.com> wrote: > >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). >
From: Adrian Birkett on 12 Jun 2008 10:58 On Sun, 08 Jun 2008 09:54:09 +0800, John wrote: > Thank you Beastfish for the suggestions. > > The directory names on the two computers appear to be the same. One > diffence is that whereas in the old puter I had C:\Documents and > Settings\User > I now have > C:\Documents and Settings\John > > Another difference is that I have Mozilla Firefox on the new puter and > not on the old. > > 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#..\..\..\.. \WINDOWS\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 > > > The stdole2.tbl and stdole32.tbl files in the old puter are dated > 29/08/2002, whereas in the new puter they are dated 23/08/2001 > > Strange that the files in the old puter appear to be a later version. > > My knowledge is limited. I understand dll's but do not know what ocx or > oca files are. > > I notice that the comdlg32.oca files in the VB directory in both puters > are dated 2/04/2008. > I wonder if this is when I installed internet explorer V7 ? > > Any further suggestions woulf be gratefully appreciated. > > John > > > On Fri, 6 Jun 2008 01:53:30 -0400, "BeastFish" <no(a)spam.com> wrote: > >>Does the Windows directory on the new computer have a different name >>than on the old one (ie, C:\Windows - C:\WinNT)? Or perhaps on the old >>box the .vbp's were referencing a copy of the control in another >>directory? >> >>Open up one of the questionable .VBP files in Notepad and see what path >>the control is referenced to. >> >> >> >><John> wrote in message >>news:ne6f44pb2ln3p010thdli7h0cqeshcl75d(a)4ax.com... >>> I was running VB5 under XP and my computer was giving trouble so I >>> bought a new computer. >>> >>> On the new computer I installed VB5 under the XP Pro operating system >>> and now several of my projects will not run in development mode. >>> >>> When I try to run these programs, I get the error message >>> >>> COMDLG32 .OCX could not be loaded >>> continue loading project ? >>> >>> I tried registering the DLL by running regsvr32 COMDLG32.OCX and it >>> said it registered. >>> >>> Also tried running VB5cli.exe which produced Vbcmpfix.exe which ran >>> OK. >>> >>> I cannot find any solution on the MS Knowledge Base or Download sites. >>> >>> Any suggestions would be appreciated. >>> >>> John Hi, Could this possibly be a difference in classID values - the bits between the curly brackets on the two systems? For example I don't have that key registered on my system but the value immediately before it {6B7E6391-850A-101B-AFC0-4210102A8DA7} refers to a something called "lStatusBarEvents" in the registry (down from HKEY_Classes_Root) Just a thought Ade
First
|
Prev
|
Pages: 1 2 3 Prev: Non-programmer - trying to get VB 6.0 installed on a Vista machine Next: Automate Any Email Client |