themax90 Posted August 8, 2006 Posted August 8, 2006 Okay. As it seems for various values and parameters I find myself writing out every possible type in a param combination/type. For example Math(a, b, type) As represented in C++: expandcollapse popup#include <iostream> using namespace std; float Math(float a, float b, float c) { /* Math function. a (param c) b. 1 = Add 2 = Subtract 3 = Multiply 4 = Divide */ float d; if (c == 1) { d = a + b; } else if (c == 2) { d = a - b; } else if (c == 3) { d = a * b; } else if (c == 4) { d = a / b; } else { return -1; } return(d); } int main(void) { cout << "2 + 2 : "; cout << Math(2, 2, 1); return 0; } As represented in AutoIt: $Type = InputBox("Type...", "1 = add, 2 = subtract, 3 = multiply, 4 = divide") $Result = Math(2, 2, $Type) If @Error Then Exit MsgBox(16, "Error", "Invalid type.") MsgBox(0, "Result", $Result) Func Math($a, $b, $c) If $c = 1 Then Return ($a + $B) If $c = 2 Then Return ($a - $B) If $c = 3 Then Return ($a * $B) If $c = 4 Then Return ($a / $B) If $c <= 0 Or $c >= 5 Then SetError(-1) EndFunc My question is this : Is there a simpler way of coding this without all the hassle of writing out each type? Thanks, just wondering. AutoIt Smith
Moderators SmOke_N Posted August 8, 2006 Moderators Posted August 8, 2006 (edited) How about:$Type = '*' ;~ $Type = InputBox("Type...", "+ = add, - = subtract, * = multiply, / = divide") $Result = Math(2, 2, $Type) If @Error Then Exit MsgBox(16, "Error", "Invalid type.") MsgBox(0, "Result", $Result) Func Math($a, $b, $c) Return Execute($a & $c & $B) EndFunc Edited August 8, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
themax90 Posted August 8, 2006 Author Posted August 8, 2006 How about:$Type = '*' ;~ $Type = InputBox("Type...", "+ = add, - = subtract, * = multiply, / = divide") $Result = Math(2, 2, $Type) If @Error Then Exit MsgBox(16, "Error", "Invalid type.") MsgBox(0, "Result", $Result) Func Math($a, $b, $c) Return Execute($a & $c & $B) EndFuncIs there a way to do it in C++?
Moderators SmOke_N Posted August 8, 2006 Moderators Posted August 8, 2006 Is there a way to do it in C++?Huh? I thought you wanted an easier way in AutoIt I would look up to see if the Execute function is released in the source if I were you. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
nfwu Posted August 8, 2006 Posted August 8, 2006 float Math(float a, float b, float c) { /* Math function. a (param c) b. 1 = Add 2 = Subtract 3 = Multiply 4 = Divide */ float d; if (c < 1 || c > 4) return -1; if (c < 3){ if (c == 2) b *= -1; return a + b; } if (c > 2){ if (c == 4) b = 1 / b; return a * b; } } #) TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode()
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