Hello Me You Posted March 13, 2007 Share Posted March 13, 2007 (edited) At school we are learning algorithm, which I know what is. He gave us (the teacher) some examples of algorithms and I bet with him that if I make a program with a specific algorithm (from the examples), I will get A!The algorithm calculates the area and the perimeter of a (2D) square/box and the algorithm is:1) Read A (first side)2) Read B (second side)3) Calculate A*B4) Calculate 2A+2B5) Print area & perimeterHere is what I tried:$a = InputBox("Side A", "Length of side A (cm)") If @error Then MsgBox(16, "Error!", "Invalid value") $b = InputBox("Side B", "Length of side B (cm)") If @error Then MsgBox(16, "Error!", "Invalid value") MsgBox(64, "Area and Perimeter", "Area: " & $a*$b & "cm²" & @CRLF & "Perimeter: " & (2*$a)+(2*$B) & "cm")But it is not complete. That it misses is:1) If @error then show msgbox BUT go to the first step again. (ask for side A lenght)2) The same problem with the up one but if it happens to the second inputbox, which asks for side B lenght.3) If the entered value isl letters (a, b, c, etc...) instead of numbers show msgbox and ask for side lenght again4) And the last I can think is if the value is >0 (I can do this)Can you help me finish it?Did I forgot something?Are these very noob questions? Edited March 13, 2007 by Hello Me You Random Link to comment Share on other sites More sharing options...
Hasher Posted March 13, 2007 Share Posted March 13, 2007 (edited) Some suggestions - You want to check the value entered is numeric and also that its a number small enough to make a calculation ( StringRegExp )...... will you handle floating numbers ? If not StringRegExp then a check involving Length and isNumber() - Declare variables - Make the cancel button in your msgbox do something - put you inputbox statement in a Do - Until loop ..... once algo is happy it go's to next stage - It may work that math exression can be done in a msgbox but I think its just not good practice, Maybe others have views on this - Comment your code.....just to impress your teacher My 2 cents Edited March 13, 2007 by Hasher Firefox's secret is the same as Jessica Simpson's: its effortless, glamorous style is the result of shhh extensions! Link to comment Share on other sites More sharing options...
Hello Me You Posted March 13, 2007 Author Share Posted March 13, 2007 (edited) I still can't figure it out. Here is my source: $a = InputBox("Side A", "Length of side A (cm)") If $a<0 Or @error Then MsgBox(16, "Error!", "Invalid value") $b = InputBox("Side B", "Length of side B (cm)") If $b<0 Or @error Then MsgBox(16, "Error!", "Invalid value") MsgBox(64, "Area and Perimeter", "Area: " & $a*$b & " cm²" & @CRLF & "Perimeter: " & (2*$a)+(2*$B) & " cm") EDIT: 1) I can't use isNumber(). I tried but I can't do it. 2) I maked a do-until loop but loops and even when I type a number.. 3) Any help? Edited March 13, 2007 by Hello Me You Random Link to comment Share on other sites More sharing options...
nitekram Posted March 13, 2007 Share Posted March 13, 2007 I still can't figure it out. Here is my source: $a = InputBox("Side A", "Length of side A (cm)") If $a<0 Or @error Then MsgBox(16, "Error!", "Invalid value") $b = InputBox("Side B", "Length of side B (cm)") If $b<0 Or @error Then MsgBox(16, "Error!", "Invalid value") MsgBox(64, "Area and Perimeter", "Area: " & $a*$b & " cm²" & @CRLF & "Perimeter: " & (2*$a)+(2*$B) & " cm")oÝ÷ Ø@ÈORj}ý¶ëÃn·«"ÚâyÖî´mvØçZv§¶)e¢[ºÙh¢×¯z|!zr-Êéz½À(^êº^1¬zëiÚ.Ø¥Zê뢶®¶s`¦Fð¢b33c¶ÒçWD&÷gV÷Cµ6FRgV÷C²ÂgV÷C´ÆVæwFöb6FR6ÒgV÷C²§VçFÂb33c¶fwC³÷"äõBW'&÷ code not tested 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator Link to comment Share on other sites More sharing options...
Hello Me You Posted March 13, 2007 Author Share Posted March 13, 2007 My only problem is that I can not an error when value contains letters.. $a = InputBox("Side A", "Length of side A (cm)") If $a<0 Or @error Then MsgBox(16, "Error!", "Invalid value") $b = InputBox("Side B", "Length of side B (cm)") If $b<0 Or @error Then MsgBox(16, "Error!", "Invalid value") MsgBox(64, "Area and Perimeter", "Area: " & $a*$b & " cm²" & @CRLF & "Perimeter: " & (2*$a)+(2*$B) & " cm") Random Link to comment Share on other sites More sharing options...
Hello Me You Posted March 13, 2007 Author Share Posted March 13, 2007 Except of the preview post I want to say that if there is an error (e.g. at the first side [A]) the script will continue to the side B without asking again the side. Here is when we need Go To command... What can I do for that? Random Link to comment Share on other sites More sharing options...
BigDod Posted March 13, 2007 Share Posted March 13, 2007 From the help fileInputBox --------------------------------------------------------------------------------Displays an input box to ask the user to enter a string.Therefor your input is always going to be a string Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother Link to comment Share on other sites More sharing options...
Hello Me You Posted March 13, 2007 Author Share Posted March 13, 2007 (edited) Therefor your input is always going to be a stringI want to check if only numbers are entered. Edited March 13, 2007 by Hello Me You Random Link to comment Share on other sites More sharing options...
BigDod Posted March 13, 2007 Share Posted March 13, 2007 Try do $a = InputBox("Side A", "Length of side A (cm)") until not StringIsAlpha($a) Do $b = InputBox("Side B", "Length of side B (cm)") until not StringIsAlpha($B) MsgBox(64, "Area and Perimeter", "Area: " & $a*$b & " cm²" & @CRLF & "Perimeter: " & (2*$a)+(2*$B) & " cm") Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother Link to comment Share on other sites More sharing options...
Hello Me You Posted March 13, 2007 Author Share Posted March 13, 2007 (edited) Thanks BigDod, finally I am done. What do you think, is it complete (for algorithm)? Here it is: Do $a = InputBox("Side A", "Length of side A (cm)", "Numbers Only") If @error = 1 Then Exit If StringIsAlpha($a) Then MsgBox(16, "Numbers Only!", "Please enter numbers only.") If $a < 0 Or @error Then MsgBox(16, "Error!", "Invalid value.") Until $a > 0 And Not @error Do $b = InputBox("Side B", "Length of side B (cm)", "Numbers Only") If @error = 1 Then Exit If StringIsAlpha($B) Then MsgBox(16, "Numbers Only!", "Please enter numbers only.") If $b < 0 Or @error Then MsgBox(16, "Error!", "Invalid value.") Until $b > 0 And Not @error SoundPlay(@WindowsDir & "\media\tada.wav") MsgBox(64, "Area and Perimeter", "Area: " & $a * $b & " cm²" & @CRLF & "Perimeter: " & (2 * $a) + (2 * $B) & " cm") Edited March 13, 2007 by Hello Me You Random 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