不太理解,各种参数我还不会灵活使用。
module里是:
Public Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 46 And InStr(1, aaaa.Text1.Text, ".") > 0 Then '这里把我难住了。。。。。
KeyAscii = 0
End If
End Sub
不太理解,module里怎会有事件?
Public Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 46 And InStr(1, aaaa.Text1.Text, ".") > 0 Then '这里把我难住了。。。。。
KeyAscii = 0
End If
End Sub
-------------------------------------------------------
通常要跨表单透过模块进行控件项操作,我都是直接把表单当参数传递给模块,再进行操作。
Public Sub AAA(A1 as Form,B1 as Integer)
A1.XXX=??? 'A1看你是从哪个表单传来的,就是那个表单的东西。
End Sub
-------------------------------------------------------
呼叫使用的时候再:
1.Form1 -> Call AAA(Form1,1)
2.Form2 -> Call AAA(Form2.2)
.....
-------------------------------------------------------
不过个人不建议把表单动作写在模块内,后续会很麻烦。
那你用函数吧。
----------Module 的代码----------
Public Function TextKeyCheck(objtext As TextBox, KeyAscii As Integer) As Integer
'传二个参数进来,第一个是 文本框,第二个是 按键值
TextKeyCheck = KeyAscii '默认等于 原始值
If TextKeyCheck = 46 And InStr(1, objtext.Text, ".") > 0 Then '如果符合取消的条件
TextKeyCheck = 0 '置 0
End If
End Function
---------窗体中的代码--------------
Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = TextKeyCheck(Text1,Keyascii)
End Sub
==========================================================
还有一种写法,就借助VB6 过程(函数)的参数默认是按地址传递,那就直接修改值就可以了,不需要 使用函数的调用方法。
--------Module中的代码------------
Public Function TextKeyCheck(objtext As TextBox, ByRef KeyAscii As Integer) As Integer
'传二个参数进来,第一个是 文本框,第二个是 按键值 ,按键值,显式指定为按地址传递,方便理解
If KeyAscii = 46 And InStr(1, objtext.Text, ".") > 0 Then '如果符合取消的条件
KeyAscii = 0 '置 0
End If
End Function
---------窗体中的代码--------------
Private Sub Text1_KeyPress(KeyAscii As Integer)
call TextKeyCheck(Text1,Keyascii)
End Sub