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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing a return value from vb.net to vfp

Status
Not open for further replies.

jpower69

Programmer
Feb 5, 2008
54
US
I am using the following statements in VFP.
DECLARE INTEGER ShellExecute IN shell32.DLL ;
INTEGER hndWin, ;
STRING cAction, ;
STRING cFileName, ;
STRING cParams, ;
STRING cDir, ;
INTEGER nShowWin

**

cAction = "open"
cFileName = "c:\temp\ping_servers.exe"
cParams = ALLTRIM(In_Params)
cPath = "c:\temp\"

mrtn = ShellExecute(0,cAction,cFileName,cParams,cPath,1)

As you can see, I pass variables to my vb.net application, ping_servers.exe
this is my vb.net code being called
Imports System.Net.NetworkInformation
Imports System.Text
Imports System.Environment


Public Class ping_servers

Dim lretval As Integer = -1
Dim gserver As String

Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Dim gserver As String

TextBox2.Text =
This is My vb.ne


'gserver = Trim(TextBox2.Text)
gserver = Trim(Environment.GetCommandLineArgs(1))

lretval = ping(gserver)


If lretval = True Then

MessageBox.Show("Ping is Successful")
Else

MessageBox.Show("Ping failed")
End If

Return

Me.Dispose()
End Sub


Public Function ping(ByVal server As String) As String


Dim reply As System.Net.NetworkInformation.PingReply
Dim p As New System.Net.NetworkInformation.Ping

Try
reply = p.Send(server, 1000)
If reply.Status.ToString = "Success" Then
lretval = True
End If

Catch ex As Exception
lretval = False

End Try

Return lretval

End Function


End Class

I knoow this routine works, I display the messagebox stating 'Ping successfulle/fail)
what I need to do, is to return the value of the variable lretval (wgich is either true or false) back to the calling rprogram
in this case vfp
the mrtn mentioned above returns a value that represents a successful call, not the actual value
I am relatively new at vb.net and I have been looking around and can not seem to find exactly what I need
I've tried environment.exitcode, but i have not been abole to pass it back to vfp

Any comments/suggestions greatly appreciated

thanks in advance
 

Well, a .NET application can only return a single Int32, so you could return 0 for false and 1 for true. You need a Main function in your code, with a return value of Integer:

Public Sub Main() As Integer


End Sub

In fact, I would make the .NET program a console application, not a Windows Forma application, unless you really need the message boxes and such. If you do a console app, it would look like this:

Code:
Dim lretval As Integer = -1
Dim gserver As String

Public Sub Main() As Integer

    Dim gserver As String

    gserver = Trim(Environment.GetCommandLineArgs(1))

    lretval = ping(gserver)

    Return lretval

End Sub

Public Function ping(ByVal server As String) As String

    Dim reply As System.Net.NetworkInformation.PingReply
    Dim p As New System.Net.NetworkInformation.Ping

    Try
        reply = p.Send(server, 1000)
        If reply.Status.ToString = "Success" Then
            lretval = True
        End If

    Catch ex As Exception
        lretval = False

    End Try

    Return lretval

End Function

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
thanks for the info

I'll try and let you know

again thanks

happy halloween...

 
I created the following

Imports System.Net.NetworkInformation
Imports System.Text
Imports System.Environment

Module test_ping

Dim lretval As Integer = -1
Dim gserver As String


Public Sub Main()

Dim gserver As String

gserver = Trim(Environment.GetCommandLineArgs(1))

lretval = ping(gserver)

Return lretval<< I get 'Return' Statement in a sub or set cannot return a value


End Sub

Public Function ping(ByVal server As String) As String


Dim reply As System.Net.NetworkInformation.PingReply
Dim p As New System.Net.NetworkInformation.Ping

Try
reply = p.Send(server, 1000)
If reply.Status.ToString = "Success" Then
lretval = 1
End If

Catch ex As Exception
lretval = 0

End Try

Return lretval

End Function
silly question, but what am i missing here
 

Oops...my bad. The definition of Main() should be as a function, not a sub:

Public Function Main() As Integer

Sorry about that.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top