Sundance Posted February 13, 2012 Share Posted February 13, 2012 Hiho,i don't know if this behavior is normal but i would like to hear your thoughts.Look at the following code._Test(0) Func _Test($iFirst = "nothing") If $iFirst = "nothing" Then ConsoleWrite("$iFirst = nothing" & @CRLF) ConsoleWrite("Parameterval: " & $iFirst & @CRLF) EndIf EndFuncThe if expression inside the function will be true even when i do give the function the paramter 0.Is this a bug. In my special case i have an optional paramter which can be range from 0 to n. But at the moment i can't pass the value 0 to my function...Hope someone can clarify this for me and thanks in advanceSundance Link to comment Share on other sites More sharing options...
jaberwacky Posted February 13, 2012 Share Posted February 13, 2012 _Test(0) Func _Test($iFirst = "nothing") If $iFirst == "nothing" Then ConsoleWrite("$iFirst = nothing" & @CRLF) ConsoleWrite("Parameterval: " & $iFirst & @CRLF) EndIf EndFunc Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 13, 2012 Moderators Share Posted February 13, 2012 Sundance,You are mixing string and number values in your If statement which will usually end in tears. "nothing" will be converted to a number value of 0, which coincidentally is the value you compare it to. LaCastiglione's suggestion to use the == operator will force a string comparison and thus work correctly. As a general rule avoid number/string comparisons as they can give you results you do not expect - even though AutoIt is handling them as best it can it cannot read your mind. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
ProgAndy Posted February 13, 2012 Share Posted February 13, 2012 In this case, I would use either the keyword Default and/or @NumParams ConsoleWrite(">_Test()" & @LF) _Test() ConsoleWrite(">_Test(Default)" & @LF) _Test(Default) ConsoleWrite(">_Test(0)" & @LF) _Test(0) Func _Test($iFirst = Default) If @NumParams = 0 Then ConsoleWrite("No parameter" & @LF) ElseIf $iFirst = Default Then ConsoleWrite("Parameter Default" & @LF) EndIf EndFunc ConsoleWrite(">_Test2()" & @LF) _Test2() ConsoleWrite(">_Test2(Default)" & @LF) _Test2(Default) ConsoleWrite(">_Test2(0)" & @LF) _Test2(0) Func _Test2($iFirst = Default) If $iFirst = Default Then ConsoleWrite("Parameter Default" & @LF) EndIf EndFunc *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
Sundance Posted February 14, 2012 Author Share Posted February 14, 2012 Oh my god. I knew it was my fault. How could i mix an integer with a string. Yesterday i was very sleepy and in the middle of programming i felt asleep! Sorry for posting such a dump question and many thanks for your answers!! I didn't knew @NumParams. Also a possible way. Thx again folks!! Today i fell better and got enough sleep last night so and think a won't post today greetz Sundance 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