Implement Backtracking in Visual basic

how can i implement backtracking in a Visual Basic program.
give answar with example
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

what do you mean in backtracking , is it something from linear programming ,or backtracking trace???

Mike TomlinsonMiddle School Assistant TeacherCommented:
One way is to use a stack.  You simply push your current position onto the stack each time you move.  If you need to backtrack then you simply start popping values off the stack.

Here is an example of a collection being used as a stack.  Create a project and add two listboxes and a commandbutton.  Run the app and push the button.  The first listbox will show you the order the items went into the box.  The second listbox will show the order of the items as they come out of the stack...which should be in the reverse order.

Option Explicit

Private stack As New Collection

Private Sub Command1_Click()
    Dim i As Integer
    For i = 1 To 10
        stackPush (i)
        List1.AddItem i
    Next i
    While stackCount() > 0
        List2.AddItem stackPop
End Sub

Private Sub stackPush(ByVal newValue As Variant)
    If stack.Count > 0 Then
        stack.Add newValue, , 1
        stack.Add newValue
    End If
End Sub

Private Function stackPop() As Variant
    If stack.Count > 0 Then
        stackPop = stack.Item(1)
        stack.Remove (1)
        MsgBox "Stack is Empty", vbCritical, "Error"
    End If
End Function

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike TomlinsonMiddle School Assistant TeacherCommented:
Sorry, I lost a "." in there somehow...

It should be:

    While stack.Count() > 0
        List2.AddItem stackPop

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Game Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.