I have a function that check validity of inserted data of a form, and in this function I have to ask some confirmation from user, and this confirmation need to be asked outside of the function, so if I hit one of this confirmations, I create the message and send out the validation function, user confirms or not and the function would called again
so here is the problem: I need to put some checkpoints in my function so when I call the validation function I jump to that checkpoint with the selected confirmation from user and run the validation function from that checkpoint
1: is this possible at all?
2: any ideas to do this?
Edit 1: I'm doing this validation in my business layer and can not show any message boxes from there, I just create the message and return it to the UI layer and the answer get from the user and function call again with this answer but I don't want to run the function from beginning and need to run it from where I left
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
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…