Hi Greg,
 
> I'm trying to write a basic file printing script.
> 
> The problem is when I print a file, the VB prints
> the machine code of the file. In other words, it
> prints out exactly the code you would get if you
> were to open the program in an ASCII viewier like 
> notepad.

That's exactly what "open for input" gets you - a poorly converted
ascii binary representation of the file contents.

In order for this to work correctly you have to ShellExecute the
file with the 'print' verb. This REQUIRES software capable of both
parsing and printing the file to exist on the computer. If it does
not then the ShellExecute call will fail.

Plug the code below into a new module, then take a look at the
Fprint() function.

'// ======================================================== 
Option Explicit
'[Declares]
  Private Declare Function ShellExecute _
    Lib "shell32.dll" _
    Alias "ShellExecuteA" ( _
      ByVal hwnd As Long, _
      ByVal lpOperation As String, _
      ByVal lpFile As String, _
      ByVal lpParameters As String, _
      ByVal lpDirectory As String, _
      ByVal nShowCmd As Long) _
        As Long
'[Enumeration]
 'values to plug into the nShowCmd param for ShellExecute
  Public Enum swDisplay
    swdNormal = 1&
    swdMinimized = 2&
    swdMaximized = 3&
    swdNoActivate = 4&
    swdMinNoActivate = 7&
    swdNA = 8&
    swdDefault = 10&
  End Enum

'[Code]
  '*********************************************************
  ' Opens files with their associated app
  '*********************************************************
  Public Function FOpen&(ByVal sFile$, _
          Optional eDisplay As swDisplay = swdNormal)
    FOpen = ShellExecute(0&, "open", sFile, "", "", eDisplay)
  End Function
  '*********************************************************
  ' "Edit"s files with their associated app
  '*********************************************************
  Public Function FEdit&(ByVal sFile$, _
          Optional eDisplay As swDisplay = swdNormal)
    FEdit = ShellExecute(0&, "edit", sFile, "", "", eDisplay)
  End Function
  '*********************************************************
  ' "Print"s files with their associated app
  '*********************************************************
  Public Function FPrint&(ByVal sFile$, _
          Optional eDisplay As swDisplay = swdMinNoActivate)
    FPrint = ShellExecute(0&, "print", sFile, "", "", eDisplay)
  End Function
'// ======================================================== 

Regards,

Shawn K. Hall
http://12PointDesign.com/
http://ReliableAnswers.com/





'// =======================================================
    Rules : http://ReliableAnswers.com/List/Rules.asp
    Home  : http://groups.yahoo.com/group/vbHelp/
    =======================================================
    Post  : [email protected]
    Join  : [EMAIL PROTECTED]
    Leave : [EMAIL PROTECTED]
'// =======================================================
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/vbhelp/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to