[RESOLVED] Variable Sent To Other VB6 Project?
I need to know how to get my first project to send another one of my projects a value, eg: Item1 = "1". That is only if the project is sending the value. But if the project isn't sending the value. My second project will be reading Item1 as "0" instead of "1".
Re: Variable Sent To Other VB6 Project?
TheEmp.
there are many ways.
you can use a common registry value to exchange data between your app.
for example :
Registry
-Projects of TheEmp
-- Project 1 Key
-- Project 2 Key
-- A common value use to exchange data.
(so both programs use this location to exchange data.)
Re: Variable Sent To Other VB6 Project?
How about an INI or CFG file?
Re: Variable Sent To Other VB6 Project?
Quote:
Originally Posted by ThEiMp
How about an INI or CFG file?
yah yah that will also ok. many ways.
you can also use sendmessage to post the data to your other app (to a hiden text box).
sendMessage windowHandle,wm_settext, 0&, "Hai app"
:wave:
Re: Variable Sent To Other VB6 Project?
Quote:
Originally Posted by Fazi
TheEmp.
there are many ways.
you can use a common registry value to exchange data between your app.
yeah, One way I do it (instead of using DDE) is to use the registry to hold the window handle of a textbox and use SendMessage to send data to it, when the textbox receives something its change event fires and the program knows it has new incoming data form the other program.
Re: Variable Sent To Other VB6 Project?
Could you please send some source code showing that, particular demostration that you are talking about?
Re: Variable Sent To Other VB6 Project?
Quote:
Originally Posted by ThEiMp
Could you please send some source code showing that, particular demostration that you are talking about?
' Receiver Program....
Code:
' // Receive value from other program //
' * Add a textbox to the Form and name it "txtRcv"
Option Explicit
Private Sub Form_Load()
' hide the textbox so users can't enter data into it!
txtRcv.Visible = False
' save textbox handle to registry.
SaveSetting "MyCompanyName", "MyProgramName", "ClientRcv", txtRcv.hWnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
' reset registry to zero for added handle.
SaveSetting "MyCompanyName", "MyProgramName", "ClientRcv", 0
End Sub
Private Sub txtRcv_Change()
' - incoming data text box -
Dim IncomingValue As Double
If Len(txtRcv.Text) = 0 Then Exit Sub
IncomingValue = CDbl(txtRcv.Text) ' convert incoming text to a double type value.
txtRcv.Text = ""
' do something with the value received.
MsgBox "Incoming Value = " & IncomingValue
'Call MySub(IncomingValue)
End Sub
' Sender Program....
Code:
Option Explicit
Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Const WM_SETTEXT = &HC
Private Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Command1_Click()
' Send a value to our other (receiving) program.
Dim Dest_Hwnd As Long
Dest_Hwnd = GetSetting("MyCompanyName", "MyProgramName", "ClientRcv", 0)
If IsWindow(Dest_Hwnd) = 1 Then ' if textbox found then send text to it
SendMessageByString Dest_Hwnd, WM_SETTEXT, 0, "1234567.89" ' send value as text
Else
MsgBox "Error: Handle not found!"
End If
End Sub
Re: Variable Sent To Other VB6 Project?
Thanks for that, EdgeMeal!!