PDA

Click to See Complete Forum and Search --> : Why can't I pass a string variable from form1 to form2 in the attached code???


Al Smith
Jan 23rd, 2000, 04:25 AM
Hi.
What am I doing wrong. I can pass the strings to Form2 if I refer to the strings as Form1.string. But Form2 will also need to process data from other forms, e.g. Form3.
Form2 has a winsock control to send the data to an E-mail address.

Form1: optSelect is the string I'm trying to pass without the Form1. prefix. It's the description of which option button was selected.


Public txtTo As String
Public txtMsg As String
Public txtSubject As String
Public txtCC As String
Public optSelect As String


Sub cmdSend_Click(Index As Integer)
If optSelect = "" Then
MsgBox ("You must select a discrepancy type.")
Exit Sub
End If
Form2.Show
End Sub

Sub optDiscr_Click(Index As Integer)
If optDiscr(0).Value = True Then
optSelect = "Discrepancy Report - Transfer"
ElseIf optDiscr(1).Value = True Then
optSelect = "Discrepancy Report - Inventory Level"
ElseIf optDiscr(2).Value = True Then
optSelect = "Discrepancy Report - Replenishment"
ElseIf optDiscr(3).Value = True Then
optSelect = "Discrepancy Report - Core Returns"
ElseIf optDiscr(4).Value = True Then
optSelect = "Discrepancy Report - New Defective"
ElseIf optDiscr(5).Value = True Then
optSelect = "Discrepancy Report - Other"
End If
End Sub

Sub txtWhse_Change()
txtWhse.Text = UCase(txtWhse.Text)
End Sub



Form2: All the strings prefaced with Form1. come through ok. The string optSelect doesn't. It shows "Empty" when running in Debug.


Sub Form_Load()
txtTo = "asmith@spxateg.com"
txtMsg = "Whse " & Form1.txtWhse & vbCrLf & _
"Name " & Form1.txtName & vbCrLf & vbCrLf & _
"Item " & Form1.txtPart & vbCrLf & vbCrLf & _
"Discrepancy" & vbCrLf & Form1.txtDisc
txtSubject = optSelect
Text1.Text = txtSubject & vbCrLf & _
"To: " & txtTo & vbCrLf & _
txtMsg
End Sub


Again, as always

Thanks,
Al.



------------------
A computer is a tool, not a toy.
<A HREF="mailto:asmith3914@aol.com
asmith@spxateg.com">asmith3914@aol.com
asmith@spxateg.com</A>

DiGiTaIErRoR
Jan 23rd, 2000, 05:10 AM
strings are only stored in the sub in which they were defined
visual basic sucks... use a label


------------------
DiGiTaIErRoR

Civil78
Jan 23rd, 2000, 05:16 AM
Put the string variable to a module as public

Public StringName as String

bye

Al Smith
Jan 23rd, 2000, 05:53 AM
Civil78,
Thank you.
Simply moving the declarations to a module works perfectly.
Again, Thank you.
Al.


------------------
A computer is a tool, not a toy.
<A HREF="mailto:asmith3914@aol.com
asmith@spxateg.com">asmith3914@aol.com
asmith@spxateg.com</A>