Announcement

Collapse
No announcement yet.

When using SHELL to TYPE a textfile...

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • When using SHELL to TYPE a textfile...

    Reminder to self: TYPE is a built-in command and not an "external" command file (eg, it's NOT TYPE.EXE).

    Shelling to an .EXE:
    Code:
       lRet = SHELL("someprogram.exe")
    or to a .BAT
    Code:
       lRet = SHELL ("command.exe /C " & sCmd)
    BUT shelling to a built-in command requires a slightly different syntax:
    Code:
       sVerb = "type "
       lRet = SHELL (ENVIRON$("COMSPEC") & " /C " & sVerb & sTgtFile)
    I'm posting this as a reminder to me, so that I can find it again next time I forget!

    -John

  • #2
    Thanks John

    Is it possible to shell to a file - text or Word file - and put the contents on the clipboard? I would find that really useful.
    [I]I made a coding error once - but fortunately I fixed it before anyone noticed[/I]
    Kerry Farmer

    Comment


    • #3
      Not sure I understand... You want to put onto the clipboard the content of a file... that you shelled to?

      First of all, what CMD.EXE command do you intend to execute in the SHELL?
      The built-in TYPE, or an external viewer? etc. (what action do you envision happening in the SHELL?)

      Why not just open the file from your PB code, OPEN it (binary?) and use the CLIPBOARD commands?

      -John

      Comment


      • #4
        Originally posted by John Montenigro View Post
        Not sure I understand... You want to put onto the clipboard the content of a file... that you shelled to?

        First of all, what CMD.EXE command do you intend to execute in the SHELL?
        The built-in TYPE, or an external viewer? etc. (what action do you envision happening in the SHELL?)

        Why not just open the file from your PB code, OPEN it (binary?) and use the CLIPBOARD commands?

        -John
        You can't do that and get somthing usable from a Word .docx file for example. They are zip files full of XML files.

        But I agree with you about a plain text file, just GET$ it and CLIPBOARD SET TEXT.

        Comment


        • #5
          Originally posted by Kerry Farmer View Post
          Thanks John

          Is it possible to shell to a file - text or Word file - and put the contents on the clipboard? I would find that really useful.
          For a Word file, you'd probably use the Word object model and execute SELECT ALL and COPY commands in it.

          Comment


          • #6
            I agree with you over a text file - sorry my question was bad.

            But I would like an answer for a word file. Stuart, I do not actually understand but I will do some more investigation on what you say
            [I]I made a coding error once - but fortunately I fixed it before anyone noticed[/I]
            Kerry Farmer

            Comment


            • #7
              Originally posted by Kerry Farmer View Post
              I agree with you over a text file - sorry my question was bad.

              But I would like an answer for a word file. Stuart, I do not actually understand but I will do some more investigation on what you say
              If you look in samples\Objects\Word\ in your PB folder, you will find a file called oWord.bas.

              Edit that file by adding:

              Code:
                OBJECT CALL   oWordSel.WholeStory
                OBJECT CALL   oWordSel.Copy
              immediately before
              Code:
              Terminate:
              In essence, you have done a Ctrl+A, Ctrl+C.

              You will now have the full contents of the Word document that was created on the clipboard.


              Comment


              • #8
                Thanks Stuart - i will
                [I]I made a coding error once - but fortunately I fixed it before anyone noticed[/I]
                Kerry Farmer

                Comment


                • #9
                  Originally posted by Stuart McLachlan View Post

                  If you look in samples\Objects\Word\ in your PB folder, you will find a file called oWord.bas.

                  Edit that file by adding:

                  Code:
                  OBJECT CALL oWordSel.WholeStory
                  OBJECT CALL oWordSel.Copy
                  immediately before
                  Code:
                  Terminate:

                  Stuart

                  Forgive my ignorance, but where can I find a full list of these object calls?

                  Can I do the equivalent of a control/p?

                  Thanks

                  [I]I made a coding error once - but fortunately I fixed it before anyone noticed[/I]
                  Kerry Farmer

                  Comment


                  • #10
                    Stuart,

                    I'm not sure I'm remembering correctly, so please tell me if this is true: I thought it is necessary that MS Word has to be installed on the machine in order to use the oWord include file...???

                    I thought I hit a snag (a long time ago) trying to use oWord on a machine that used OpenOffice...

                    -John

                    Comment


                    • #11
                      Originally posted by Kerry Farmer View Post

                      Stuart

                      Forgive my ignorance, but where can I find a full list of these object calls?

                      Can I do the equivalent of a control/p?

                      Thanks
                      Look in oWord.inc in the same folder.

                      FWIW, I find the easiest thing to automate Word or Excel is to "Record Macro", do what you want to do and then open the macro editor and use the displayed VBA methods etc.

                      That's what I did for the copy/paste above. I just started recording, did a Ctrl-A, Ctrl-C , stopped recording and looked at the resultant macro:

                      Code:
                      Sub Macro1()
                      '
                      ' Macro1 Macro
                      '
                      '
                          Selection.WholeStory
                          Selection.Copy
                      End Sub
                      The PB Sample code already created a Selection object, so it was trivial to come up with the required code

                      Comment


                      • #12
                        Originally posted by John Montenigro View Post
                        Stuart,

                        I'm not sure I'm remembering correctly, so please tell me if this is true: I thought it is necessary that MS Word has to be installed on the machine in order to use the oWord include file...???

                        I thought I hit a snag (a long time ago) trying to use oWord on a machine that used OpenOffice...

                        -John
                        Correct, If you don't have MS Word, you can't automate it and that's all you are doing when you use oWord.inc (same with any of the MS Office applications)

                        Comment

                        Working...
                        X