|
-
Sep 7th, 2012, 09:26 AM
#1
Thread Starter
Member
[RESOLVED] I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)
Code:
Private Sub Command1_Click()
ChDir (Text2.Text)
If Text1.Text <> "dsufhuidsh" Then Text2.Text & "cmd.exe /c Dir /b >> dir.txt" = CMDLINE
Shell CMDLINE
Open "dir.txt" For Input As #1
Text1.Text = Input(LOF(1), 1)
Close #1
Kill "dir.txt"
End Sub
Private Sub Form_Load()
Text2.Text = "C:\Documents and Settings\max.anstey\Desktop\New Folder"
End Sub
Code:
If Text1.Text <> "dsufhuidsh" Then Text2.Text & "cmd.exe /c Dir /b >> dir.txt" = CMDLINE
was an attempt of a workaround to concanenating the two .. things.. to create a customisable directory path as I couldn't do
Code:
Text2.Text & "cmd.exe /c Dir /b >> dir.txt" = CMDLINE
. I'm probably making a rookie mistake and would just like it corrected.
Thanks!!
-
Sep 7th, 2012, 09:29 AM
#2
Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)
vb Code:
If Text1.Text <> "dsufhuidsh" Then
CMDLINE = Text2.Text & "cmd.exe /c Dir /b >> dir.txt"
End IF
-
Sep 7th, 2012, 09:42 AM
#3
Thread Starter
Member
Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)
Code:
Private Sub Command1_Click()
ChDir (Text2.Text)
If Text1.Text <> "dsufhuidsh" Then
CMDLINE = "cmd.exe /c" & Text2.Text & "Dir /b >> dir.txt"
End If
Shell CMDLINE
Open "dir.txt" For Input As #1
Text1.Text = Input(LOF(1), 1)
Close #1
Kill "dir.txt"
End Sub
Private Sub Form_Load()
Text2.Text = "C:\Documents and Settings\max.anstey\Desktop\New Folder"
End Sub
gives me error "file not found"
thanks for your help
-
Sep 7th, 2012, 11:25 AM
#4
Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)
Take a look at what your CMDLINE variable contains, you should be able to work out the two most obvious problems, and the solution to them.
If you don't know how, see the article about Debug in our Classic VB FAQs (in the FAQ forum)
-
Sep 7th, 2012, 12:21 PM
#5
Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)
Agree, that's the only way to learn
JG
... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...
-
Sep 7th, 2012, 12:25 PM
#6
Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)
Code:
CMDLINE = "cmd.exe /c" & Text2.Text & "Dir /b >> dir.txt"
You will probably need to add a space after the /c and another before the Dir but then there is no way for us to know what the content of the textbox is so that may not be the case.
As suggested above take a look at the content of the CMDLine var
-
Sep 8th, 2012, 04:59 AM
#7
Thread Starter
Member
Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)
 Originally Posted by DataMiser
Code:
CMDLINE = "cmd.exe /c" & Text2.Text & "Dir /b >> dir.txt"
You will probably need to add a space after the /c and another before the Dir but then there is no way for us to know what the content of the textbox is so that may not be the case.
As suggested above take a look at the content of the CMDLine var
Code:
Private Sub Form_Load()
Text2.Text = "C:\Documents and Settings\max.anstey\Desktop\New Folder"
End Sub
For now, the content is the directory, because I haven't got far enough in writing the program to have a browse button allowing you to choose a directory, and then concatenating that pathline with the rest of the code to put in the command prompt in order to get the list of filenames to then paste into an excel column if it's possible when I get to it (*breathes*)
I'll take a look at the FAQ, do I need to be using an array instead?
-
Sep 8th, 2012, 05:31 AM
#8
Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)
Well, there is probably your problem:
You will probably need to add a space after the /c and another before the Dir
vb Code:
CMDLINE = "cmd.exe /c " & Text2.Text
Shell CMDLINE
CMDLINE = "Dir /b >> dir.txt"
Shell CMDLINE
-
Sep 8th, 2012, 07:09 AM
#9
Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)
What is the purpose of the code? My guess is you could do what you want without using a commandline.
-
Sep 8th, 2012, 09:58 AM
#10
Thread Starter
Member
Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)
I have to electronically distribute a lot of files I scan in as PDFs, so I find the directory using CD, DIR /b it and copy and paste the names into an excel spreadsheet to write next to the filenames who they're going to so I can email them with ease. I'm going to have a browse button to select the directory, and when you press okay it runs the cmd prompt, does dir /b in the correct directory, >> to text file, open text file copy and paste contents into a spreadsheet column in the form (assuming this is possible) but I could also download CLIP.exe so that you can put "| CLIP" at the end of the line in the cmd prompt and it will copy the results to the clipboard to then paste like that
-
Sep 8th, 2012, 10:07 AM
#11
Thread Starter
Member
Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)
Code:
Private Sub Command1_Click()
ChDir (Text2.Text)
Clipboard.Clear
CMDLINE = "cmd.exe /c Dir /b | clip"
Shell CMDLINE
Text1.Text = Clipboard.GetText
End Sub
Private Sub Form_Load()
Text2.Text = "C:\Users\Max\Desktop\New folder"
End Sub
returns an empty string when I do exactly the same thing myself in the cmd prompt and it works 
Code:
Private Sub Command1_Click()
ChDir (Text2.Text)
CMDLINE = "cmd.exe /c Dir /b >> C:\dir.txt"
Shell CMDLINE
Open "C:\dir.txt" For Input As #1
Text1.Text = Input(LOF(1), 1)
Close #1
Kill "C:\dir.txt"
End Sub
Private Sub Form_Load()
Clipboard.Clear
Text2.Text = "C:\Users\Max\Desktop\New folder"
End Sub
works fine so I can progress my program from that
Last edited by Max Anstey; Sep 8th, 2012 at 11:02 AM.
-
Sep 8th, 2012, 10:57 AM
#12
Thread Starter
Member
Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)
<ignore this i don't know how to delete posts>
Last edited by Max Anstey; Sep 8th, 2012 at 11:07 AM.
-
Sep 8th, 2012, 04:39 PM
#13
Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)
Is it fair to assume that you are trying to get a list of all the files in the "C:\Users\Max\Desktop\New folder" directory and place them in Text1?
-
Sep 8th, 2012, 06:12 PM
#14
Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)
The easiest way would be to use the filelist box, set the path and pattern if desired then just loop through the list to get all the filenames, or you could use the Vb Dir$() function and do the same thing.
-
Sep 8th, 2012, 06:50 PM
#15
Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)
 Originally Posted by MarkT
Is it fair to assume that you are trying to get a list of all the files in the "C:\Users\Max\Desktop\New folder" directory and place them in Text1?
 Originally Posted by DataMiser
The easiest way would be to use the filelist box, set the path and pattern if desired then just loop through the list to get all the filenames, or you could use the Vb Dir$() function and do the same thing.
If that is the case he might be able to get an idea from the code I posted here.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Sep 9th, 2012, 03:31 AM
#16
Thread Starter
Member
Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)
When doing this myself, I find the directory in DOS, DIR /b it, and paste the results into a Excel column. I basically want to automate this within a form (with it's own spreadsheet) but as i'm a novice programmer i'm starting off without a browse button (instead a text box where you have to manually input the directory) and without a excel spreadsheet (instead another text box).
I'm just taking small steps at a time and learning the way, rather than finding it online and pasting that code into VB.
I'll take your replies in to consideration and check out that post. Thanks a lot for the help so far.
-
Sep 9th, 2012, 05:00 AM
#17
Thread Starter
Member
Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)
I have this so far and now I need to learn how to paste it into a column in a spreadsheet object. Thanks for the help.
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
|