vb .Show 多个窗口之间传递值,我有三个窗口,form1,form2,form3,全部窗口如下,按下form按钮进入form1,
我有三个窗口,form1,form2,form3,全部窗口如下,按下form1按钮进入form2,form1代码OptionExplicitDimaaAsNewForm2...
我有三个窗口,form1,form2,form3,
全部窗口如下,
按下form1按钮进入form2,
form1代码
Option Explicit
Dim aa As New Form2
Private Sub Command1_Click()
aa.Show 1, Me
End Sub
form2代码
Option Explicit
Dim bb As New Form3
Private Sub Command1_Click()
bb.Text1.Text = Text1.Text
bb.Show 1, Me
End Sub
Private Sub Form_Initialize()
Text1.Text = "33b"
End Sub
Private Sub Form_load()
Text1.Text = "22a"
End Sub
form3的代码
Option Explicit
Private Sub Command1_Click()
Form2.Text1.Text = Text1.Text
Unload Me
End Sub
运行效果是点form1的按钮后,弹出form2窗口,点form2的按钮后弹出form3窗口,同时,form2的text1传递给form3,在form3窗口中点按钮后,form3的text1的值要再传递回form2的text1中,但是,前面都很顺利,但从form3回传给form2的时候就有问题了,
我检查了一下,在回form2的时候要运行form2的form_load() 展开
全部窗口如下,
按下form1按钮进入form2,
form1代码
Option Explicit
Dim aa As New Form2
Private Sub Command1_Click()
aa.Show 1, Me
End Sub
form2代码
Option Explicit
Dim bb As New Form3
Private Sub Command1_Click()
bb.Text1.Text = Text1.Text
bb.Show 1, Me
End Sub
Private Sub Form_Initialize()
Text1.Text = "33b"
End Sub
Private Sub Form_load()
Text1.Text = "22a"
End Sub
form3的代码
Option Explicit
Private Sub Command1_Click()
Form2.Text1.Text = Text1.Text
Unload Me
End Sub
运行效果是点form1的按钮后,弹出form2窗口,点form2的按钮后弹出form3窗口,同时,form2的text1传递给form3,在form3窗口中点按钮后,form3的text1的值要再传递回form2的text1中,但是,前面都很顺利,但从form3回传给form2的时候就有问题了,
我检查了一下,在回form2的时候要运行form2的form_load() 展开
展开全部
Form1KeyDown,KeyPress,KeyUp事件响应函数,检测按键
面例:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'If KeyCode = vbKey2 Then Form2.Show Else Form3.Show
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
Dim mychar As Byte
'mychar = Chr(KeyAscii)
'If mychar = "2" Then Form2.Show Else Form3.Show
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKey2 And Shift = 1 Then Form2.Show Else Form3.Show
End Sub
面VB帮助KeyDown事件示例代码
打新工程并变量 ShiftKey 添加窗体声明部:
Dim ShiftKey as Integer
Textbox 控件添加窗体并程添加 KeyDown 事件:Private Sub Text1_KeyDown(KeyCode As Integer, _
Shift As Integer)
ShiftKey = Shift And 7
Select Case ShiftKey
Case 1 '或 vbShiftMask Print "You pressed the SHIFT key." Case 2 '或 vbCtrlMask Print "You pressed the CTRL key." Case 4 '或 vbAltMask Print "You pressed the ALT key." Case 3 Print "You pressed both SHIFT and CTRL." Case 5 Print "You pressed both SHIFT and ALT." Case 6 Print "You pressed both CTRL and ALT." Case 7 Print "You pressed SHIFT, CTRL, and ALT." End SelectEnd Sub
面例:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'If KeyCode = vbKey2 Then Form2.Show Else Form3.Show
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
Dim mychar As Byte
'mychar = Chr(KeyAscii)
'If mychar = "2" Then Form2.Show Else Form3.Show
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKey2 And Shift = 1 Then Form2.Show Else Form3.Show
End Sub
面VB帮助KeyDown事件示例代码
打新工程并变量 ShiftKey 添加窗体声明部:
Dim ShiftKey as Integer
Textbox 控件添加窗体并程添加 KeyDown 事件:Private Sub Text1_KeyDown(KeyCode As Integer, _
Shift As Integer)
ShiftKey = Shift And 7
Select Case ShiftKey
Case 1 '或 vbShiftMask Print "You pressed the SHIFT key." Case 2 '或 vbCtrlMask Print "You pressed the CTRL key." Case 4 '或 vbAltMask Print "You pressed the ALT key." Case 3 Print "You pressed both SHIFT and CTRL." Case 5 Print "You pressed both SHIFT and ALT." Case 6 Print "You pressed both CTRL and ALT." Case 7 Print "You pressed SHIFT, CTRL, and ALT." End SelectEnd Sub
追问
大哥,看不懂啊
2019-04-12
展开全部
'VB 的Callbyname 窗体应用
'以下为FORM2的内容
Option Explicit
Private oForm As Object
Private aParam As Variant
'来自的调用的窗体FORM1
'Private Sub Text1_Click()
' Dim aTemp
' 'aTemp = Array("Caption", "Text1.Text")
' aTemp = "Text1.Text"
' If Form2 Is Nothing Then Load Form2
' Form2.getInstance Me, aTemp
' Form2.Show vbModal
'End Sub
Private Sub Command1_Click()
'如果是数组,就对应多个返回值返回组FORM1控件
aParam(0, 1) = Text1.Text
'aParam(1, 1) = Text1.Text
backLetObj oForm, aParam
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Public Function getInstance(ByRef oInForm As Object, ByVal sInParam As Variant)
Dim i&
If IsEmpty(sInParam) Then sInParam = "Caption"
If IsArray(sInParam) Then
If UBound(sInParam) = -1 Then sInParam = Array("Caption")
ReDim aParam(LBound(sInParam) To UBound(sInParam), 0 To 1)
For i = LBound(aParam, 1) To UBound(aParam, 1)
aParam(i, 0) = sInParam(i)
Next i
Else
ReDim aParam(0 To 0, 0 To 1)
aParam(0, 0) = sInParam
End If
Set oForm = oInForm
End Function
Private Sub backLetObj(ByRef oObj As Object, aParam As Variant)
Dim oTemp As Object, aTemp, i&, j&
For i = LBound(aParam, 1) To UBound(aParam, 1)
Set oTemp = oObj
aTemp = Split(aParam(i, 0), ".")
For j = 0 To UBound(aTemp) - 1
Set oTemp = CallByName(oTemp, aTemp(j), VbGet)
Next j
CallByName oTemp, aTemp(UBound(aTemp)), VbLet, CStr(aParam(i, 1))
Erase aTemp
Set oTemp = Nothing
Next i
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set oForm = Nothing
End Sub
'以下为FORM2的内容
Option Explicit
Private oForm As Object
Private aParam As Variant
'来自的调用的窗体FORM1
'Private Sub Text1_Click()
' Dim aTemp
' 'aTemp = Array("Caption", "Text1.Text")
' aTemp = "Text1.Text"
' If Form2 Is Nothing Then Load Form2
' Form2.getInstance Me, aTemp
' Form2.Show vbModal
'End Sub
Private Sub Command1_Click()
'如果是数组,就对应多个返回值返回组FORM1控件
aParam(0, 1) = Text1.Text
'aParam(1, 1) = Text1.Text
backLetObj oForm, aParam
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Public Function getInstance(ByRef oInForm As Object, ByVal sInParam As Variant)
Dim i&
If IsEmpty(sInParam) Then sInParam = "Caption"
If IsArray(sInParam) Then
If UBound(sInParam) = -1 Then sInParam = Array("Caption")
ReDim aParam(LBound(sInParam) To UBound(sInParam), 0 To 1)
For i = LBound(aParam, 1) To UBound(aParam, 1)
aParam(i, 0) = sInParam(i)
Next i
Else
ReDim aParam(0 To 0, 0 To 1)
aParam(0, 0) = sInParam
End If
Set oForm = oInForm
End Function
Private Sub backLetObj(ByRef oObj As Object, aParam As Variant)
Dim oTemp As Object, aTemp, i&, j&
For i = LBound(aParam, 1) To UBound(aParam, 1)
Set oTemp = oObj
aTemp = Split(aParam(i, 0), ".")
For j = 0 To UBound(aTemp) - 1
Set oTemp = CallByName(oTemp, aTemp(j), VbGet)
Next j
CallByName oTemp, aTemp(UBound(aTemp)), VbLet, CStr(aParam(i, 1))
Erase aTemp
Set oTemp = Nothing
Next i
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set oForm = Nothing
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询