Results 1 to 4 of 4

Thread: Why can't I pass a string variable from form1 to form2 in the attached code???

  1. #1

    Thread Starter
    Hyperactive Member Al Smith's Avatar
    Join Date
    May 1999
    Location
    Marcellus, MI. USA
    Posts
    330

    Post

    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.

    Code:
    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.

    Code:
    Sub Form_Load()
    txtTo = "[email protected]"
    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:[email protected]
    [email protected]">[email protected]
    [email protected]</A>


  2. #2
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111

    Post

    strings are only stored in the sub in which they were defined
    visual basic sucks... use a label


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

  3. #3
    Lively Member
    Join Date
    Jan 2000
    Location
    Thessaloniki ,Greece
    Posts
    100

    Post

    Put the string variable to a module as public

    Public StringName as String

    bye

  4. #4

    Thread Starter
    Hyperactive Member Al Smith's Avatar
    Join Date
    May 1999
    Location
    Marcellus, MI. USA
    Posts
    330

    Post

    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:[email protected]
    [email protected]">[email protected]
    [email protected]</A>


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width