写某个函数时,要求强出某个对话框,让用户选择值,就象msgbox,

strA = GetSelect
其中,GetSelect函数要求用户在自写的对话框中选择某条件,在选择未完成时,不能让程序继续执行。自己用了很多方法,有的实现了,但极不理想。请高手指教。

解决方案 »

  1.   

    Private Sub Form_Unload(Cancel As Integer)
        If Not fun_Judge Then
            Exit Sub
        End If
        
        ……
            
    End SubPrivate Sub oCmdCancel_Click()
        If Not fun_Judge Then
            Exit Sub
        End If
        
        ……
        
    End SubPrivate Sub oCmdOK_Click()
        If Not fun_Judge Then
            Exit Sub
        End If
        
        ……
        
    End SubPrivate Function fun_Judge() As Boolean
        
    End Function
      

  2.   

    Private Sub Form_Unload(Cancel As Integer)
        If Not fun_Judge Then
            Cancel = 1
            Exit Sub
        End If
        
    '    ……
            
    End SubPrivate Sub oCmdCancel_Click()
        If Not fun_Judge Then
            Exit Sub
        End If
        
    '    ……
        
    End SubPrivate Sub oCmdOK_Click()
        If Not fun_Judge Then
            Exit Sub
        End If
        
    '    ……
        
    End SubPrivate Function fun_Judge() As Boolean
        
    End Function
      

  3.   

    不行!
    请看如下代码。Private Sub as_Click()
          Form1.Show 1
          Debug.Print Form1.Text1.Text
    End Sub执行后,可以打开Form1,更改text1后,不返回更改后的数值,却返回默认值text1
      

  4.   

    风马牛不相及,这个和上面说的根本就不是一回事。
    你更改text1的代码是怎么写的?form1关闭了值就没有了,当然出错public strMy as stringPrivate Sub as_Click() 
          Form1.Show 1 
          Debug.Print strMy 
    End Sub 
    form1:
    Private Sub oCmdOK_Click()
        If Not fun_Judge Then
            Exit Sub
        End If
        
        strMy=text1.text
    '    ……
        
    End Sub
      

  5.   

    呵呵!意思是用全局变量啊!在选择的时候将数值写入全局变量,很不错,可这种方法我也用过。还有用timer的,问题我想实现msgbox那种,函数就是函数,用起来的时候直接调用就可以了。
      

  6.   

    在各位的提醒下问题基本解决。函数可以完全封装了!
    以下代码可以让用户输入一个字符串,关闭窗口(inputbox更好,不过只是演示个原理)form2中:
    Option ExplicitPublic Function GetText() As String
          Dim a As New Form1
          Dim b As New Form1      Set a.AttMe = b
          a.Show 1
          GetText = b.Value
          
          Unload b
          Set a = Nothing
          Set b = Nothing
    End FunctionPrivate Sub as_Click()
          Debug.Print GetText
    End Subform1中:
    Option Explicit
    Public Value As String
    Public AttMe As Form1Private Sub Text1_Change()
           AttMe.Value = Text1.Text
    End Sub
      

  7.   

    我来献丑一下:
    用函数来实现阻塞功能
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)'阻塞函数
    private sub subZuSai(byval lngT as long)
        call Sleep(lngT) '阻塞lngT毫秒
    end sub
      

  8.   

    直接将函数写在窗体中,看我的回复
    http://topic.csdn.net/u/20080625/09/a5060268-854f-482e-a224-2ba6bb4a7620.html
    http://topic.csdn.net/u/20081205/13/ff73ac67-536a-4536-9f0e-8055fa36427f.html
      

  9.   

    Tiger_Zhao厉害,唉!思路不如人啦!看来我对模式窗体的理解不够!jhone99的代码最简最明白,但需要全局变量,无法封装成函数!
    我自己的代码不需要全局变量!但理解上困难一点!
    Tiger_Zhao的代码最清楚明白!操作简单!得大奖!(区区几分不成敬意!还请笑纳!)