|
-
Dec 6th, 2000, 11:34 AM
#1
Thread Starter
Fanatic Member
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
-
Dec 6th, 2000, 11:44 AM
#2
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
-
Dec 6th, 2000, 12:00 PM
#3
Thread Starter
Fanatic Member
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
-
Dec 6th, 2000, 12:03 PM
#4
Frenzied Member
instead use
shell path\notepad.exe,vbNormalFocus
-
Dec 6th, 2000, 12:20 PM
#5
Thread Starter
Fanatic Member
This says "Object required"
for shell path\notepad.exe,vbNormalFocus
JO
-
Dec 6th, 2000, 12:23 PM
#6
Frenzied Member
replace path with your notepad path:
exemple:c:\windows\notepad.exe
-
Dec 6th, 2000, 12:24 PM
#7
Frenzied Member
replace "path" with correct path
such as "c:\windows\notepad.exe"
-
Dec 6th, 2000, 12:35 PM
#8
Thread Starter
Fanatic Member
-
Dec 6th, 2000, 01:27 PM
#9
Thread Starter
Fanatic Member
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
-
Dec 6th, 2000, 01:36 PM
#10
Frenzied Member
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
-
Dec 6th, 2000, 01:46 PM
#11
Fanatic Member
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!]
-
Dec 6th, 2000, 01:53 PM
#12
Thread Starter
Fanatic Member
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
-
Dec 6th, 2000, 02:00 PM
#13
Fanatic Member
FileName = File1.path & "\" & file1.filename
Kurt Simons
[I know I'm a hack but my clients don't!]
-
Dec 6th, 2000, 02:55 PM
#14
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.
-
Dec 6th, 2000, 03:06 PM
#15
Thread Starter
Fanatic Member
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
-
Dec 6th, 2000, 03:18 PM
#16
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
-
Dec 6th, 2000, 03:21 PM
#17
Frenzied Member
also make sure that if you source or destination is,
c:\ don't do:
source & "\" & filename cuz the result :
c:\\text.txt
-
Dec 6th, 2000, 03:35 PM
#18
Thread Starter
Fanatic Member
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
-
Dec 6th, 2000, 04:03 PM
#19
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
-
Dec 6th, 2000, 04:12 PM
#20
Frenzied Member
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.
-
Dec 6th, 2000, 04:13 PM
#21
Thread Starter
Fanatic Member
Thanks
Thanks so much!!
This has gotten me out of a bit of a bind.
JO
-
Dec 6th, 2000, 04:15 PM
#22
I knew that Jop, I was just testing you .
-
Dec 6th, 2000, 09:53 PM
#23
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|