Very Advanced VB Question
Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: Very Advanced VB Question

  1. #1
    Senior Member
    Join Date
    Jan 2003
    Posts
    1,499

    Very Advanced VB Question

    What I want to do is have a text value in a string which will then be executed.

    E.G

    dim strcommand as string
    strcommand = "mkdir c:\directory"

    'code goes here to execute the strcommand

    Anyone know how to do this.

    I don't want to call external programs I want to use the buit in VB commands. e.g mkdir, kill etc

  2. #2
    AO Antique pwaring's Avatar
    Join Date
    Aug 2001
    Posts
    1,409
    Well, you can call the external commands using the Shell() function in Visual Basic (e.g. Shell(strcommand)), but I don't know whether or not it's possible to take a string and call the functions directly (unless there's a way of splitting the string into the command and arguments, and then executing the function with a name equal to that of the first part of the string).
    Paul Waring - Web site design and development.

  3. #3
    Senior Member
    Join Date
    Jan 2003
    Posts
    1,499
    Its still the same principle pwaring. you still want to run a line of code

  4. #4
    Banned
    Join Date
    Aug 2001
    Location
    Yes
    Posts
    4,424
    It used to be just "shell" in Basic... that probably ain't helping you very much

  5. #5
    Senior Member
    Join Date
    Jan 2003
    Posts
    1,499
    Thats o.k negative. I know its a big day for you !!

  6. #6
    Banned
    Join Date
    Aug 2001
    Location
    Yes
    Posts
    4,424
    Big day indeed

    You could always ask your question on Jupitermedia's VB Forum

  7. #7
    Senior Member
    Join Date
    Nov 2001
    Posts
    4,786
    you probably already figured it out but anyway:

    Private Sub Command1_Click()
    Dim strcommand As String
    strcommand = Text1.Text
    Shell (strcommand)
    End Sub
    Bukhari:V3B48N826 “The Prophet said, ‘Isn’t the witness of a woman equal to half of that of a man?’ The women said, ‘Yes.’ He said, ‘This is because of the deficiency of a woman’s mind.’”

  8. #8
    Senior Member
    Join Date
    Jan 2003
    Posts
    1,499
    Nope, Thats to call an external command or executable.

    I want to use internal VB things like mkdir, kill etc and it has to be the internal VB things not external commands.

  9. #9
    Senior Member Maestr0's Avatar
    Join Date
    May 2003
    Posts
    604
    Shell still works. You can append variables for command line params like: Shell ("net send" & sIPadress + "3y3 0wn j00") as for getting your params you can tokenize stuff with Split() which default delimits by space but can be changed to whatever you want, eg MyArray()=Split(MyString,Chr(10)) will split on LF and put the tokens into the array. I'm not sure what you mean about using VB functons not external programs, cant you just write a function and call it??


    -Maestr0


    edit: I see everyone posted at once, sorry I see above this isnt what you needed, maybe explain a little more??
    \"If computers are to become smart enough to design their own successors, initiating a process that will lead to God-like omniscience after a number of ever swifter passages from one generation of computers to the next, someone is going to have to write the software that gets the process going, and humans have given absolutely no evidence of being able to write such software.\" -Jaron Lanier

  10. #10
    Senior Member
    Join Date
    Jan 2003
    Posts
    1,499
    O.K thanks for those who have contributed so far but in the intrest of not putting me closer to slitting my wrists unless your really sure here can you just leave it be.

    I will explain again.

    I want to execute the text inside a string. I don't want to shell out to an external program.

    Example. A form has a textbox "text1" and a command button "cmdone"

    Private Sub Cmdone_Click()
    Dim strcommand As String
    strcommand = Text1.Text
    ' The string read in is a visual basic command e.g one that would normally appear in the code' of a vb file e.g mkdir, kill, msgbox, filecopy.


    E.G the string could be "kill c:\autoexec.bat"
    That string esxecuted would delete the autoexec.bat file.

    Am I explaining this a little clearer now ? I hope so and I hope this can be done because its driving me nuts more than that stearing wheel in my pants.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •