4 Replies - 2589 Views - Last Post: 14 October 2012 - 08:28 AM Rate Topic: ***-- 2 Votes

#1 ashleycardwell94  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-October 12

Can you hint me in the right direction?

Posted 13 October 2012 - 11:55 AM

Im writing a program with shutdown options. Top half of the program has LOCK, LOGOFF, SHUTDOWN, RESTART and SLEEP buttons that do the command in 1 second. The bottom half i am struggling with.

I have 5 Radio buttons:
radiobuttonlock
radiobuttonsleep
radiobuttonshutdown
radiobuttonrestart
radiobuttonlogoff

Currently for the radiobuttonlock, i have:

    Private Sub Execute_Button_Click(sender As System.Object, e As System.EventArgs) Handles Execute_Button.Click
        If RadioButtonLogoff.Checked Then
            Shell("shutdown.exe -l -t")



        End If


What i have is a radio button, a text box where numbers are entered, adnd then i want the shell to finish like:

Shell("shutdown.exe -l -t NUMBER") but i want the numbers from the text box to be entered just after the T in the shell.

Im new to this, so in struggling a little bit.

Thanks in advance for the help.

Is This A Good Question/Topic? 0
  • +

Replies To: Can you hint me in the right direction?

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4332
  • View blog
  • Posts: 12,127
  • Joined: 18-April 07

Re: Can you hint me in the right direction?

Posted 13 October 2012 - 03:43 PM

Well you can do this by reading the textbox, building the string which you then pass to the shell() command.

For instance....

Dim strCmd as String = "shutdown.exe -l -t"
strCmd = strCmd & " " & mytextbox.text

Shell(strCmd)



This of course assumes that the text the user entered was indeed a number. So make sure you validate their content first. Once you have validated the text as a number, you can append it on to the rest of the command and pass that to the Shell() command.

That should get you moving in the right direction. :)

P.S. Moving this to the VB.NET forum since that is what you are apparently using, not VB6.
Was This Post Helpful? 0
  • +
  • -

#3 manos364  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 42
  • Joined: 09-October 12

Re: Can you hint me in the right direction?

Posted 14 October 2012 - 03:11 AM

You can use case!
Dim parameter As String = ""
Select Case parameter
Case "shutdown"
   Shell("shutdown.exe -s -t" & number.Text)
Case "logoff"
   Shell("shutdown.exe -l -t" & number.Text)
End Select


Was This Post Helpful? 0
  • +
  • -

#4 ashleycardwell94  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-October 12

Re: Can you hint me in the right direction?

Posted 14 October 2012 - 03:50 AM

View PostMartyr2, on 13 October 2012 - 03:43 PM, said:

Well you can do this by reading the textbox, building the string which you then pass to the shell() command.

For instance....

Dim strCmd as String = "shutdown.exe -l -t"
strCmd = strCmd & " " & mytextbox.text

Shell(strCmd)



This of course assumes that the text the user entered was indeed a number. So make sure you validate their content first. Once you have validated the text as a number, you can append it on to the rest of the command and pass that to the Shell() command.

That should get you moving in the right direction. :)

P.S. Moving this to the VB.NET forum since that is what you are apparently using, not VB6.


In using visual basic express 2010 if that helps.

should i be putting my
 [b]If RadioButtonShutdown.Checked Then[/b]
            Dim StrCmd As String = "shutdown.exe -s -t"
            StrCmd = StrCmd & " " & TextBox1.Text
        [b]End If[/b]



and am i correct in thinking that this code should go on my EXECUTE button?

Also, how do i go about
 
If radiobuttonshutdown.checked Then
blah blah blah 
End If


if i am going to insert another IF for the radiobuttonlogoff.checked, then do i put in Or or OrElse

im trying to get all of the code under the button as that is what i think i should be doing.
Was This Post Helpful? 0
  • +
  • -

#5 raymai97  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 16-November 11

Re: Can you hint me in the right direction?

Posted 14 October 2012 - 08:28 AM

Dim CmdToRun as string
If radiobuttonlock.Checked then
'sorry but I don't know what's the argument for shutdown.exe to lock a computer
ElseIf radiobuttonsleep.Checked then
'I don't know this also
ElseIf radiobuttonshutdown.Checked then
CmdToRun = "Shutdown -s -t " & textbox1.text
ElseIf radiobuttonrestart.Checked then
CmdToRun = "Shutdown -r -t " & textbox1.text
ElseIf radiobuttonlogoff.Checked then
'I remember logoff can't set countdown time.
CmdToRun = "Shutdown -l"
End If
Shell(CmdToRun)



Lots of way you can do the same thing, just providing a simple example.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1