8 Replies - 378 Views - Last Post: 17 January 2013 - 07:58 PM Rate Topic: -----

#1 jayveeeeeee  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 66
  • Joined: 27-September 12

my program is stock when i press my button

Posted 15 January 2013 - 08:14 AM

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim d As Integer = d.ToString()

        ListBox1.BeginUpdate()

        For d = 1 To 5

            ListBox1.Items.Add(d)

        Next d

        ListBox1.EndUpdate()

    End Sub

 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim d As Integer = d.ToString()

        ListBox1.BeginUpdate()

        ListBox2.BeginUpdate()

        While ListBox1.SelectedItems.Count > 0

            d = ListBox1.Items.Add(0)

            ListBox1.Items.Remove(d)

            ListBox2.Items.Add(d * d)

            ListBox1.EndUpdate()

            ListBox2.EndUpdate()
        End While

    End Sub

End Class






i want to create a two listbox with a button and i am doing is in the listbox have a value of loop 1 to 5 and then when i press the button ,in the listbox1 will go into listbox2 but it will multiply by itself ...

my problem when i run my program and i press the button my program stock (form 1).

 Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim d As Integer = d.ToString()

ListBox1.BeginUpdate()

For d = 1 To 5

ListBox1.Items.Add(d)

Next d

ListBox1.EndUpdate()

End Sub



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim d As Integer = d.ToString()

ListBox1.BeginUpdate()

ListBox2.BeginUpdate()

While ListBox1.SelectedItems.Count > 0

d = ListBox1.Items.Add(0)

ListBox1.Items.Remove(d)

ListBox2.Items.Add(d * d)

ListBox1.EndUpdate()

ListBox2.EndUpdate()
End While

End Sub

End Class



This post has been edited by modi123_1: 15 January 2013 - 08:13 AM
Reason for edit:: fixed botched code tag


Is This A Good Question/Topic? 0
  • +

Replies To: my program is stock when i press my button

#2 jayveeeeeee  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 66
  • Joined: 27-September 12

Re: my program is stock when i press my button

Posted 15 January 2013 - 09:12 AM

please help me ,,just give me suggest what to do to my code ...
Was This Post Helpful? 0
  • +
  • -

#3 torind_2000  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 52
  • View blog
  • Posts: 271
  • Joined: 22-August 11

Re: my program is stock when i press my button

Posted 15 January 2013 - 09:18 AM

View Postjayveeeeeee, on 15 January 2013 - 11:14 AM, said:

        Dim d As Integer = d.ToString() 



Wut?
Was This Post Helpful? 0
  • +
  • -

#4 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: my program is stock when i press my button

Posted 15 January 2013 - 11:00 AM

View Postjayveeeeeee, on 15 January 2013 - 09:14 AM, said:

i want to create a two listbox with a button and i am doing is in the listbox have a value of loop 1 to 5 and then when i press the button ,in the listbox1 will go into listbox2 but it will multiply by itself ...

my problem when i run my program and i press the button my program stock (form 1).


Well, it isn't actually stuck. It's just not doing what you think you told it to do.
First, you need to learn some Debugging Skills.

Now for your code:

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim d As Integer = d.ToString()
           'This works, but what it does is makes a variable called d,
           '  which has a value of 0. Then it assigns the string representation
           '  of 0 to d. The compiler automatically converts it back to a 0 for you
           'You can do exactly the same thing by using [b]Dim d as Integer[/b]

        ListBox1.BeginUpdate()
           'While you are debugging (presumably single-stepping through
           '  the code, you should comment out all the BeginUpdate and EndUpdate
           '  lines. and for debugging, one step at a time, you should add a statement
           ' after each ListBox.Items.Add statement that says [b]Application.DoEvents[/b].
           'This will cause the debugger to let the ListBox update immediately
        For d = 1 To 5
            ListBox1.Items.Add(d)
        Next d
            'This works as you expect.

        ListBox1.EndUpdate()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim d As Integer = d.ToString()
          ' Again, just [b]Dim d as Integer[/b]
        ListBox1.BeginUpdate()
        ListBox2.BeginUpdate()

        While ListBox1.SelectedItems.Count > 0
          'There are no SelectedItems in the ListBox
          'Look up the Documentation for ListBoxes, and see what Items(n)
          '  does for you. (n is a number)

            d = ListBox1.Items.Add(0)
              'This is one of the most creative statements I've ever seen.
              'When you single-step through it, you'll see that it does two things
              'The first is that it adds an entry to ListBox 1 (it adds a 0)
              ' and assigns 5 to variable d. Why" Because there are 5 Items in
              ' the ListBox, and ListBox.Items either sets or gets the items
              'Because of the Add, the Count goes up, and each time through the loop
              ' d becomes larger. It results in an endless loop, because the number
              ' of Items in the ListBox never gets to zero. The first 8 values
              ' in ListBox 2 end up as 25, 25, 36.49,64,81,100,121
              'Of course, you never see them becase of the BeginUpdate and EndUpdate statements

            ListBox1.Items.Remove(d)
            ListBox2.Items.Add(d * d)
            ListBox1.EndUpdate()
            ListBox2.EndUpdate()
        End While
    End Sub

End Class


See what you can come up with now that a few things have been pointed out to you. Get back to us with any further questions you may have.

This post has been edited by lar3ry: 15 January 2013 - 11:02 AM

Was This Post Helpful? 0
  • +
  • -

#5 jayveeeeeee  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 66
  • Joined: 27-September 12

Re: my program is stock when i press my button

Posted 17 January 2013 - 07:44 AM

one thing i just want to enter the button once how can i do it ..
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim a As Integer
        Application.DoEvents()
        For a = 1 To 5
            ' If ListBox2.SelectedItems.Count = false Then
            ListBox2.Items.Add(a * a.ToString())


            'End If
        Next a
    End Sub
    

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim a As Integer
        Application.DoEvents()
        For a = 1 To 5
            ListBox1.Items.Add(a.ToString())
        Next a
    End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8399
  • View blog
  • Posts: 31,245
  • Joined: 12-June 08

Re: my program is stock when i press my button

Posted 17 January 2013 - 07:58 AM

Quote

one thing i just want to enter the button once

What does this even mean?
Was This Post Helpful? 0
  • +
  • -

#7 jayveeeeeee  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 66
  • Joined: 27-September 12

Re: my program is stock when i press my button

Posted 17 January 2013 - 08:53 AM

i just want to try if it possible to enter once in button ,like i have a two listbox , in the listbox1 is the value of loop(1 to 5) when i enter the button it will go to listbox2 .and then when pressed one button will not exist anymore it will just one to enter
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8399
  • View blog
  • Posts: 31,245
  • Joined: 12-June 08

Re: my program is stock when i press my button

Posted 17 January 2013 - 09:04 AM

Sure.. that's all an architecture hurdle on your end, right? You need to develop a work flow. So the app starts.. list box 1 and 2 are filled, the button is enabled, and listbox 2 is disabled. A user selects an option in listbox1 and clicks the button.. the button checks the enabled state of listbox 1 and 2.. sees 1 is enabled and 2 is disabled.. it then disables listbox1 and enables listbox2...

the user selects something in listbox2 and clicks the button.. the button checks the state of listbox 1 and 2... it sees 1 is disabled and 2 is enabled.. so it knows to disabled listbox 2 and disable itself.

See.. work flow!
Was This Post Helpful? 1
  • +
  • -

#9 jayveeeeeee  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 66
  • Joined: 27-September 12

Re: my program is stock when i press my button

Posted 17 January 2013 - 07:58 PM

thanks Men
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1