【发布时间】:2017-09-26 11:31:16
【问题描述】:
我有一个检查表单插入数据有效性的功能,在这个功能中我必须要求用户进行一些确认,并且需要在功能之外询问这个确认,所以如果我点击其中一个确认,我创建消息并发送验证函数,用户确认与否,该函数将再次调用
所以问题出在这里:我需要在我的函数中放置一些检查点,所以当我调用验证函数时,我会根据用户选择的确认跳转到该检查点并从该检查点运行验证函数
1:这可能吗?
2:有什么想法吗?
编辑 1:我正在我的业务层中进行此验证,并且无法从那里显示任何消息框,我只是创建消息并将其返回到 UI 层,然后从用户和函数调用中再次获得答案这个答案,但我不想从头开始运行该功能,需要从我离开的地方运行它
Public Class BL
Private Queue As Queue(Of String)
Public Sub New()
Dim checkpoints = New String(){"CheckPoint1","CheckPoint2","CheckPoint3"}
checkpoints.ToList.ForEach(Function(item) <b>Queue.Enqueue(item)</b>)
End Sub
Public Function Func(ByVal res As Response,ParamArray ByVal params As String()) As Response
Dim response As Response
Dim chk = Queue.Dequeue()
GoTo chk
CheckPoint1:
'Do some stuff
response = New Response(Response.ResponseType.Message,"Are you sure you wanna do this?")
Return response
CheckPoint2:
If(res.Type = Response.ResponseType.ResponseBack)
Dim r As DialogResult = Convert.ChangeType([Enum].Parse(GetType(DialogResult),res.Message),GetType(DialogResult))
If (r= DialogResult.OK)
'Do stuffs on DialogResult.Yes
Else
'Do stuffs on DialogResult.No
End If
'Do other stuffs with database
End If
' Do other stuff
response = New Response(Response.ResponseType.Message,"You should do this!!OK?")
Return response
CheckPoint3:
'Do stuff like CheckPoint1
End Function
End Class
Public Class Response
Friend Enum ResponseType
Message
Result
ResponseBack
None
End Enum
Friend Message As String
Friend Type As ResponseType
Friend Sub New(ByVal type As ResponseType,msg As String)
Message=msg
Type= type
End Sub
End Class
Public Class Form1
Public Sub New()
' This call is required by the designer.
InitializeComponent()
Dim BL As New BL()
' Add any initialization after the InitializeComponent() call.
Dim rese As Response
Do
rese =BL.Func(Nothing)
BL.Func(new Response(Response.ResponseType.ResponseBack,if(MessageBox.Show(rese.Message).ToString())))
Loop Until rese.Type <> Response.ResponseType.Result
MessageBox.Show(if(rese.Message="True","OK","ERROR"))
End Sub
End Class
【问题讨论】:
-
@ParrishHusband 我需要从函数中返回,做一些事情并再次调用它,我怎样才能用一个while循环来做到这一点?
-
我读到的问题有点不同,所以忽略我最初的 While 循环评论。您能否更具体地说明您正在验证的内容以及该功能应该做什么?
-
@ParrishHusband 我刚刚编辑了我的问题!!