Questions

Problem in Vb

+
0 Votes
Locked

Problem in Vb

vishalddd
Hi Everybody,
I am using vb6 and have a problem with Dialog box . I have used Dialog box to save a file . But After i enter file name in Dialog box and run my Application than it fails to run.
i am running batch file using shell() function.
But i fails to create process and application returns to main form.
if i close my application and run it again than i run but again as soon as i write file name in dialog box it wont be able to run batch file.

Plz help .....
+
0 Votes
Tony Hopkinson

You've used the dialog box to get a name and path to save the file to.
Then you save the file to that location.
Then you shell() it.
Then what...

Does teh file exist at teh save location?
Will it run from the command line?
Does it have a recognisable extension?

+
0 Votes
vishalddd

Thanks for your Quick Reply ...

Actually my application is running batch file from vb ... using shell function()...
And CommonDialog Box that i am using is only for saving some .txt file......which i am saving using code.....

With CommonDialog1 'open a with statement as there is a lot of code
.DialogTitle = "Save" 'sets the dialog title
.InitDir = App.path & "/../Config/gui/user/CmdFile/" 'sets the initial directory
.Flags = cdlOFNOverwritePrompt
.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*" 'sets the file
'types

.ShowSave 'show the dialog

If .FileName <> "" Then
'Save CommandFile As Name Given By User In Dialog Box
fso.CopyFile src, .FileName
fso.DeleteFile src
End If
End With
CommonDialog1.InitDir = Mid$(CommonDialog1.FileName, 1, InStrRev(CommonDialog1.FileName, "\"))


If i wont click on CommonDialog box save option to save file...my app. succesfully running batch file from shell() function but as soon as i click on save in CommonDialog Box than my app. fail to run batch file through shell() function...

It seems to me that it is MS Error but not sure.. i am still looking for sol. ...

Plz Help

+
0 Votes
Tony Hopkinson

XCan't see much in there that would point to anything going wrong.
Short of src and .Filename being the same file.

Does the batch file do something with this txt document?

If you do the save but don't shell, then run the batch file from the windows command line, does it still work?

+
0 Votes
vishalddd

No....Batch file is nothing to do with this text file that i have saved using Dialog box ...
Also if i run batch file from Command line than it runs fine..but after using Dialog box it wont run from Shell() ...

You may create same scenario by creating just a simple form which first show a dialog box than execute batch file using shell() function according to me it won't work as my application is failling under same scenario..

Also i have read on some forum that if we use dialog box than it deactivate timer event ...and that it why we are not able to run shell() function after commondialog box....
i am not sure wheather it is true or not....
Plz guide me...
Also if there is any other way by which i can save file through dialog box other than commondialog box ... than plz let me know..
Thanks In Advance..
:-)

+
0 Votes
mdv3441

What if you use ShellExecute(x,x,x) instead of Shell?

+
0 Votes
atklinger

I was with the same problem and I the procedure below works well:

The CommonDialog I have is cdlKlinger. You must change it to the name you actually have.
On my procedure I dumped my outputs into a ListBox Control, I called lstCase01.

Here is the Procedure:

Private Sub cmdSave_Click()

' Printing in File.
With cdlKlinger
.CancelError = False
On Error GoTo ErrorHandler

If Err.Number = 32755 Or cdlCancel = True Then
GoTo ErrorHandler
Exit Sub
Else
.Flags = cdlOFNOverwritePrompt
.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|Data Files (*.dat)|*.dat"
.ShowSave

FileNumber = 1
FileName = .FileName
If FileName <> "" Then
Open FileName For Output As #FileNumber
Print #FileNumber, "Your Name or Title"
Print #FileNumber, "Your Profession"
Print #FileNumber, ""
Print #FileNumber, "Allowable Stress Design"
Print #FileNumber, ""

With lstCase01
For i = 0 To .ListCount
Print #FileNumber, .List(.ListIndex + i)
Next i
End With

Close #FileNumber
Else
Exit Sub
End If
End If
End With

Exit Sub

ErrorHandler:
MsgBox Err.Number & vbCrLf & vbCrLf & _
Err.Description & vbCrLf & vbCrLf & _
Err.Source, vbCritical, Me.Caption
Exit Sub

End Sub

And I am using also a Procedure to Print:

Private Sub cmdPrint_Click()

' Stablishing the CommomDialog Control
With cdlKlinger
.CancelError = False
On Error GoTo ErrorHandler

If (Err.Number = cdlCancel) Or (Err.Number = 32755) Or (cdlCancel = True) Then
' The User Canceled. Do nothing.
GoTo ErrorHandler
Exit Sub
Else
.Flags = (cdlPDReturnDC = True) And (cdlPDSelection = True) And _
(cdlPDHidePrintToFile = True) And _
(cdlPDDisablePrintToFile = True) And _
(cdlPDSelection = True) And _
(cdlPDAllPages = True)

.ShowPrinter
Printer.Orientation = .Orientation
' Printing in Printer

Printer.Font.Bold = True
Printer.Print vbTab & "Your Name"
Printer.Print vbTab & "Your Title and Profession" & vbCrLf
Printer.Print vbTab & "Allowable Stress Design" & vbCrLf
Printer.Print vbTab & Me.Caption & vbCrLf
Printer.Print vbTab & Format(Now, " mmm dd, yyyy (dddd)" & vbTab & "hh:mm:ss") & vbCrLf
Printer.Font.Bold = False
'

Printer.Print
Printer.Print

With lstCase01
For i = 0 To .ListCount
Printer.Print vbTab & .List(.ListIndex + i)
Next i
End With

Printer.NewPage
Printer.EndDoc
Printer.KillDoc
End If
End With

Exit Sub
ErrorHandler:
MsgBox "Error: " & Format$(Err.Number) & _
"Selecting Printer:" & Printer.DeviceName & vbCrLf & vbCrLf & _
Err.Description & vbCrLf & vbCrLf & _
Err.Source, vbCritical, Me.Caption
Exit Sub

End Sub

These two procedures work very good.

Albert