Robin Posted March 19, 2009 Share Posted March 19, 2009 Suddenly i have struck a BLANK! Can anyone here help me with this? $Value = InputBox("Testing", "Enter Http or IP Address", "","") If $Value = @error = 0 Then MsgBox(0, "Abort", "Aborting...", 1) Else RunWait(@ComSpec & ' /c ' & 'ping ""' & $Value & '"" > C:\test.txt', '', @SW_HIDE) RunWait("notepad.exe c:\test.txt") EndIf I want the program to return an "Error" if "OK" was pressed with NO data in the box...At the moment i DO get the error when "Cancel" is clicked. thx guys Link to comment Share on other sites More sharing options...
Skizmata Posted March 19, 2009 Share Posted March 19, 2009 (edited) $Value = InputBox("Testing", "Enter Http or IP Address…", "", "") If $Value = @error = 0 or StringLen($Value) < 1 Then MsgBox(0, "Abort", "Aborting...", 1) Else RunWait(@ComSpec & ' /c ' & 'ping ""' & $Value & '"" > C:\test.txt', '', @SW_HIDE) RunWait("notepad.exe c:\test.txt") EndIf This seems to work for me Edited March 19, 2009 by Skizmata AutoIt changed my life. Link to comment Share on other sites More sharing options...
Robin Posted March 19, 2009 Author Share Posted March 19, 2009 $Value = InputBox("Testing", "Enter Http or IP Address", "", "") If $Value = @error = 0 or StringLen($Value) < 1 Then MsgBox(0, "Abort", "Aborting...", 1) Else RunWait(@ComSpec & ' /c ' & 'ping ""' & $Value & '"" > C:\test.txt', '', @SW_HIDE) RunWait("notepad.exe c:\test.txt") EndIf This seems to work for me Yeeeaaaahhhh....good thinking there...I'm going 2 use it....thanks a bunch Link to comment Share on other sites More sharing options...
ResNullius Posted March 19, 2009 Share Posted March 19, 2009 This If $Value = @error = 0 is a poorly formatted line of code. While it seems to be working, you shouldn't test the three values in that manner in a single line. To see why this is poor form, run your example and enter "123" in the input. It should pass according to your conditions but it fails. If you want to test for @error, this would be better: $Value = InputBox("Testing", "Enter Http or IP Address &", "", "") If @error <> 0 OR StringLen($Value) < 1 Then MsgBox(0, "Abort", "Aborting...", 1) Else RunWait(@ComSpec & ' /c ' & 'ping ""' & $Value & '"" > C:\test.txt', '', @SW_HIDE) RunWait("notepad.exe c:\test.txt") EndIf This tests for @error 1st, then tests the string length. Other way around is: $Value = InputBox("Testing", "Enter Http or IP Address&", "", "") If @error = 0 AND StringLen($Value) > 0 Then RunWait(@ComSpec & ' /c ' & 'ping ""' & $Value & '"" > C:\test.txt', '', @SW_HIDE) RunWait("notepad.exe c:\test.txt") Else MsgBox(0, "Abort", "Aborting...", 1) EndIf Link to comment Share on other sites More sharing options...
Robin Posted March 19, 2009 Author Share Posted March 19, 2009 This If $Value = @error = 0 is a poorly formatted line of code. While it seems to be working, you shouldn't test the three values in that manner in a single line. To see why this is poor form, run your example and enter "123" in the input. It should pass according to your conditions but it fails. If you want to test for @error, this would be better: $Value = InputBox("Testing", "Enter Http or IP Address &", "", "") If @error <> 0 OR StringLen($Value) < 1 Then MsgBox(0, "Abort", "Aborting...", 1) Else RunWait(@ComSpec & ' /c ' & 'ping ""' & $Value & '"" > C:\test.txt', '', @SW_HIDE) RunWait("notepad.exe c:\test.txt") EndIf This tests for @error 1st, then tests the string length. Other way around is: $Value = InputBox("Testing", "Enter Http or IP Address&", "", "") If @error = 0 AND StringLen($Value) > 0 Then RunWait(@ComSpec & ' /c ' & 'ping ""' & $Value & '"" > C:\test.txt', '', @SW_HIDE) RunWait("notepad.exe c:\test.txt") Else MsgBox(0, "Abort", "Aborting...", 1) EndIfAaa ok...got it, thanks. Just for interrest sakes...Is there a way to make the InputBox "case-sensitive"? Link to comment Share on other sites More sharing options...
jvanegmond Posted March 19, 2009 Share Posted March 19, 2009 Aaa ok...got it, thanks. Just for interrest sakes...Is there a way to make the InputBox "case-sensitive"?Case sensitive string comparisons are like so using a double = . $var = "Lawl" $var2 = "LAWL" If ( $var == $var2 ) then MsgBox(0, "", "Not equal") else MsgBox(0, "", "equal") EndiF github.com/jvanegmond Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now