Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing variables with values into vb.net application (.exe) 2

Status
Not open for further replies.

vj

Programmer
Nov 18, 2000
58
MU

hi everyone,

i have a visual foxpro9sp2 form and i need to pass some variables with values into vb.net application , here is what iam doing :

MAPCODE=CUSTOMER.CUSTOMER_CODE
MAPSTREET=CUSTOMER.CUSTOMER.ADDRESS2
MAPCITY=CUSTOMER.CITY

DECLARE INTEGER ShellExecute IN shell32.dll ;
INTEGER hndWin, ;
STRING cAction, ;
STRING cFileName, ;
STRING cParams, ;
STRING cDir, ;
INTEGER nShowWin

cFileName="C:\Documents and Settings\sunny\Desktop\Locator-with-Setup\Locator\TEST.EXE"
cAction = "open"
cParams = "MAPCODE,MAPSTREET,MAPCITY"
ShellExecute(0,cAction,cFileName,"cParams","",1)

the vb.net application comes up fine .. but for some reason i think the values from the variables i'v passed are not read into the vb.net form ... can anyone tell if there's anything wrong in the above lines or is there another way to do it ..

thankx alot
vijay
 
The problem is that you are passing the names of the variables (Mapcode, etc) not the contents of the variables.

You need to pass a single string, containing the contents of the variables, in whatever format the target application is expecting. Assuming that it is expecting a comma-delimited string, you need something like this:

[tt]cParams = ALLTRIM(Mapcode) + "," + ALLTRIM(MapStreet) + "," + ALLTRIM(MapCity)[/tt]

Of course, you also need to be sure that the target program is capable of picking up command-line parameters. But that's a VB.NET issue, not a VFP one.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike is corerect.

And with cParams filled as he did, you need to call ShellExecute(0,cAction,cFileName,cParams,"",1)
I'd also separate cDir from cFilename, so cDir = "C:\Documents and Settings\sunny\Desktop\Locator-with-Setup\Locator\", cFilename = "TEST.EXE"

Bye, Olaf.
 
hi guys,

thankx for the reply ... hmm ... ok mike i'll do as you said ... cParams = ALLTRIM(Mapcode) + "," + ALLTRIM(MapStreet) + "," + ALLTRIM(MapCity) ... but can anyone tell me .. how the vb.net application will accept or read these values ... i mean can these values be read into a text box ... e.g. thisform.text1.value=mapcode .... and then it just appears there inside the text box ... could anyone just give some hints on that ... this is the first time iam doing this sort of thing !

thankx alot
vijay
 
how the vb.net application will accept or read these values

As I said earlier, that's really a VB question.

I've never done VB.NET. I have done C#, which might be similar. As far as I remember, to receive command-lime parameters in C#, you add this line to your main program:

[tt]static void Main(string[], args)[/tt]

Maybe someone else here can give you a more helpful answer. Alternatively, you could ask in a VB.NET forum. (If you do that, just ask how to receive command-line parameters. Don't confuse the folk there with mentions of Visual FoxPro.)

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
The short answer is that anything is possible, but the VB app has to be written to accept your parameters. It doesn't magically know automatically.

As such, the author of the program should tell you exactly how it expects to receive parameters.

If the program was not written to receive parameters then you can pass them all day long but there's nothing to receive them or do anything with them.
 
I just found some old VB.NET code which might help.

In fact, it seems to be very simple. To receive the parameters in your main program:

[tt]Dim strStartupArguments() As String
strStartupArguments = System.Environment.GetCommandLineArgs[/tt]

[tt]strStartupArguments[/tt] then contains the three parameters that you passed from your VFP program. So [tt]strStartupArguments(0)[/tt] will contain the MapCode, [tt]strStartupArguments(1)[/tt] will contain the street address, and so on.

I've got no way to test this, so cannot guarantee that it's correct, but it should give you something to work on.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
If you create a Console Application project in .NET, doesn't matter if C# or VB.NET, you get a main code, as Mike showed earlier.
Actually the project template for VB.NET console applications does not include args, while C# does.

VS2010 (Ultimate) generates a VB stub of:
Code:
Module Module1

    Sub Main()

    End Sub

End Module

Change that to
Code:
Module Module1

    Sub Main(ByVal args As String())

    End Sub

End Module
Parameters arrive in the args string array, System.Environment.GetCommandLineArgs is another place they will be available even later on, but you typically process parameters in the main code right away.

What's important to know, if you set cParams = "1,2,3" you get 1 parameter, the string "1,2,3", Commandline parameters have to be separated by space, not by comma, so set cParams = "1 2 3" to get three parameters "1", "2" and "3". If you want a parameter value to contain a space, put the parameter itself in quotes, so set cParams='"1 2" 3' to get two parameters args(0)="1 2" and args(2)="3".

The value type will always be string, args is an array of strings, no matter if C# or VB.NET, you have to define what parameters should be and convert them from string to whatever you need.

Bye, Olaf.



 
hi guys,

thankx alot for all the replies ... it's all working fine .. iam able to pass parameters and i can even receive it on the vb.net form ... now the PROBLEM is ... the info i receive on vb.net form is broken up ... e.g value in MAPCITY is : Port Louis and value in MAPSTEET is : Turner Road. so now the vb.net app reads it as 4 different arguments ... what can be done to read them as only 2 arguments only Port Louis separate and Turner Road. separate ????

thanks
vijay
 
Vijay,

By coincidence, I was thinking of this very point earlier today. I realised that if the parameters are space-delimited, you will need to put quotes around them.

So, amend your VFP code to read as follows:

Code:
cParams = ;
    ["] + ALLTRIM(Mapcode) + ["] + "," + ;
    ["] + ALLTRIM(MapStreet) + ["] + "," + ;
    ["] + ALLTRIM(MapCity) + ["]

That should give you the correct three parameters in VB. I'm not sure if the parameters in VB will still have the quotes. If they do, you will have to remove them within the VB program.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 

thankx alot everyone ,,, it's working perfectly fine now ...
 
I already talked about space separaation of parameters and putting parameters including spaces in quotes. You can do so always, preventive.

Anyway, problem solved.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top