undo button?

noob82

Member
Joined
Apr 20, 2010
Messages
6
Programming Experience
Beginner
hey guys one question for you.. i have created a flight booking application for my assignment. to complete it i need to create an undo button.. any ideas on how i can do it? cheers!
 
Do you actually think there is enough info there to even get a response? Besides this one =)
 
thanx for the reply lol right basically i have coded a simple flight booking application on vb.net. what i need to achieve is a button called undo that undoes a previous selection in tghe drop down boxes i have created.. hope that helps =)
 
Nope, try again. Add things like; here is the code I have so far, I am using a <blank> to store stuff, these are my errors (if any), etc...
 
thats the thing i have no clue with the undo button
VB.NET:
 Public Class Form1

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
       

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        End
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
   
    End Sub

    Private Sub ListBox1_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
        
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ComboBox1.Items.Add("Manchester")
        ComboBox1.Items.Add("Liverpool")
        ComboBox1.Items.Add("Newcastle")
        ComboBox1.Items.Add("Leeds")
        ComboBox1.Items.Add("Cardiff")
        ComboBox1.Items.Add("London")

        ComboBox2.Items.Add("Washington D.C")
        ComboBox2.Items.Add("Alicante")
        ComboBox2.Items.Add("Rome")
        ComboBox2.Items.Add("Palma")
        ComboBox2.Items.Add("Paris")
        ComboBox2.Items.Add("Barcelona")

        ComboBox3.Items.Add("1")
        ComboBox3.Items.Add("2")
        ComboBox3.Items.Add("3")
        ComboBox3.Items.Add("4")
        ComboBox3.Items.Add("5")

        ComboBox4.Items.Add("0")
        ComboBox4.Items.Add("1")
        ComboBox4.Items.Add("2")
        ComboBox4.Items.Add("3")
        ComboBox4.Items.Add("4")
        ComboBox4.Items.Add("5")

        ComboBox5.Items.Add("0")
        ComboBox5.Items.Add("1")
        ComboBox5.Items.Add("2")
        ComboBox5.Items.Add("3")
        ComboBox5.Items.Add("4")
        ComboBox5.Items.Add("5")

    End Sub

    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged

    End Sub

    Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged

    End Sub

    Private Sub ComboBox4_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox4.SelectedIndexChanged

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        ComboBox1.Text = ""
        ComboBox2.Text = ""
        ComboBox3.Text = ""
        ComboBox4.Text = ""
        ComboBox5.Text = ""
        TextBox1.Text = ""


    End Sub
  
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

    End Sub

    Private Sub ListBox1_SelectedIndexChanged_2(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If ComboBox2.Text = "Alicante" Then
            TextBox1.Text = (ComboBox3.Text * 300) + (ComboBox4.Text * 150) + (ComboBox5.Text * 100)
        End If
        If ComboBox2.Text = "Rome" Then
            TextBox1.Text = (ComboBox3.Text * 400) + (ComboBox4.Text * 200) + (ComboBox5.Text * 150)
        End If
        If ComboBox2.Text = "Palma" Then
            TextBox1.Text = (ComboBox3.Text * 280) + (ComboBox4.Text * 190) + (ComboBox5.Text * 160)
        End If
        If ComboBox2.Text = "Paris" Then
            TextBox1.Text = (ComboBox3.Text * 280) + (ComboBox4.Text * 190) + (ComboBox5.Text * 160)
        End If
        If ComboBox2.Text = "Washington D.C" Then
            TextBox1.Text = (ComboBox3.Text * 480) + (ComboBox4.Text * 290) + (ComboBox5.Text * 190)
        End If
        If ComboBox2.Text = "Barcelona" Then
            TextBox1.Text = (ComboBox3.Text * 380) + (ComboBox4.Text * 200) + (ComboBox5.Text * 190)
        End If

    End Sub
   

    Private Sub TextBox1_TextChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click

    End Sub
End Class
here is what i have so far tho.. im a total newb to visual basic
 
VB.NET:
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

    End Sub
that is where i need to put the undo button
 
For a better experience later; name things something useful - btnUndo, cbCity, etc... If you mean when you select an item from a combobox you want it to go back to empty then set it's selected index to -1. Items in controls like these are 0 based so 0 is the first and -1 is none selected.
 
how could i code that right? sorry to ask but i have come this far but am yet to find solution.. its due in tomorrow too.. =S thanx for replying tho
 
VB.NET:
combobox1.SelectedIndex = -1

When your typing in the editor intellisence will show you the available properties to controls, and there is a useful notation as to what is does.
 
thanx for the reply.. i have 5 combo boxes.. how could i code it so that the combobox i have just left undo that one without clearing the rest of them..?? do appreciate your help tho
 
thanx for the reply.. i have 5 combo boxes.. how could i code it so that the combobox i have just left undo that one without clearing the rest of them..?? do appreciate your help tho

I'd recommend declaring two variables at the top of your Form1 class.

VB.NET:
    Dim comboLastComboBoxTouched As ComboBox
    Dim intLastValue As Integer

You can use the tag property of each ComboBox to store the last value. Go through each ComboBox in design view and set the tag property to -1. This way the form will load with the last value being equal to -1, or nothing.

In each ComboBox, set up the following code in each SelectedIndexChanged event. Don't know how to do this? Double-click on a ComboBox in design view. It should automatically create an event for that ComboBox, which depends on your user history. Regardless, if it isn't already the SelectedIndexChanged event, you will see a list of events in the top right-hand corner of the screen. They have little lightening bolts next to them. In the dropdown, select the correct event. Add the following code, adjusting it for the name of each ComboBox.

VB.NET:
        comboLastComboBoxTouched = ComboBox1
        intLastValue = ComboBox1.Tag
        ComboBox1.Tag = ComboBox1.SelectedIndex

So, when the ComboBox is changed, you first capture the ComboBox in the comboLastComboBoxTouched variable. You then capture the last value it contained (which we store in the Tag property), and last of all you set the ComboBox Tag property to the new value that was selected. You no longer need the old value because you have just stored it in the intLastValue variable.

Now in the Click event of your undo button, the following code will do the trick.

VB.NET:
     comboLastComboBoxTouched.SelectedIndex = intLastValue

At this point, the comboLastComboBoxTouched will be equal to the ComboBox that was last changed, restoring the SelectedIndex value to the last index value you captured.

Hope that helps. Rather than just hand you the code, I tried to walk you through it and make you duplicate it for your own good. It will help you learn if it isn't handed to you on a silver platter. Before you turn in your project, you should really rename your objects as was recommended earlier. You will appear much more intelligent and it is a good habit to build early on.

~ServantOfOne~
 
Also, you should probably set the comboLastComboBoxTouched equal to your first comboBox in the Form_Load event as well as intLastValue = -1. Otherwise, if your user presses the Undo button before changing any ComboBoxes, your program will crash because the comboLastComboBoxTouched will be null.
 
Back
Top