Results 1 to 6 of 6

Thread: Link a textbox to a cmd command in Visual Basics

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    1

    Unhappy Link a textbox to a cmd command in Visual Basics

    I want to make a program that will sync two folders together with the command in cmd called xcopy, so when i click on a sync logo the folders sync. But i want the user to be able to browse for the locations then set the locations as they sync folders. I already have linked two FolderBrowserDialogs to two textboxes so when i select a folder in the browser the directory shows in the text box. But then how do i put the two directories into the xcopy command? This is what i have done so far...

    Code:
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            FolderBrowserDialog1.ShowDialog()
            TextBox1.Text = FolderBrowserDialog1.SelectedPath
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            FolderBrowserDialog2.ShowDialog()
            TextBox2.Text = FolderBrowserDialog2.SelectedPath
        End Sub
    
        Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
            Shell("CMD.exe")
            SendKeys.Send("xcopy C:\folder1 C:\folder2 /D /E")
            SendKeys.Send("xcopy C:\folder2 C:\folder1 /D /E")
            SendKeys.Send("{ENTER}")
            SendKeys.Send("EXIT")
        End Sub
    End Class
    I want the C:\folder1 to show up as whats in the TextBox1 and the c:\folder2 to show up as whats in the TextBox2.

    Thanks Alot
    PLEASE HELP!

  2. #2
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Link a textbox to a cmd command in Visual Basics

    Code:
            SendKeys.Send("xcopy " & TextBox1.Text & " " & TextBox2.Text & " /D /E")
            SendKeys.Send("xcopy " & TextBox2.Text & " " & TextBox1.Text & " /D /E")
    Also, the code you posted is VB.Net and this forum section is for VB Classic. I'll tell the mods to move the thread for you.

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Link a textbox to a cmd command in Visual Basics

    1) SendKeys is notoriously unreliable... and less so in .NET
    2) what baja posted will work... up until the first time you have a space in one of your paths.
    3) There are other ways to do this in .NET... probably safer too...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Link a textbox to a cmd command in Visual Basics

    I agree regarding SendKeys. You should definitelly look into alternatives. My ability with .Net is limited though.

    One other way would be to create a batch file instead, then execute it. You don't need real time interaction so no need to use a system like SendKeys.

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

    Re: Link a textbox to a cmd command in Visual Basics

    Thread moved from 'VB6 and Earlier' forum to 'VB.Net' (VB2002 and later) forum

    (thanks for letting us know baja_yu )

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Link a textbox to a cmd command in Visual Basics

    If you're using VB.NET then why not use VB.NET? VB.NET can move and copy files and folders with classes from the System.IO namespace.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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