taylansan Posted January 24, 2023 Share Posted January 24, 2023 Hello, I wanted to call a function inside ConsoleWrite: ConsoleWrite("Hello " & _write15() & " B" & @CRLF) ConsoleWrite("END" & @CRLF) Func _write15() ;ConsoleWrite("15") ConsoleWrite(5*3) EndFunc I was expecting this output: Hello 15 B END But what I got is: 15Hello 0 B END If I change the function like this, of course it will work (without calling function): ConsoleWrite("Hello " & 5*3 & " B" & @CRLF) ConsoleWrite("END" & @CRLF) Func _write15() ;ConsoleWrite("15") ConsoleWrite(5*3) EndFunc As you can see, ConsoleWrite executed the _write15() before writing Hello, even Hello comes before the function. In addition to that, there is a "0" in the middle of my output. I have no idea where it came from. Please note that: I know we can assign the output of _write15() to a variable and call that variable in ConsoleWrite or maybe some easy solutions. But the goal is to call the function within ConsoleWrite. TY. Link to comment Share on other sites More sharing options...
Danp2 Posted January 24, 2023 Share Posted January 24, 2023 The ConsoleWrite in the function completes before the one in the main script, so the output you saw makes sense to me. You should return the result from the function if you want it to appear inline with the other text -- ConsoleWrite("Hello " & _write15() & " B" & @CRLF) ConsoleWrite("END" & @CRLF) Func _write15() Return 5*3 EndFunc ioa747 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
ioa747 Posted January 24, 2023 Share Posted January 24, 2023 (edited) you can call in this order ConsoleWrite("Hello ") _write15() ConsoleWrite(" B" & @CRLF & "END" & @CRLF) Func _write15() ;ConsoleWrite("15") ConsoleWrite(5*3) EndFunc or ConsoleWrite("Hello " & _write15() & " B" & @CRLF) ConsoleWrite("END" & @CRLF) Func _write15() ;ConsoleWrite("15") Return 5*3 EndFunc Edited January 24, 2023 by ioa747 JLogan3o13 1 I know that I know nothing Link to comment Share on other sites More sharing options...
ioa747 Posted January 24, 2023 Share Posted January 24, 2023 @JLogan3o13 give an explanation please I know that I know nothing Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted January 24, 2023 Moderators Share Posted January 24, 2023 Your post confused me, as it is almost an exact copy of Danp2's. Perhaps you guys posted at the exact same time. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
ioa747 Posted January 24, 2023 Share Posted January 24, 2023 the truth is that I didn't notice, I put one first and then the second . but now i understand why you are confused @Danp2 i am Sorry ! I know that I know nothing Link to comment Share on other sites More sharing options...
taylansan Posted January 25, 2023 Author Share Posted January 25, 2023 21 hours ago, ioa747 said: you can call in this order Yeah, I know that order will work. But if the script is allowing me to use in the way that I use, without any compile errors, then it should be fine. And you can see in the below example that, I'm not separating in different lines. The thing is, if I want to use any inbuilt function such as String Length: ConsoleWrite("Hello " & StringLen("abcdefg") & " B" & @CRLF) ConsoleWrite("END" & @CRLF) ;I'm not dividing the 1st line into 3 parts as you suggested: ;ConsoleWrite("Hello ") ;ConsoleWrite(StringLen("abcdefg")) ;ConsoleWrite(" B" & @CRLF) ;ConsoleWrite("END" & @CRLF) My output will be as below as expected, which is good and correct: Hello 7 B END Which makes me think that I can use my function inside the console write too. Assume that my function is not doing any arithmetic equation, just another console write: ConsoleWrite("Hello " & _write15() & " B" & @CRLF) ConsoleWrite("END" & @CRLF) Func _write15() ConsoleWrite("15") ;Return 5*3 EndFunc ;This gives the below output ;15Hello 0 B ;END If I change that _write15() function to Return("15"), that will work too. So, I'm confused where that 0 comes from when I call _write15 which has ConsoleWrite inside. Also writing that "15" in the beginning of the output is confusing too. TY. Link to comment Share on other sites More sharing options...
Danp2 Posted January 25, 2023 Share Posted January 25, 2023 5 minutes ago, taylansan said: So, I'm confused where that 0 comes from when I call _write15 which has ConsoleWrite inside. From the help file -- Quote Use the Return keyword to exit the function. Unlike built-in functions, user-defined functions return 0 unless another return value is specified. So that explains where the 0 comes from. I believe I addressed your other confusion in my prior post, so maybe you could elaborate on why you are still confused. pixelsearch and taylansan 2 Latest Webdriver UDF Release Webdriver Wiki FAQs 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