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 Variables 1

Status
Not open for further replies.

Rob7

Programmer
Dec 12, 2001
152
US
I have a question about passing variables. I have a situation where the user lands on a text box and this has to pop another screen that the user loads data into.
Private Sub ReceiptQty_GotFocus()
frmNewScreen.Show
End Sub

At this point, the new screen pops up and the user loads data. I also have a command button on this form that writes some of the data off to a file and rehides the screen. There is one piece of data that I want to bring back to the original GotFocus event from this new screen and I cannnot figure out how to get it there.

Thanks

Rob

 
assign a variable to that new data on that form and call it from the other form.

 
The code I tested looked like this

Private Sub ReceiptQty_GotFocus(PlantWt As Long)
Dim PlantWt As Long
If macForm.RejectQty.Text <> &quot;&quot; Then
frmLiveRec.Show

End If

Private Sub cmdEnter_Click(PlantWt As Long)
Dim Trailer As Single
Dim HCRec As Long
Dim PlantWt As Long
Dim FarmWt As Long

Trailer = frmLiveRec.txtTrailer
HCRec = frmLiveRec.txtHCRec
PlantWt = frmLiveRec.txtPlantWt
FarmWt = frmLiveRec.txtFarmWt

Open &quot;c:\RecData.DAT&quot; For Append As #1
Write #1, Trailer, HCRec, PlantWt, FarmWt
Close #1

frmLiveRec.Hide

End Sub

When the code begins, it errors out on the get focus event saying that the Procedure declaration does not match description of event or procedure having the same name.

Rob
 
I susupect you copied and pasted the code from the vb project if so. You have GOT and not GET for the GetFocus function. This could be a problem.
 
Well, this is one of the events. Well, no matter. I can call a Sub that opens the new screen so it looks like:

Private Sub ReceiptQty_GotFocus()
Dim PlantWt As Long
If macForm.RejectQty.Text <> &quot;&quot; Then
Call NewSub(PlantWt)

End If

Public Sub NewSub(PlantWt as long)
frmLiveRec.Show
End Sub

When I do this, the PlantWt never holds the value from the text box in the frmLiveRec.

Rob
 
I think you are passing a string instead of long?
what about pass val(text)
Good luck
 
What you need to do is build a Property Get procedure in the new form, something like this:


'//New form to be shown:
private m_lngPlantWt as long '//This holds the variable you want to have.

... '//Do some very intersting stuff, like asking the user for input or whatever (and assign the result to m_lngPlantWt...).
...


'//The property get proc:
Public Property Get PlantWt() as long
PlantWt = m_lngPlantWt
End Property



'//The original form:
If macForm.RejectQty.Text <> &quot;&quot; Then
dim lngPLantW as long
dim objForm as frmLiveRec

'//Get user input:
objForm.Show vbModal, Me

'//Now get the value you wanted:
lngPLantW = objForm.PlantWt

'//Clean up:
Unload objForm
set objForm = Nothing
End if



Greetings,
Rick
 
Lazyme has the solution. Here is some more information:

You really don't need to use Property Get/Set/Let declarations in 32 bit VB. The compiler builds them for you you. You can just declare
Code:
Dim PlantWt As Long
or
Code:
Public PlantWt As Long
in the Declarations section of a form.

What is tripping you up is that 32 bit Visual Basic has a hidden declaration in it's run-time:
Code:
frmLiveRec As New frmLiveRec
. This means that the every
Code:
frmNewScreen.Show
creates a new instance of the form. By opening the form through a localy declared refence you have a link to the correct form instance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top