Cannot Use Parentheses When Calling A Sub Error In Qtp
Contents |
Select Page Cannot use parentheses when calling a Sub: 3 Techniques You Won't Get This Error by Ankur Jain | Last Updated On Aug 8, 2016 | Some Common Errors/ Issues, VB Script and QTP | 3 comments If you have worked on QTP with VB cannot use parentheses when calling a sub vbs Script for sometime, I’m sure you have encountered this error Cannot use parentheses when
Cannot Use Parentheses When Calling A Sub Msgbox
calling a Sub. While at times you may have received this error because of a genuine mistake, most of the other
Cannot Use Parentheses When Calling A Sub Asp
times this maybe because of a quirk with VB Script. Let me show that with the help of an example.I have created two functionsfunction oneargument(x) msgbox "In a function with a single argument " &
Cannot Use Parentheses When Calling A Sub Vbscript
x End functionfunction twoarguments(x,y) msgbox "In a function with two arguments " & x & " and " & y End functionWhat do you think will be the output of following codefunction oneargument(x) msgbox "In a function with a single argument " & x End function Call oneargument(10) oneargument(10)Now guess the answer for this piece of codefunction twoarguments(x,y) msgbox "In a function with two arguments " & x & cannot use parentheses when calling a sub replace " and " & y End function Call twoarguments(10,20) twoarguments(10,20)The two functions above are almost the same and here is what it gets interestingThe first piece of code above would run fine but the last call to twoarguments function will error out saying Cannot use parentheses when calling a Sub. While a call to a single argument function, with parenthesis works fine with or without using Call keyword, call to a function with more than one arguments using parenthesis will error out if you use parenthesis and omit Call keyword.As a thumb rule, here are the ONLY 3 situations where you can use parenthesis safely with VBScript.Result = twoarguments(10,20) : When you retrieve the return value from a function with an assignment operator, you can have any number of arguments in parenthesis.Call twoarguments(10,20): When you use the Call keyword, you can have any number of arguments in parenthesis.oneargument(10): When you don’t use the Call keyword and you don’t have an assignment operator to retrieve return value, you can only have one argument in parenthesis.Outside these 3, you should call functions/subroutines without using parenthesis.Over to you, do you know any other quirk with VB Script? You Should Read These 3 Related Articles Too!VB Script and QTP - Part3HP QTP Quiz:
calling a Sub" If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before cannot use parentheses when calling a sub classic asp you can post: click the register link above to proceed. To start viewing 800a0414 messages, select the forum that you want to visit from the selection below. Results 1 to 3 of expected end of statement 3 Thread: *RESOLVED* VBS:"Cannot use parentheses when calling a Sub" Tweet Thread Tools Show Printable Version Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode http://www.learnqtp.com/cannot-use-parentheses-when-calling-a-sub-3-reasons/ Oct 4th, 2004,07:14 PM #1 Disiance View Profile View Forum Posts Visit Homepage Thread Starter Hyperactive Member Join Date Sep 2004 Location Denver, CO Posts 439 *RESOLVED* VBS:"Cannot use parentheses when calling a Sub" I get the error: "Cannot use parentheses when calling a Sub" when I try to call a function in my ASP code that takes two parameters. This works: Code: http://www.vbforums.com/showthread.php?307544-*RESOLVED*-VBS-quot-Cannot-use-parentheses-when-calling-a-Sub-quot Function MyTest(para1) End Function MyTest("test") This doesn't: Code: Function MyTest(para1,para2) End Function MyTest1("test1","test2") Disiance Last edited by Disiance; Oct 5th, 2004 at 10:26 AM. Reply With Quote Oct 4th, 2004,08:08 PM #2 Danial View Profile View Forum Posts Big D Join Date Jul 2000 Location ASP.Net Forum Posts 2,877 Re: VBS:"Cannot use parentheses when calling a Sub" Originally posted by Disiance This doesn't: Code: Function MyTest(para1,para2) End Function MyTest1("test1","test2") Disiance Use : Code: Function MyTest(para1,para2) End Function MyTest1 "test1","test2" or Code: Function MyTest(para1,para2) End Function Call MyTest1("test1","test2") [VBF RSS Feed] There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side. If I have been helpful, Please Rate my Post. Thanks. This post was powered by : Reply With Quote Oct 5th, 2004,10:26 AM #3 Disiance View Profile View Forum Posts Visit Homepage Thread Starter Hyperactive Member Join Date Sep 2004 Location Denver, CO Posts 439 Ugg, I feel so stupid, I've been using VBScript/VB for 4 years now, DUH! Thanks, Disiance Reply With Quote Quick Navigation ASP, VB Script Top Site Areas Settings Priv
parenthesis when calling a Sub' when I try to use a function in my QTP script? People who like this Close Like · 0 · Add comment Comment 10 |600 characters needed characters http://eyeontesting.com/questions/5955/cannot-use-parenthesis-when-calling-a-sub.html left characters exceeded ▼ Viewable by all users Viewable by moderators Viewable by moderators http://www.webdeveloper.com/forum/showthread.php?256509-Cannot-use-parentheses-when-calling-a-Sub and the original poster Viewable by all users 1 Reply · Add your reply Sort: Best Answer Answer by Rich Text · Apr 30, 2014 at 03:04 PM This is talked about on many VBScripting websites and tutorials, but it basically breaks down into how you are calling or using the function in a script. Below cannot use is a summary I found on a VBScript tutorial site a while ago that helps clarify: If you are using a variable to capture a value returned from a function, you can enclose as many arguments as you need within parenthesis, such as: return_value = LogMeIn ("user1","password1","region 5") If you are using the optional Call before the function, you can also have many arguments in parenthesis, such as: Call cannot use parentheses LogMeIn ("user1","password1","region 5") Notice there is no return value in the Call statement, but it allows parenthesis If you are only going to pass one argument into the function AND you are not returning a value back to the calling script, you can put the one argument in parenthesis, such as: LogMeIn ("user1") If you are not using the above situations, usually you not use parenthesis around the arguments of the function. Example: LogMeIn "user1","password1","region 5" Comment KaptainKayoss balzac Gandalesh People who like this Close Like · 3 · Add comment · Share 10 |600 characters needed characters left characters exceeded ▼ Viewable by all users Viewable by moderators Viewable by moderators and the original poster Viewable by all users Your answer Hint: You can notify a user about this post by typing @username Attachments: Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total. Stuff we like Orasi Software Perfecto Mobile Follow Follow this Question Answers Answers and Comments 2 People are following this question. Related Questions Getting error code 80004005 on CreateObject 1 Answer Error when trying to use QTP API in script file 1 Answer QTP addin for QC will not install 2 An
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. Results 1 to 5 of 5 Thread: Cannot use parentheses when calling a Sub Tweet Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 02-08-2012,12:23 PM #1 fredmv View Profile View Forum Posts Moderator Join Date Jul 2003 Location Boston Area, Massachusetts Posts 3,489 Cannot use parentheses when calling a Sub Hi folks, I'm working on a relatively simple feature to update some content in a database - a time-stamp, specifically. However, every time I try to make the call, I get the following error: Code: Microsoft VBScript compilation error '800a0414' Cannot use parentheses when calling a Sub /datetest.asp, line 31 UpdateContactBK(StrContactNo,ObjTrack,pd(DAY(date()),2) & " " & MonthName(2,true) & " " & YEAR(date()),"TrainAcc") ------------------------------------------------------------------------------------------------------------------^ The corresponding code: Code: <% Function pd(n, totalDigits) if totalDigits > len(n) then pd = String(totalDigits-len(n),"0") & n else pd = n end if End Function Function returnDateString() Dim lastAccDate lastAccDate = pd(DAY(date()),2) & " " & MonthName(2,true) & " " & YEAR(date()) returnDateString = lastAccDate End Function Response.Write(returnDateString()) UpdateContactBK(StrContactNo,ObjTrack,returnDateString(),"TrainAcc") %> As you'll see, the Response.Write call is perfectly fine, and correctly prints the date in MM-DD-YYYY format. However, the compiler doesn't seem to like the red line. I've read http://blogs.msdn.com/b/ericlippert/...dex=2#comments amongst other blogs, but to no avail. I'd like some other opinions. Note: UpdateContactBK method omitted, as it isn't relevant. Thanks, all. Last edited by fredmv; 02-08-2012 at 12:39 PM. Moderator @ WebDeveloper.com Reply With Quote 02-08-2012,01:23 PM #2 yamaharuss View Profile View Forum Posts Visit Homepage V8 Rider Join Date Jan 2008 Location Florida Posts 1,227 http://blogs.msdn.com/b/ericlippert/.../15/52996.aspx Internet Design Concepts Web Development, Hosting and eCommerce/Database Project Development Reply With Quote 02-08-2012,01:46 PM #3 fredmv View Profile View Forum Posts Moderator Join Date Jul 2003 Location Boston Area, Massachusetts Posts 3,48