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
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
不行! 请看如下代码。Private Sub as_Click() Form1.Show 1 Debug.Print Form1.Text1.Text End Sub执行后,可以打开Form1,更改text1后,不返回更改后的数值,却返回默认值text1
风马牛不相及,这个和上面说的根本就不是一回事。 你更改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
在各位的提醒下问题基本解决。函数可以完全封装了! 以下代码可以让用户输入一个字符串,关闭窗口(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
我来献丑一下: 用函数来实现阻塞功能 Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)'阻塞函数 private sub subZuSai(byval lngT as long) call Sleep(lngT) '阻塞lngT毫秒 end sub
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
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
请看如下代码。Private Sub as_Click()
Form1.Show 1
Debug.Print Form1.Text1.Text
End Sub执行后,可以打开Form1,更改text1后,不返回更改后的数值,却返回默认值text1
你更改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
以下代码可以让用户输入一个字符串,关闭窗口(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
用函数来实现阻塞功能
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)'阻塞函数
private sub subZuSai(byval lngT as long)
call Sleep(lngT) '阻塞lngT毫秒
end sub
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
我自己的代码不需要全局变量!但理解上困难一点!
Tiger_Zhao的代码最清楚明白!操作简单!得大奖!(区区几分不成敬意!还请笑纳!)