Results 1 to 17 of 17

Thread: [RESOLVED] I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2012
    Posts
    40

    Resolved [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!!

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,263

    Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)

    vb Code:
    1. If Text1.Text <> "dsufhuidsh" Then
    2. CMDLINE = Text2.Text & "cmd.exe /c Dir /b >> dir.txt"
    3. End IF

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2012
    Posts
    40

    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
    Code:
    Shell CMDLINE
    gives me error "file not found"

    thanks for your help

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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)

  5. #5
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    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 ...

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    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

  7. #7

    Thread Starter
    Member
    Join Date
    Aug 2012
    Posts
    40

    Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)

    Quote Originally Posted by DataMiser View Post
    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?

  8. #8
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,263

    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:
    1. CMDLINE = "cmd.exe /c " & Text2.Text
    2. Shell CMDLINE
    3. CMDLINE = "Dir /b >> dir.txt"
    4. Shell CMDLINE

  9. #9
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    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.

  10. #10

    Thread Starter
    Member
    Join Date
    Aug 2012
    Posts
    40

    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

  11. #11

    Thread Starter
    Member
    Join Date
    Aug 2012
    Posts
    40

    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.

  12. #12

    Thread Starter
    Member
    Join Date
    Aug 2012
    Posts
    40

    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.

  13. #13
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    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?

  14. #14
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    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.

  15. #15
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)

    Quote Originally Posted by MarkT View Post
    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 View Post
    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

  16. #16

    Thread Starter
    Member
    Join Date
    Aug 2012
    Posts
    40

    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.

  17. #17

    Thread Starter
    Member
    Join Date
    Aug 2012
    Posts
    40

    Re: I'm doing something wrong (I'm sure it's very simple - < 10 lines of code)

    Name:  Untitled.png
Views: 221
Size:  7.8 KB 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
  •  



Click Here to Expand Forum to Full Width