Solved

How to create a vb prog that will accept the parameters ?

Posted on 2000-05-17
32
334 Views
Last Modified: 2010-05-02
I would like to create an simple vb prog that will accept some parameters
from another vb prog. For example :

vbprog1 has 3 textboxes. There are :
 - name
 - age
 - phone number
and this vbprog1 only accept these
three parameter from other prog.

Let assume, I also has another vb prog called vbprog2. This vbprog2 has a button. After I press the button, this vb prog2 will pass name, age and phone number as parameters to vbprog1. After
the button is pressed, the vbprog1 will be popped up and name, age and phone number fields have the contents pasted from vbprog1.

How to do it ? Any example ?


Thanks a lot !
0
Comment
Question by:sing_web
  • 9
  • 8
  • 5
  • +7
32 Comments
 
LVL 9

Expert Comment

by:Ruchi
Comment Utility
"How to pass strings between two app's"
http://www.vbgreatone.8m.com/VB/downloads/PassString.zip

http://www.thescarms.com/vbasic/PassString.htm. This sample shows how to send string from one VB app to another
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
just curious...why have two separate applications as opposed to multiple forms?
0
 

Author Comment

by:sing_web
Comment Utility
Just want to learn !
0
 
LVL 9

Expert Comment

by:Ruchi
Comment Utility
Are the links I posted helpful to you?
0
 
LVL 9

Expert Comment

by:GivenRandy
Comment Utility
I won't speak for sing_web, but I could not get the first URL to work.  The second one was fine.
0
 
LVL 1

Expert Comment

by:lochiano
Comment Utility
The way that we do it is with the command line options

''assume that the program is started with A.exe /L:JoeDoe '''
strCMD = Command()



   
y = InStr(strCmd, "/L:")
If y > 0 Then
    y = y + 3
    z = InStr(y, strCmd, " ") - y
    gstrLoginName = Mid(strCmd, y, z)
End If


0
 

Expert Comment

by:Billy06
Comment Utility
Are you talking about two separate VB project?
Or Multiple Forms?
If Multiple forms, it's fairly simple.
I haven't seen it done with two separate VB Project..
0
 

Author Comment

by:sing_web
Comment Utility
I am talking about two separate vb progs.


Ruchi :
 
when I went to :

http://www.vbgreatone.8m.com/VB/downloads/PassString.zip

I was asked for username and password.
What is the username and password ?

 
0
 
LVL 9

Expert Comment

by:Ruchi
Comment Utility
I could not get the first URL link to work, too. Anyway, I did test a few months ago, and I don;t think it did not mention any username or password. Did you try to go to the second link?
0
 
LVL 9

Expert Comment

by:Ruchi
Comment Utility
The first link I posted is not working, but that link, I think, equivalent is http://vbabc.hypermart.net/misc/PassString.zip
0
 

Author Comment

by:sing_web
Comment Utility
lochiano :

Can you explain your code in details. Thanks !
0
 
LVL 9

Expert Comment

by:Ruchi
Comment Utility
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
This is primitive Private clipboard format sample :)
Of course, you'll not use strings like "Sing Web", but textbox names, e.g. txtName.Text

Private Sub Form_Click()
'   put this to cmdSendData in your first app
    Clipboard.Clear
    Clipboard.SetText "Sing Web" & vbCrLf & "220" & vbCrLf & "555-555"

'   put this to cmdReceiveData in your second app
    Dim s As String, data() As String
    s = Clipboard.GetText
    data = Split(s, vbCrLf)
    MsgBox "Name: " & data(0) & vbCrLf & _
        "Age: " & data(1) & vbCrLf & _
        "Phone: " & data(2) & vbCrLf
End Sub
0
 
LVL 1

Expert Comment

by:tirupur_selva
Comment Utility
Try the "LinkMode" property in the form's property window. Refer MSDN for complete example of its functioning.
0
 
LVL 13

Expert Comment

by:crazyman
Comment Utility
Why you you try Dynamic Data Exchange for passing between running apps, using the command$ only works if your actually starting the second app from the first.
0
 
LVL 13

Expert Comment

by:crazyman
Comment Utility
From microsoft KB.



INFO: Using DDE to Communicate with Other Windows Applications

--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0

--------------------------------------------------------------------------------


SUMMARY
While Visual Basic offers more powerful, robust and reliable intercommunication between programs with OLE, it still supports the older Dynamic Data Exchange (DDE) technology. You can use DDE to link to and share data between applications.



MORE INFORMATION
Using OLE to communicate with other applications is better than using DDE with Visual Basic. OLE offers you better performance than DDE does.

If a program supports OLE Automation, it exposes an "Object Model" that allows you to manipulate the program through code to perform actions for you.

Dynamic Data Exchange is more useful in communicating with older applications which might not support OLE. Many old 16-bit applications fall into this category.

It is highly recommended that you use OLE rather than DDE when developing your Visual Basic application to communicate with another application



REFERENCES
MSDN contains documentation on DDE methods/properties/events supported within Visual Basic 6.0. In MSDN, set the "Active Subset" to "Visual Basic Documentation," select the "Index" tab, and type in DDE. The topics not grayed out are applicable to Visual Basic 6.0.

In Visual Basic 5.0, select "Books Online" under the "Help" menu. When Books Online appears, select "Index" under the "View" menu. When the Index search browser appears on the left, type in "DDE."
 
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 1

Expert Comment

by:lochiano
Comment Utility
The calling program of A.exe wants to start B.exe with the varables of X=1 and Y=2 and Z=3


''''A.exe''''''''''''''
x = Winexec("B.exe /X:1 /Y:2 /Z:3", SW_SHOWNORMAL)
'''''''''''''''''''''''



''''B.exe'''''''''''''''
sub Main
dim strCMD as string   'this is a local varables that is used to evaluate the incomming stuff.  Remember that the limit of the incomming stuff is 126 characters.


strCMD = command()   'in this example the value is "/X:1 /Y:2 /Z:3" or the contents of the command line options without the program name.


Getglobal strCMD   'calling a local sub to evaluate the passed stuff

''other start up actions

'''''
Sub GetGlobal (strCMD as string)
dim y as integer
dim z as integer


If strCmd = "" Then Exit Sub   'if nothing passed in then do nothing
strCmd = UCase(strCmd) & " "   'make string tests easer


   
Y = InStr(strCmd, "/X:")  'if this variable here?
If Y > 0 Then     'yes it is
    Y = Y + 3       'length of the test
    z = InStr(Y, strCmd, " ") - Y   'is a space at the end
    gintX = val(Mid(strCmd, Y, z))  'The value of the varable is what is in between these spots.
End If

....other stuff...


exit sub

0
 

Author Comment

by:sing_web
Comment Utility
Ruchi :

I have looked at PassString.zip.
What should I do/change/modify if I want at least pass 3 parameters ?
PassString only passes 1 parameter.
0
 
LVL 1

Expert Comment

by:lochiano
Comment Utility
Just keep ading code to the end of the GetGlobal section.  One for each of the paramaters that you need.


repeat this section

     
Y = InStr(strCmd, "/X:")  'if this variable here?
If Y > 0 Then     'yes it is
    Y = Y + 3       'length of the test
    z = InStr(Y, strCmd, " ") - Y   'is a space at the end
    gintX = val(Mid(strCmd, Y, z))  'The value of the varable is what is in between these spots.
End If

0
 

Author Comment

by:sing_web
Comment Utility
lochiano,

Can you put your codes into a vb prog ?
so I can test it and I can understand.
0
 
LVL 1

Expert Comment

by:lochiano
Comment Utility
try this



''''''''''''''''''''''''''''
VERSION 5.00
Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   2220
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4230
   LinkTopic       =   "Form1"
   ScaleHeight     =   2220
   ScaleWidth      =   4230
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox Text1
      Height          =   495
      Index           =   2
      Left            =   1920
      TabIndex        =   3
      Top             =   1560
      Width           =   1815
   End
   Begin VB.TextBox Text1
      Height          =   495
      Index           =   1
      Left            =   1920
      TabIndex        =   2
      Top             =   960
      Width           =   1815
   End
   Begin VB.TextBox Text1
      Height          =   495
      Index           =   0
      Left            =   1920
      TabIndex        =   1
      Top             =   240
      Width           =   1815
   End
   Begin VB.Label Label1
      Caption         =   "Z = "
      Height          =   375
      Index           =   2
      Left            =   720
      TabIndex        =   5
      Top             =   1680
      Width           =   1215
   End
   Begin VB.Label Label1
      Caption         =   "Y = "
      Height          =   375
      Index           =   1
      Left            =   720
      TabIndex        =   4
      Top             =   960
      Width           =   1215
   End
   Begin VB.Label Label1
      Caption         =   "X = "
      Height          =   375
      Index           =   0
      Left            =   720
      TabIndex        =   0
      Top             =   240
      Width           =   1215
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private gintX  As Long
Private gintY As Long
Private gintZ As Long


Private Sub Form_Load()
Dim strCmd As String

strCmd = Command()


'''''''''''''
'this is a good place to add code for testing purposes
'            strcmd = InputBox("Test command line", , "/X:1 /Y:2 /Z:123"))
''''''''''''''''

GetGlobal strCmd
Text1(0).Text = gintX
Text1(1).Text = gintY
Text1(2).Text = gintZ





End Sub
Sub GetGlobal(ByVal strCmd As String)
Dim Y As Long, z As Long


If strCmd = "" Then Exit Sub
strCmd = UCase(strCmd) & " "


 
Y = InStr(strCmd, "/X:")
If Y > 0 Then
    Y = Y + 3
    z = InStr(Y, strCmd, " ") - Y
    gintX = Val(Mid(strCmd, Y, z))
   
End If


 
Y = InStr(strCmd, "/Y:")
If Y > 0 Then
    Y = Y + 3
    z = InStr(Y, strCmd, " ") - Y
    gintY = Val(Mid(strCmd, Y, z))
End If


 
Y = InStr(strCmd, "/Z:")
If Y > 0 Then
    Y = Y + 3
    z = InStr(Y, strCmd, " ") - Y
    gintZ = Val(Mid(strCmd, Y, z))
End If






End Sub

0
 
LVL 13

Expert Comment

by:crazyman
Comment Utility
lochiano is refering to passing parameters when starting an app not passing them between two running apps,which did you want?
0
 
LVL 1

Expert Comment

by:lochiano
Comment Utility
TYhe thing that makes this work is that there is a space in between each of the varables to be passed.  In the case of a name field where you can have a space in the name we use a different ending character.  Normally we use a ":" to mark the end of the test field.  This is what the Z test for

        z = InStr(Y, strCmd, ":") - Y
   
but there is nothing special about that.  Also I listed longs as what is passing.  That can change as well to be what is needed.
0
 

Author Comment

by:sing_web
Comment Utility
I want to pass them between two running
apps, just like PassString.zip
0
 
LVL 1

Expert Comment

by:lochiano
Comment Utility
To do that between two running Apps then you are looking at a DDE call?

0
 
LVL 13

Expert Comment

by:crazyman
Comment Utility
DDE is what i mentioned above :o)
0
 
LVL 1

Expert Comment

by:lochiano
Comment Utility

''''''''''''''''''''''''''''''''''
Set sLnk = New cShellLink                           ' Create ShellLink Instance



   
    Id = 0  ' Get ID from combo box
   x = sLnk.GetSystemFolderPath(Me.hwnd, Id, sfPath)



   sLnk.CreateShellLink sfPath & "\FTW5.lnk", _
                         "c:\ftw5\ftw.exe", _
                         "c:\ftw5", _
                         "", _
                         "C:\ftw5\ftw.exe", _
                    CLng(0), _
                    CLng(1)               ' Create a ShellLink (ShortCut)
   
    Set sLnk = Nothing                                  ' Destroy object reference
''''''''''''''''''''''''''''''''''''''''



This is a sample call.  It an icon on the desktop by calling the program (which is already running).  This uses a class that I can send you if you wish.
0
 

Author Comment

by:sing_web
Comment Utility
But why I don't see any DDE in
PassString.zip vb prog ?
0
 
LVL 1

Expert Comment

by:lochiano
Comment Utility
The PassString.zip copies the information directly into the secondary program.
0
 

Author Comment

by:sing_web
Comment Utility
lochiano :

In PassString.zip, teher is only one
textbox. Do you know how to modify the
codes ? So, I can have more than one
textbox. If yes, I will award the points
to you.
0
 
LVL 1

Expert Comment

by:lochiano
Comment Utility
A simple method would be to add a field name to the beginning of the code and test it with a select statement.


'''''''sending form''''''''''''''''
Private Sub cmdSend_Click()
SendIt Me.txtString

End Sub

Private Sub SendIt(PassedCtl As Control)
Dim sString As String
Dim lHwnd   As Long
Dim cds     As COPYDATASTRUCT
Dim buf(1 To 255) As Byte  'could be make bigger

sString = PassedCtl.Name & "|" & Trim$(PassedCtl)
 {rest if the same}




''''''''''receiving form'''''''''''
Sub pReceiveMsg(lParam As Long)
Dim sString As String
Dim cds     As COPYDATASTRUCT
Dim buf(1 To 255) As Byte
Dim PosOfBar As Long    '  location of the field seporator
'
' Copy the data sent to this application
' into a local structure.
'
Call CopyMemory(cds, ByVal lParam, Len(cds))
'
' Copy the string that was passed into a byte array.
'
Call CopyMemory(buf(1), ByVal cds.lpData, cds.cbData)
'
' Convert the ASCII byte array back to a Unicode string.
'
sString = StrConv(buf, vbUnicode)
sString = Left$(sString, InStr(1, sString, Chr$(0)) - 1)
'
' Display the received string.
'
PosOfBar = InStr(sString, "|")

If PosOfBar = 0 Then
    frmReceive.lblString = sString        'no directed copy was requested
Else
    sName = UCase(Left(sString, PosOfBar + 1))       'Get the name of the sending field
    sString = Right(sString, Len(sString) - PosOfBar)  'get the name out
    Select Case sName
        Case "TXTSTRING"
            frmReceive.lblString = sString
         ' CASE "OTHER FIELD NAMES"
         '  OTHER ACTIONS
    End Select
End If
End Sub



''''''''''''''''''''''''''''''''''''
Another would be to use the copymemory  and ValPtr functions to copy the information into an unknown control.  
0
 
LVL 1

Accepted Solution

by:
csameer1 earned 100 total points
Comment Utility
if you want a KISS (keep it simple stuuu) app,just pass the value thru a text file!!!

or use ini files(GetProfileString)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now