[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!!
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
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
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)
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
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
Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)
Quote:
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?
Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)
Well, there is probably your problem:
Quote:
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
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.
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
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
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>
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?
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.
Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)
Quote:
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?
Quote:
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.
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.
1 Attachment(s)
Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)
Attachment 91237 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.