Using sub or function when passing parameter to vb.net exe ?

Ask general questions here.
rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

Using sub or function when passing parameter to vb.net exe ?

Post by rastek » Fri Aug 08, 2014 11:20 am

When I create a console project in program.vb main function created like this
Function Main() As Integer

But examples I found in the internet always defines main like this
Sub Main(Byval args() As String)

so, when I change main to this and define a variable inside main function like this
Dim Data1 As String = args(0)

and when I build the project gives error as "No accesible 'Main' method with an appropriate signature was found in 'Call' (BC30737)

so I comment out Return ErrorNumber and changed function to sub and it worked ?

this means If I want to pass parameters to main I can not return ?

I mean ranorex exe returns an error code and also I need it bedise passing parameter.

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Using sub or function when passing parameter to vb.net exe ?

Post by krstcs » Fri Aug 08, 2014 1:38 pm

You should not change the main function's signature, if should be a FUNCTION.

SUB does not return a value.
Shortcuts usually aren't...

rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

Re: Using sub or function when passing parameter to vb.net exe ?

Post by rastek » Fri Aug 08, 2014 1:58 pm

I know SUB does not return a value but how can I pas parameter

MSDN site tells that

http://msdn.microsoft.com/en-us/library/3ewaa0yy.aspx
Command-line applications must have a Sub Main defined. Main must be declared as Public Shared if it is defined in a class,

or as Public if defined in a module.

Define a Public Sub Main procedure for your project. Declare it as Shared if and only if you define it inside a class.

What can I do ??

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Using sub or function when passing parameter to vb.net exe ?

Post by krstcs » Fri Aug 08, 2014 2:13 pm

On the command-line parameter issue, I would expect that Ranorex takes this into account with the Environment.CommandLine object that gets passed into the test runner.

Have you tried passing in a global parameter at the command-line to see if it works with the FUNCTION variant?



My recommendation is to use C# for coding in Ranorex. Personally, I don't touch VB because I think it is a poor language (do we really need sub with no return vs. just using a void return function like C#/Java/C/C++??) designed a long time ago for non-developers to code in and dropping it in over the top of .NET didn't help it. And if you are coming from VBScript (QTP for instance), VB.NET is enough different that you won't gain much by staying with it. C# is more consistent with other high-level languages and learning it would help you understand Java, JavaScript, C/C++, etc., better. Just my 2 cents though...
Shortcuts usually aren't...

rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

Re: Using sub or function when passing parameter to vb.net exe ?

Post by rastek » Fri Aug 08, 2014 2:41 pm

Yeah I come form VBScript (QTP) also know a little bit c# before but I used to the vbscript.

Is that a proper solution If: I use driver program (a console application with c#) and other projects in vb.net ?

Then I can call other tests in vb.net.

There is still some points I didnt get using parameters.
How can I parse different parameters in the code ?

Cna you give me some example code block ?

Thanks in advance.