AhmedSamir
AhmedSamir

Reputation: 43

How to remove text in visual basic

I want to make a CMD command by vb, if textbox1.text contains CMD then it remove "CMD " and it take the rest of text and (Call shell) of it

example:( CMD SHUTDOWN -t 15 ), then it delete "CMD " and it take "SHUTDOWN -t 15" to (Call Shell) to it

this is my code... and of course it's not working :

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
 If TextBox1.Text.Contains("CMD") = True Then
  TextBox1.Text.Remove("CMD ")
  Call Shell(TextBox1.Text)
 End If
End Sub

Upvotes: 0

Views: 2202

Answers (3)

RAJVH
RAJVH

Reputation: 13

To start CMD with parameters try:

Process.Start("shutdown", "-s -f -t 30")

This force-shuts down the computer in 30 seconds.

The text between the second pair of quotation marks are the parameters, which in your case would be '-t 15'.

Upvotes: 0

ttrmw
ttrmw

Reputation: 161

You might try:

... 
TexBox1.Text = TextBox1.Text.Replace("CMD ", "") 
Shell(TextBox1.Text) 

1) Remove has no overload that takes a sub-string, see: http://msdn.microsoft.com/en-us/library/system.string.remove%28v=vs.110%29.aspx, hence my use of replace here.

2) No need to use the call keyword here.

3) Just a heads up, but:

if TextBox1.Text.Contains("CMD") = True 

is the same as:

if TextBox1.Text.Contains("CMD") 

Upvotes: 0

Jadeja RJ
Jadeja RJ

Reputation: 1014

try this

If TextBox1.Text.Contains("CMD ") = True Then 
    TextBox1.Text = TextBox1.Text.Replace("CMD ","") 
End If 

Upvotes: 3

Related Questions