Hello all我的问题是:是否可以从另一个子中提取案例选择数据?我在按钮子中有这个:
'Public Sub btnSearch_Click(sender As Object, e As EventArgs) Handles
btnSearch.Click
Dim strInvalid As String = txtUsername.Text
Dim frmIdenitityCheckerResults As New frmIdenitityCheckerResults()
Select Case True
Case txtUsername.Text = (ReadALine(filename, GetNumberOfLines(filename),
0))
Me.Close()
My.Forms.frmIdenitityCheckerResults.TopLevel = False
My.Forms.FrmWorkTool.Panel2.Controls.Add
(My.Forms.frmIdenitityCheckerResults)
my.Forms.frmIdenitityCheckerResults.Show()
My.Forms.frmIdenitityCheckerResults.Label2.Text = "John"
My.Forms.frmIdenitityCheckerResults.lblSSN.Text = "1211"
My.Forms.frmIdenitityCheckerResults.lblCompany.Text = strPhoenix
My.Forms.frmIdenitityCheckerResults.lblEMP.Text = "1"
My.Forms.frmIdenitityCheckerResults.lblStartDate.Text = "10/10/2017"
Case txtUsername.Text = (ReadALine(filename, GetNumberOfLines(filename), 2))
Me.Close()
My.Forms.frmIdenitityCheckerResults.TopLevel = False
My.Forms.FrmWorkTool.Panel2.Controls.Add
(My.Forms.frmIdenitityCheckerResults)
My.Forms.frmIdenitityCheckerResults.Show()
My.Forms.frmIdenitityCheckerResults.Label2.Text = "Terri"
My.Forms.frmIdenitityCheckerResults.lblSSN.Text = "4218"
My.Forms.frmIdenitityCheckerResults.lblCompany.Text = strPhoenix
My.Forms.frmIdenitityCheckerResults.lblEMP.Text = "2"
My.Forms.frmIdenitityCheckerResults.lblStartDate.Text = "10/10/2017"'
Case txtUsername.Text = (ReadALine(filename, GetNumberOfLines(filename), 1))
Link_lbl1.Text = "John"
Case txtUsername.Text = (ReadALine(filename, GetNumberOfLines(filename), 3)) OrElse
txtUsername.Text = (ReadALine(filename, GetNumberOfLines(filename), 3)) OrElse
txtUsername.Text = (ReadALine(filename, GetNumberOfLines(filename), 3)) OrElse
txtUsername.Text = (ReadALine(filename, GetNumberOfLines(filename), 3))
Link_lbl1.Text = "Terri"
Link_lbl2.Text = "Jordan"
Link_lbl3.Text = "Lisa"
Link_lbl4.Text = "David"
我想从此Select Case中提取数据,以便在下面的代码中输入
Private Sub link_lbl1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles Link_lbl1.LinkClicked
Select Case
Case Link_lbl1.Text = "John"
btnSearch 1
Case Link_lbl1.Text = "Terri"
End Select
End Sub'
但我不确定这是否有可能,如果有人能指出我正确的方向,我将不胜感激。
我试过了:
Select Case link_lbl1.text
Case "John"
但这引发了一个错误,并没有从我以前的案例选择中提取数据。 我可以使用下面的内容工作,但不知道是否有更容易的方法。
Private Sub link_lbl1_LinkClicked(sender As Object, e As
LinkLabelLinkClickedEventArgs) Handles Link_lbl1.LinkClicked
Select Case True
Case Link_lbl1.Text = "John"
Me.Close()
My.Forms.frmIdenitityCheckerResults.TopLevel = False
My.Forms.FrmWorkTool.Panel2.Controls.Add(My.Forms.frmIdenitityCheckerResults)
My.Forms.frmIdenitityCheckerResults.Show()
My.Forms.frmIdenitityCheckerResults.Label2.Text = "John"
My.Forms.frmIdenitityCheckerResults.lblSSN.Text = "1211"
My.Forms.frmIdenitityCheckerResults.lblCompany.Text = strPhoenix
My.Forms.frmIdenitityCheckerResults.lblEMP.Text = "1"
My.Forms.frmIdenitityCheckerResults.lblStartDate.Text = "10/10/2017"
Case Link_lbl1.Text = "Terri"
Me.Close()
My.Forms.frmIdenitityCheckerResults.TopLevel = False
My.Forms.FrmWorkTool.Panel2.Controls.Add(My.Forms.frmIdenitityCheckerResults)
My.Forms.frmIdenitityCheckerResults.Show()
My.Forms.frmIdenitityCheckerResults.Label2.Text = "Terri"
My.Forms.frmIdenitityCheckerResults.lblSSN.Text = "4218"
My.Forms.frmIdenitityCheckerResults.lblCompany.Text = strPhoenix
My.Forms.frmIdenitityCheckerResults.lblEMP.Text = "2"
My.Forms.frmIdenitityCheckerResults.lblStartDate.Text = "10/10/2017"
End Select
End Sub'
答案 0 :(得分:1)
根据建议,您的Select Case
开头是错误的。而不是这个:
Select Case True
Case Link_lbl1.Text = "John"
'...
Case Link_lbl1.Text = "Terri"
'...
End Select
你应该这样做:
Select Case Link_lbl1.Text
Case "John"
'...
Case "Terri"
'...
End Select
关于这个问题,我认为你的意思是你想避免在每个Case
块中重复自己。如果是这样,那么首先要做的是确定什么是常见的,什么是具体的。您可以将公共部分复制到方法中,然后为每个特定部分添加参数,例如
Private Sub DoSomething(label2Text As String, ssn As String, emp As String)
With My.Forms.frmIdenitityCheckerResults
.TopLevel = False
.Show()
.Label2.Text = label2Text
.lblSSN.Text = ssn
.lblCompany.Text = strPhoenix
.lblEMP.Text = emp
.lblStartDate.Text = "10/10/2017"
End With
My.Forms.FrmWorkTool.Panel2.Controls.Add(My.Forms.frmIdenitityCheckerResults)
Me.Close()
End Sub
然后,您可以在每个Case
块中调用该方法,并为每个参数传入适当的值。
请注意,我还使用了With
块来阻止该代码并更正确地重新排序。