function form2_text_value() as string
form2.show
form2_text_value = form2.a.text
end functionsub form1_load()
...
dim temp as string 
temp = form2_text_value()
...
end sub
现在有2个form,一个form1,一个form2,在form2中有一个名为a的text框。
现在在模块里写个函数form2_text_value,内容如上,用来返回form2这个text框的输入值,
然后再form1里面,调用这个函数form2_text_value。请问怎么才能使temp的值不为空,就是说form2的这个text框必须输入东西,否则焦点就停留在form2的这个text框上,程序也不往下运行,直到输入东西之后,程序才运行,form2里应该怎么写

解决方案 »

  1.   

    'Module1
    function form2_text_value() as string
        form2.show vbmodal
        form2_text_value = form2.a.text
        unload form2
    end function'Form2
    private sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        If LenB(a.Text) <> 0 Then
            Cancel = True 'a中有值,用Hide结束模态显示以保留a中的值
            Me.Hide
        Else
            Cancel = True 'a中无值,继续输入
        End If
    end sub
      

  2.   

    VB6 Code:'Form2的窗体模块:Private Sub a_KeyPress(KeyAscii As Integer) 
            If KeyAscii=13 Then '文本框a中输入完毕后按回车键 
               temp=a.text  
            End If 
    End Sub'用不着定义函数form2_text_value 
      

  3.   

    'Module1
    Public flag As Boolean
    function form2_text_value() as string
        form2.show vbmodal
        form2_text_value = form2.a.text
        unload form2
    end function'Form2
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        If Not flag Then
            If LenB(a.Text) <> 0 Then
                Cancel = True 'a中有值,用Hide结束模态显示以保留a中的值
                Me.Hide
                flag = True
            Else
                Cancel = True 'a中无值,继续输入
            End If
        End If
    End Sub
      

  4.   

    If a.Text = "" Then
    a.SetFocusElse: 程序往下走
    End If记得给分啊,我没有分了,谢谢!
      

  5.   

    'Module1
    function form2_text_value() as string
        form2.show vbmodal
        form2_text_value = form2.a.text
        unload form2
    end function'Form2
    private sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        If LenB(a.Text) <> 0 Then
            Cancel = True 'a中有值,用Hide结束模态显示以保留a中的值
            Me.Hide
        Else
            Cancel = True 'a中无值,继续输入
        End If
    end sub