Results 1 to 23 of 23

Thread: Copy to Notepad

  1. #1

    Thread Starter
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674
    How can I copy the names in a List1Box to a new notepad.txt document?

    Also can I do this same thing with a File1 list box?

    Thanks,

    JO

  2. #2
    Guest
    Try this:

    Code:
    AppActivate "Untitled - Notepad"
    For i = 0 to List1.ListCount - 1
    SendKeys List1.List(i)
    SendKeys "{ENTER"}
    DoEvents
    Next i
    Same goes for a FileListBox.

    Code:
    AppActivate "Untitled - Notepad"
    For i = 0 to File1.ListCount - 1
    SendKeys File1.List(i)
    SendKeys "{ENTER"}
    DoEvents
    Next i

  3. #3

    Thread Starter
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674

    I see

    I'm getting Run-time error 5
    Invalid procedure call or arguement

    for AppActivate ("Untitled - Notepad")

    Any idea why this may be happening?

    JO

  4. #4
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    instead use
    shell path\notepad.exe,vbNormalFocus

  5. #5

    Thread Starter
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674
    This says "Object required"

    for shell path\notepad.exe,vbNormalFocus

    JO

  6. #6
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    replace path with your notepad path:

    exemple:c:\windows\notepad.exe

  7. #7

  8. #8

    Thread Starter
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674
    Got It!

    thank you

    JO

  9. #9

    Thread Starter
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674

    Why is this happening

    This works but it opens Notepad 2 times and writes the info in the second one.

    Private Sub Command2_Click()
    Shell "C:\WINNT4\Notepad.exe"
    For i = 0 To File1.ListCount - 1
    SendKeys File1.List(i)
    SendKeys "{ENTER}"
    DoEvents
    Next
    End Sub

  10. #10
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    change it to
    Code:
    Private Sub Command2_Click() 
        Shell "C:\WINNT4\Notepad.exe",vbNormalFocus 
        For i = 0 To File1.ListCount - 1 
           SendKeys File1.List(i) 
           SendKeys "{ENTER}" 
           DoEvents 
        Next 
    End Sub

  11. #11
    Fanatic Member
    Join Date
    Jul 2000
    Location
    Manchester NH
    Posts
    833
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal opOperation As String, ByVal lpFile As String, ByVal opParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

    ' just call it like this ShellExe("Explorer")

    Public Sub ShellExe(What As String)
    On Error Resume Next
    Call ShellExecute(0&, vbNullString, What, vbNullString, vbNullString, vbNormalFocus)
    End Sub

    Private Sub Command1_Click()
    ShellExe "notepad.exe"
    AppActivate "Untitled - Notepad"
    For i = 0 To File1.ListCount - 1
    SendKeys File1.List(i)
    SendKeys "{ENTER}"
    DoEvents
    Next i
    End Sub

    Kurt Simons
    [I know I'm a hack but my clients don't!]

  12. #12

    Thread Starter
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674

    Thanks

    Something else I need to know is:

    I'm trying to get a file name from the click event of a File1 Box when I click on the file name.

    D:\MyFile\ "the name selected in the File1 box"

    What is the syntax or property for the File1

    I hope that is clear enough.

    Thanks,

    JO

  13. #13
    Fanatic Member
    Join Date
    Jul 2000
    Location
    Manchester NH
    Posts
    833

    FileName = File1.path & "\" & file1.filename
    Kurt Simons
    [I know I'm a hack but my clients don't!]

  14. #14
    Guest
    Try using the FindWindow api function with the code I posted instead.

    Code:
    Private Declare Function FindWindow Lib "user32" _
    Alias "FindWindowA" (ByVal lpClassName As String, ByVal _
    lpWindowName As String) As Long
    
    Usage
    
    hWin = FindWindow("notepad", vbNullString)
    Replace this code with the AppActivate one.

  15. #15

    Thread Starter
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674

    I've got it now

    Something else I'm trying to do is not working.
    From the click event of my File1 box I'm trying to click a file name and have it copied or moved to another directory. When I use this:

    Private Sub File1_DblClick()
    Dim oFSO As Object
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Call oFSO.CopyFile(File1.Path & " \ " & File1.FileName, File2.Path & " \ " & File1.FileName)
    Set oFSO = Nothing
    End Sub

    It doesn't work because their is no destination with that name (File2.Path & " \ " & File1.FileName)

    Any ideas on how I can do this?

    Thanks,

    JO

  16. #16
    Guest
    Use a DirListBox along with the FileListBox.
    And using FSO is your choice. You could just use the basic VB FileCopy function if you want.

    Code:
    Private Sub File1_DblClick() 
    FileCopy Dir1.Path & "\" & File1.FileName, Dir2.Path & _
    "\" & File1.FileName) 
    End Sub

  17. #17
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    also make sure that if you source or destination is,
    c:\ don't do:
    source & "\" & filename cuz the result :

    c:\\text.txt

  18. #18

    Thread Starter
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674

    Thats PERFECT

    Hey what other basic VB File functions are there besides FileCopy:

    Like FileMove or FileSomething?

    I didn't even know there was a FileCopy function.

    Of course I'm self teaching.

    Thanks a bunch

    JO

  19. #19
    Guest
    As sebs said, if the file is in C:\, you will get C:\\.

    Here is how you can determine which is which.

    Code:
    Private Sub File1_DblClick()
    If Len(Dir1.Path) <= 3 Then CDir$ = Dir1.Path & _
    File1.Filename
    If Len(Dir1.Path) > 3 Then CDir$ = Dir1.Path & "\" & _
    File1.Filename
    If Len(Dir1.Path) <= 3 Then CDir2$ = Dir2.Path & _
    File1.Filename
    If Len(Dir1.Path) > 3 Then CDir2$ = Dir2.Path & "\" & _
    File1.Filename
    FileCopy CDir$, CDir2$
    End Sub
    VB doesn't have a function where you can move files. Only a FileCopy function. In this case, you can use FSO .

    Code:
    Private Sub File1_DblClick()
    Dim FSO as Object
    Set FSO = CreateObject("Scripting.FileSystemObject")
    FSO.MoveFile FromFile1, ToFile2
    End Sub

  20. #20
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Hey Matthew, now don't start to lie huh?

    VB doesn't have a function where you can move files. Only a FileCopy function. In this case, you can use FSO .
    It does have a Move function, but it has a strange name:
    NAME

    Code:
    Name "c:\jop\oldfile.fl" As "c:\jop\otherdir\oldfile.fl"
    that'll move oldfile.fl from c:\jop\ to c:\jop\otherdir

    hope that cleared some things up for ya

    Oh before I forget, you can also rename files
    Code:
    Name "c:\jop\oldfile.fl" As "c:\jop\newfile.fl"
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  21. #21

    Thread Starter
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674

    Thanks

    Thanks so much!!

    This has gotten me out of a bit of a bind.

    JO

  22. #22
    Guest
    I knew that Jop, I was just testing you .

  23. #23
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    I knew that Jop, I was just testing you .
    lol, good one Matthew!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width