窗体2中有一个listview ,我选择了其中的几行,并将结果保存到公用变量里了。
现在我想要在窗体2关闭之后,将这个公用变量的结果返回给窗体1的textbox1.
但是我发现总是先textbox1.text=bomstr再FrmBomList.Show,
这个textbox1的text总是空的,要如何取到窗体2中的值(bomstr)?还是我的哪里不对?
Private Sub getBomInfo()
Dim bomlist As FrmBomList
FrmBomList.Show
textbox1.text=bomstr
END SUB
窗体2中
Public bomstr As String
Private Sub Command2_Click()
bomstr = ""
If ListView1.ListItems.Count < 1 Then
Dim i As Integer
i = MsgBox("此Part无信息,请确认", 16, "提示") '消息框提示
Else
Dim PartInfo As String
PartInfo = ""
For i = 0 To ListView1.ListItems.Count - 1
'If ListView1.ListItems(I + 1).Checked = True Then
If ListView1.ListItems.Item(i + 1).Checked = True Then
PartInfo = PartInfo + CStr(ListView1.ListItems(i + 1).SubItems(1)) + "," 'i+1为定义的行数
End If
'I = I + 1
Next
If Len(PartInfo) >= 1 Then
Text1.Text = Mid(PartInfo, 1, Len(PartInfo) - 1)
bomstr = Text1.Text
End If
End If
End Sub
11 个解决方案
#1
FrmBomList.Show 1
#2
谢谢楼上的大神回复,这个方法我也试过了,这也是先赋值,然后再将 frm2弹出的,在frm里面选择数据还是影响不了frm1的结果
#3
你建一个moudle,建一个全局变量就是了
#4
不好意思,写错了,是建一个module
#5
在Form2 中 加 一条 form1.text1.text=bomstr
#6
在From2 的 command2事件中 最后 加一条:From1.Text1.text=bomstr 应该就可以
#7
http://zhidao.baidu.com/question/140287908.html
http://zhidao.baidu.com/question/55286693.html
http://zhidao.baidu.com/question/96503971.html
http://zhidao.baidu.com/question/55286693.html
http://zhidao.baidu.com/question/96503971.html
#8
多谢版主大手的热心帮忙,不过我的问题可能有一些不同。是这样的,我这两段代码实际上金蝶的K3二次开发里面的东东,这个窗口实际上是要在一个控件上调用出来,所以也不能用show 1,me这样。但是,如果不这样调,他会直接先执行完show后面的代码,再弹出我需要show的这个frm.....
#9
'Form1
Option Explicit
Public Property Let bomstr(ByVal RHS As String)
textbox1.Text = RHS
End Property
Private Sub getBomInfo()
FrmBomList.Action Me
End Sub
'FrmBomList
Option Explicit
Private m_OwnerForm As Form1
Public Sub Action(ByVal OwnerForm As Form1)
Set m_OwnerForm = OwnerForm
m_OwnerForm.bomstr = ""
Me.Show , OwnerForm
End Sub
Private Sub Command2_Click()
If ListView1.ListItems.Count < 1 Then
Dim i As Integer
i = MsgBox("此Part无信息,请确认", 16, "提示") '消息框提示'
Else
Dim PartInfo As String
PartInfo = ""
For i = 0 To ListView1.ListItems.Count - 1
'If ListView1.ListItems(I + 1).Checked = True Then
If ListView1.ListItems.Item(i + 1).Checked = True Then
PartInfo = PartInfo + CStr(ListView1.ListItems(i + 1).SubItems(1)) + "," 'i+1为定义的行数'
End If
'I = I + 1
Next
If Len(PartInfo) >= 1 Then
Text1.Text = Mid(PartInfo, 1, Len(PartInfo) - 1)
m_OwnerForm.bomstr = Text1.Text
End If
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set m_OwnerForm = Nothing
End Sub
#10
Form1
Private Sub Command1_Click()
Form2.Show 1
End Sub
Private Sub Command1_Click()
'strSelectedName = ""
If ListView1.ListItems.Count < 1 Then
Dim i As Integer
i = MsgBox("此Part无信息,请确认", 16, "提示") '消息框提示
Else
Dim PartInfo As String
PartInfo = ""
For i = 0 To ListView1.ListItems.Count - 1
'If ListView1.ListItems(I + 1).Checked = True Then
If ListView1.ListItems.Item(i + 1).Checked = True Then
'PartInfo = PartInfo + CStr(ListView1.ListItems(i + 1).SubItems(1)) + "," 'i+1为定义的行数
PartInfo = PartInfo + ListView1.ListItems(i + 1).Text + ","
End If
'I = I + 1
Next
If Len(PartInfo) >= 1 Then
'Text1.Text = Mid(PartInfo, 1, Len(PartInfo) - 1)
'bomstr = Text1.Text
Form1.Text1.Text = PartInfo
End If
End If
Unload Me
End Sub
Private Sub Form_Load()
For i = 1 To 10
Me.ListView1.ListItems.Add i, "A" + CStr(i), "Boss" + CStr(i)
Next i
End Sub
#11
后面的一段代码是在Form2.
#1
FrmBomList.Show 1
#2
谢谢楼上的大神回复,这个方法我也试过了,这也是先赋值,然后再将 frm2弹出的,在frm里面选择数据还是影响不了frm1的结果
#3
你建一个moudle,建一个全局变量就是了
#4
不好意思,写错了,是建一个module
#5
在Form2 中 加 一条 form1.text1.text=bomstr
#6
在From2 的 command2事件中 最后 加一条:From1.Text1.text=bomstr 应该就可以
#7
http://zhidao.baidu.com/question/140287908.html
http://zhidao.baidu.com/question/55286693.html
http://zhidao.baidu.com/question/96503971.html
http://zhidao.baidu.com/question/55286693.html
http://zhidao.baidu.com/question/96503971.html
#8
多谢版主大手的热心帮忙,不过我的问题可能有一些不同。是这样的,我这两段代码实际上金蝶的K3二次开发里面的东东,这个窗口实际上是要在一个控件上调用出来,所以也不能用show 1,me这样。但是,如果不这样调,他会直接先执行完show后面的代码,再弹出我需要show的这个frm.....
#9
'Form1
Option Explicit
Public Property Let bomstr(ByVal RHS As String)
textbox1.Text = RHS
End Property
Private Sub getBomInfo()
FrmBomList.Action Me
End Sub
'FrmBomList
Option Explicit
Private m_OwnerForm As Form1
Public Sub Action(ByVal OwnerForm As Form1)
Set m_OwnerForm = OwnerForm
m_OwnerForm.bomstr = ""
Me.Show , OwnerForm
End Sub
Private Sub Command2_Click()
If ListView1.ListItems.Count < 1 Then
Dim i As Integer
i = MsgBox("此Part无信息,请确认", 16, "提示") '消息框提示'
Else
Dim PartInfo As String
PartInfo = ""
For i = 0 To ListView1.ListItems.Count - 1
'If ListView1.ListItems(I + 1).Checked = True Then
If ListView1.ListItems.Item(i + 1).Checked = True Then
PartInfo = PartInfo + CStr(ListView1.ListItems(i + 1).SubItems(1)) + "," 'i+1为定义的行数'
End If
'I = I + 1
Next
If Len(PartInfo) >= 1 Then
Text1.Text = Mid(PartInfo, 1, Len(PartInfo) - 1)
m_OwnerForm.bomstr = Text1.Text
End If
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set m_OwnerForm = Nothing
End Sub
#10
Form1
Private Sub Command1_Click()
Form2.Show 1
End Sub
Private Sub Command1_Click()
'strSelectedName = ""
If ListView1.ListItems.Count < 1 Then
Dim i As Integer
i = MsgBox("此Part无信息,请确认", 16, "提示") '消息框提示
Else
Dim PartInfo As String
PartInfo = ""
For i = 0 To ListView1.ListItems.Count - 1
'If ListView1.ListItems(I + 1).Checked = True Then
If ListView1.ListItems.Item(i + 1).Checked = True Then
'PartInfo = PartInfo + CStr(ListView1.ListItems(i + 1).SubItems(1)) + "," 'i+1为定义的行数
PartInfo = PartInfo + ListView1.ListItems(i + 1).Text + ","
End If
'I = I + 1
Next
If Len(PartInfo) >= 1 Then
'Text1.Text = Mid(PartInfo, 1, Len(PartInfo) - 1)
'bomstr = Text1.Text
Form1.Text1.Text = PartInfo
End If
End If
Unload Me
End Sub
Private Sub Form_Load()
For i = 1 To 10
Me.ListView1.ListItems.Add i, "A" + CStr(i), "Boss" + CStr(i)
Next i
End Sub
#11
后面的一段代码是在Form2.