在我的代码中假设我有两个表单
在主视图中是DataGridView,它包含一个名为ActivityStatus的列,它显示成员是Stopped还是On-going我有第二个表单,我通过双击一行打开它,它给了我所有成员的详细信息,在表单的底部有一个带有密码的按钮;如果写得正确,它应该切换他的ActivityStatus(如果他已经停止;他会变得持续,反之亦然)这是我为它写的代码
在表格1中:
Private Sub DGVData_CellContentDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles DGVData.CellContentDoubleClick
Dim SV As New -- [FORM 2 NAME HERE]
If e.RowIndex >= 0 Then
Dim Row As DataGridViewRow
Row = DGVData.Rows(e.RowIndex)
SV.ActivityChange = Row.Cells("ActivityStatus").Value.ToString
SV.IDVerify = Row.Cells("ID").Value.ToString
ED.Show()
End If
End Sub
在表格2中:
Public Class StatusVertificationBox
Public Property ActivityChange As String
Public Property IDVerify As String
Private Sub StatusPassBtn_Click(sender As Object, e As EventArgs) Handles StatusPassBtn.Click
If StatusPassTxt.Text = "password123" Then
If ActivityChange = 1 Then
Dim Ask As MsgBoxResult
Ask = MsgBox("Are you sure?", MsgBoxStyle.YesNo)
If Ask = MsgBoxResult.Yes Then
Dim MakeActiveCmd As String = "UPDATE InitialTable " &
"SET ActivityStatus = 0 " &
"WHERE ID='" & IDVerify & "' "
MsgBox("This member's membership has been stopped")
ElseIf Ask = MsgBoxResult.No Then
MsgBox("No modifications have been made")
End If
ElseIf ActivityChange = 0 Then
Dim Ask As MsgBoxResult
Ask = MsgBox("Are you sure?", MsgBoxStyle.YesNo)
If Ask = MsgBoxResult.Yes Then
Dim MakeInactiveCmd As String = "UPDATE InitialTable " &
"SET ActivityStatus = 1 " &
"WHERE ID='" & IDVerify & "' "
MsgBox("This member's membership has been renewed")
ElseIf Ask = MsgBoxResult.No Then
MsgBox("No modifications have been made")
End If
End If
Me.Close()
Else
MsgBox("Incorrect Password, please try again.")
StatusPassTxt.Clear()
End If
End Sub
我不明白问题在哪里。IF语句不能正常工作(MsgBox上显示的文本与语句不匹配,并且datagridview上的值根本没有改变)
任何帮助将非常感激,感谢阅读的家伙
EDIT:从代码中修复了一些东西,我不正确地复制了它,因为我编辑了一些东西以使你们更容易理解,这使我错过了一些代码
EDIT2:我注意到它总是跟随我放在它上面的最后一个IF语句。它总是遵循如果ActivityChange = 0,即使(根据它显示的方式)它应该显示为1..我还是不知道怎么解决
EDIT:
变量ActivityChange
的类型为String。因此比较应该是:
If StrComp(ActivityChange, "1") = 0 Then
...