eyegeegeewhy Posted May 21, 2007 Posted May 21, 2007 What is the best way of error checking what a user has entered. I have a small gui that i need to check that all the feilds have been entered. But i guess i need keep this bit of the script in a loop or should i put it in a function (i have included just the error checking below followed by the gui below. expandcollapse popupIf $ip="" then MsgBox(0, "error", "You must fill in an IP") If $username="" then MsgBox(0, "error", "You must fill in a username" ) If $password="" then MsgBox(0, "error", "You must fill in a password" ) If $name="" then MsgBox(0, "error", "You must fill in a name" ) If $location ="" then $location="N/A" oÝ÷ Ù«¢+Ø(ìMÉ¥ÁÐMÑÉдå½ÕȽ±½Ü¡É(¥¹±Õ±ÐíU% ½¹ÍѹÑ̹ÔÌÐì(¥¹±Õ±ÐíÕ¥1¥ÍйÔÌÐì((ìÀÌØí½É´ÄôQ¡ÑÕ°U$(ì$ÀÌØí%¹ÁÕÐÔôQ¡9µ½Ñ¡±½Ñ¥½¸(ì$ÀÌØí%¹ÁÕÐÄôQ¡ÕÍɹµ(ì$ÀÌØí%¹ÁÕÐÈôQ¡%@½9µ(ì$ÀÌØí%¹ÁÕÐÌôQ¡ÕÍɹµÑ¼±½¥¸Ý¥Ñ (ì$ÀÌØí%¹ÁÕÐÐôQ¡ÁÍÍݽÉѼÕÑ¡¹Ñ¥ÑÝ¥Ñ (ì$ÀÌØí ÕÑѽ¸ÐôQ¡ÅÕ½Ðí½¹ÅÕ½Ðì ÕÑѽ¸(ì$ÀÌØí ÕÑѽ¸ÔôQ¡ÅÕ½Ðí±ÑÅÕ½Ðì ÕÑѽ¸(ÀÌØí½É´ÄôU% ÉÑ ÅÕ½Ðí%¹ÁÕÐÅÕ½Ðì°ÈÌØ°ÈÌܰÈäİÄÄФ($ÀÌØí%¹ÁÕÐÔôU% Ñɱ ÉÑ%¹ÁÕÐ ÅÕ½ÐìÅÕ½Ðì°àà°ÌܰÄÈİÈĤ($ÀÌØí%¹ÁÕÐÄôU% Ñɱ ÉÑ%¹ÁÕÐ ÅÕ½ÐìÅÕ½Ðì°àà°ØÔ°ÄÈİÈĤ($ÀÌØí%¹ÁÕÐÈôU% Ñɱ ÉÑ%¹ÁÕÐ ÅÕ½ÐìÅÕ½Ðì°àà°äÔ°ÄÈİÈĤ($ÀÌØí%¹ÁÕÐÌôU% Ñɱ ÉÑ%¹ÁÕÐ ÅÕ½ÐìÅÕ½Ðì°àà°ÄÈÔ°ÄÈİÈĤ($ÀÌØí%¹ÁÕÐÐôU% Ñɱ ÉÑ%¹ÁÕÐ ÅÕ½ÐìÅÕ½Ðì°àà°ÄÔÔ°ÄÈİÈĤ($ÀÌØí1°ÄôU% Ñɱ ÉÑ1° ÅÕ½Ðí%@ÅÕ½Ðì°ÄذØÔ°ÄаÄܤ($ÀÌØí1°ÈôU% Ñɱ ÉÑ1° ÅÕ½ÐíUÍɹµÅÕ½Ðì°ÄذäÔ°Øà°Äܤ($ÀÌØí1°ÌôU% Ñɱ ÉÑ1° ÅÕ½ÐíAÍÍݽÉÅÕ½Ðì°ÄذÄÈÔ°ØØ°Äܤ($ÀÌØí1°ÐôU% Ñɱ ÉÑ1° ÅÕ½Ðí1½Ñ¥½¸ÅÕ½Ðì°ÄذÄÔÔ°Øä°Äܤ($ÀÌØí1°ÔôU% Ñɱ ÉÑ1° ÅÕ½Ðí9µÅÕ½Ðì°ÄذÌܰØÐ°Äܤ($ÀÌØí1°ØôU% Ñɱ ÉÑ1° ÅÕ½Ðí¹Ü±½Ñ¥½¸ÅÕ½Ðì°ÈÐ°ÄØ°ÄÈܰÄܤ($ÀÌØí ÕÑѽ¸ÐôU% Ñɱ ÉÑ ÕÑѽ¸ ÅÕ½Ðí½¹ÅÕ½Ðì°ÄÐаÄäȰØÔ°ÈÔ°À¤($ÀÌØí ÕÑѽ¸ÔôU% Ñɱ ÉÑ ÕÑѽ¸ ÅÕ½Ðí1QÅÕ½Ðì°ÄذÄäȰØÔ°ÈÔ°À¤(íM¡½ÜÑ¡U$ݡ٩ÕÍÐÉÑ)U%MÑMÑÑ¡M]}M!=¤()]¡¥±Ä(ÀÌØí¹5ÍôU%Ñ5Í ¤($$(%M±Ð($% ÍÀÌØí¹5ÍôÀÌØíU%}Y9Q} 1=M($$íÍÑɽäÑ¡U$¥¹±Õ¥¹Ñ¡½¹Ñɽ±Ì($%U%±Ñ ¤($$íá¥ÐÑ¡ÍÉ¥ÁÐ($%á¥Ñ1½½À($$$$($% ÍÀÌØí¹5ÍôÀÌØí ÕÑѽ¸Ð($$($$ÀÌØí¹µôU% ÑɱI ÀÌØí%¹ÁÕÐÔ¤($$ÀÌØí¥ÀôU% ÑɱI ÀÌØí%¹ÁÕÐĤ($$ÀÌØíÕÍɹµôU% ÑɱI ÀÌØí%¹ÁÕÐȤ($$ÀÌØíÁÍÍݽÉôU% ÑɱI ÀÌØí%¹ÁÕÐ̤($$ÀÌØí±½Ñ¥½¸ôU% ÑɱI ÀÌØí%¹ÁÕÐФ($$ÀÌØí¹µôU% ÑɱI ÀÌØí%¹ÁÕÐÔ¤($$($$($%%ÀÌØí¥ÀôÅÕ½ÐìÅÕ½ÐìÑ¡¸5Í ½à À°ÅÕ½ÐíÉɽÈÅÕ½Ðì°ÅÕ½Ðíe½ÔµÕÍÐ¥±°¥¸¸%@ÅÕ½Ðì¤($%%ÀÌØíÕÍɹµôÅÕ½ÐìÅÕ½ÐìÑ¡¸5Í ½à À°ÅÕ½ÐíÉɽÈÅÕ½Ðì°ÅÕ½Ðíe½ÔµÕÍÐ¥±°¥¸ÕÍɹµÅÕ½Ðì¤($%%ÀÌØíÁÍÍݽÉôÅÕ½ÐìÅÕ½ÐìÑ¡¸5Í ½à À°ÅÕ½ÐíÉɽÈÅÕ½Ðì°ÅÕ½Ðíe½ÔµÕÍÐ¥±°¥¸ÁÍÍݽÉÅÕ½Ðì¤($%%ÀÌØí¹µôÅÕ½ÐìÅÕ½ÐìÑ¡¸5Í ½à À°ÅÕ½ÐíÉɽÈÅÕ½Ðì°ÅÕ½Ðíe½ÔµÕÍÐ¥±°¥¸¹µÅÕ½Ðì¤($%%ÀÌØí±½Ñ¥½¸ôÅÕ½ÐìÅÕ½ÐìÑ¡¸ÀÌØí±½Ñ¥½¸ôÅÕ½Ðí8½ÅÕ½Ðì($$(%¹M±Ð)]¹$(
November Posted May 21, 2007 Posted May 21, 2007 Well, that a bit personnal Its all about your code stile. If it was with me, ill send it to a func to validate all the conditions, correct then and then return. So i think you have to do in a way that it makes you confortable! It depends witch conditions can be blank or not. AND/OR should work too Cheers m8 Old Scriptology Visual Ping 1.8 - Mass Ping Program with export to txt delimited. Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code. Desktop 2 RGB - Pick a color in the desktop and get the RGB code. ShootIT 1.0 - Screen Capture full and partial screen [font="'Arial Black';"]Remember Remember The Fifth of November.[/font]
Xenobiologist Posted May 21, 2007 Posted May 21, 2007 Hi, I would like to give you the advice to do things like that in funcs. Because then you are able to keep you while wend loop shorter. So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
eyegeegeewhy Posted May 21, 2007 Author Posted May 21, 2007 i went with the below (passed it to a function) probably not the smartest way of doing things but it appears to work. I then used a if statment to see if things were "good" or "bad" Func Error_Check() $Status="good" If $ip="" then MsgBox(0, "error", "You must fill in an IP") $Status="bad" EndIf If $username="" then MsgBox(0, "error", "You must fill in a username" ) $Status="bad" EndIf If $password="" then MsgBox(0, "error", "You must fill in a password" ) $Status="bad" EndIf If $name="" then MsgBox(0, "error", "You must fill in a name" ) $Status="bad" EndIf If $location ="" then $location="N/A" EndIf EndFunc
gcriaco Posted May 21, 2007 Posted May 21, 2007 Another version: expandcollapse popup; Script Start - Add your code below here #include <GUIConstants.au3> #include <GuiList.au3> ;$Form1 = The actual GUI ; $Input5 = The Name of the location ; $Input1 = The username ; $Input2 = The IP/Name ; $Input3 = The username to login with ; $Input4 = The password to authenticate with ; $Button4 = The "done" Button ; $Button5 = The "delete" Button $Form1 = GUICreate("Input", 236, 237, 291, 114) $Input5 = GUICtrlCreateInput("", 88, 37, 121, 21) $Input1 = GUICtrlCreateInput("", 88, 65, 121, 21) $Input2 = GUICtrlCreateInput("", 88, 95, 121, 21) $Input3 = GUICtrlCreateInput("", 88, 125, 121, 21) $Input4 = GUICtrlCreateInput("", 88, 155, 121, 21) $Label1 = GUICtrlCreateLabel("IP", 16, 65, 14, 17) $Label2 = GUICtrlCreateLabel("Username", 16, 95, 68, 17) $Label3 = GUICtrlCreateLabel("Password", 16, 125, 66, 17) $Label4 = GUICtrlCreateLabel("Location", 16, 155, 69, 17) $Label5 = GUICtrlCreateLabel("Name", 16, 37, 64, 17) $Label6 = GUICtrlCreateLabel("Add a new location", 24, 16, 127, 17) $Button4 = GUICtrlCreateButton("Done", 144, 192, 65, 25, 0) $Button5 = GUICtrlCreateButton("DELETE", 16, 192, 65, 25, 0) ;Show the GUI we have just created GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Select Case $nMsg = $GUI_EVENT_CLOSE ;Destroy the GUI including the controls GUIDelete() ;Exit the script ExitLoop Case $nMsg = $Button4 If _CheckInputOK() Then ;...Continue. Anything OK MsgBox(0,"Test","Anything OK") Else ;Input Errors MsgBox(0,"Test","Input Errors") EndIf EndSelect WEnd Func _CheckInputOK() $name = GUICtrlRead($Input5) $ip = GUICtrlRead($Input1) $username = GUICtrlRead($Input2) $password = GUICtrlRead($Input3) $location = GUICtrlRead($Input4) $name = GUICtrlRead($Input5) If $ip="" then MsgBox(0, "error", "You must fill in an IP") Return False EndIf If $username="" then MsgBox(0, "error", "You must fill in a username" ) Return False EndIf If $password="" then MsgBox(0, "error", "You must fill in a password" ) Return False EndIf If $name="" then MsgBox(0, "error", "You must fill in a name" ) Return False EndIf If $location = "" then Return False EndIf $location="N/A" Return True EndFunc BTW, IMO using Functions you get a more readable code.
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