Visual Basic problem using loop

A debug problem using a loop

Page 1 of 1

7 Replies - 1837 Views - Last Post: 12 August 2008 - 05:59 PM Rate Topic: -----

#1 halrox  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-August 08

Visual Basic problem using loop

Posted 11 August 2008 - 08:56 AM

I need some help very badly
I can't figure out how to fix this problem in my book
It's a debug problem, which means we have to fix a minor detail in the pre existing code
the program itself is supposed to count the number of positive, negative integers entered and zeros entered, via an inputbox.

the original code looks like this:

Private Sub enterButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles enterButton.Click
		' displays the number of positive integers, the number of negative integers, 
		' and the number of zeros entered

		Dim inputNumber As String
		Dim number As Integer
		Dim positiveCounter As Integer
		Dim negativeCounter As Integer
		Dim zeroCounter As Integer
		Dim isConverted As Boolean

		Do While inputNumber <> ""
			isConverted = Integer.TryParse(inputNumber, number)
			If isConverted Then
				' update appropriate counter
				If number > 0 Then
					positiveCounter = number + 1
				ElseIf number < 0 Then
					negativeCounter = number + 1
				Else
					zeroCounter = number + 1
				End If
			Else
				MessageBox.Show("Please enter a number", "Number Entry", _
					 MessageBoxButtons.OK, MessageBoxIcon.Information)
			End If
			inputNumber = InputBox("Enter an integer. Click Cancel to end. ", _
				"Number Entry", "0")
		Loop

		' display counters
		positiveLabel.Text = Convert.ToString(positiveCounter)
		negativeLabel.Text = Convert.ToString(negativeCounter)
		zeroLabel.Text = Convert.ToString(zeroCounter)
	End Sub


I've tried a number of different things, by switching the loop to Loop until, loop while, etc. But I think it has something to do with the counter itself, I just don't know! Please help.

Is This A Good Question/Topic? 0
  • +

Replies To: Visual Basic problem using loop

#2 dineeshd  Icon User is offline

  • member icon

Reputation: 38
  • View blog
  • Posts: 619
  • Joined: 30-June 08

Re: Visual Basic problem using loop

Posted 11 August 2008 - 09:12 AM

You should post this in VB.NET Forum
Was This Post Helpful? 0
  • +
  • -

#3 dineeshd  Icon User is offline

  • member icon

Reputation: 38
  • View blog
  • Posts: 619
  • Joined: 30-June 08

Re: Visual Basic problem using loop

Posted 11 August 2008 - 09:19 AM

Anyway try this... :rolleyes:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' displays the number of positive integers, the number of negative integers, 
        ' and the number of zeros entered

        Dim inputNumber As String
        Dim number As Integer
        Dim positiveCounter As Integer
        Dim negativeCounter As Integer
        Dim zeroCounter As Integer
        Dim isConverted As Boolean

        inputNumber = InputBox("Enter an integer. Click Cancel to end. ", "Number Entry")
        Do While inputNumber <> ""
            isConverted = Integer.TryParse(inputNumber, number)
            If isConverted Then
                ' update appropriate counter
                If number > 0 Then
                    positiveCounter = positiveCounter + 1
                ElseIf number < 0 Then
                    negativeCounter = negativeCounter + 1
                Else
                    zeroCounter = zeroCounter + 1
                End If
            Else
                MessageBox.Show("Please enter a number", "Number Entry", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
            inputNumber = InputBox("Enter an integer. Click Cancel to end. ", "Number Entry")
        Loop

        ' display counters
        positiveLabel.Text = Convert.ToString(positiveCounter)
        negativeLabel.Text = Convert.ToString(negativeCounter)
        zeroLabel.Text = Convert.ToString(zeroCounter)
    End Sub 

Was This Post Helpful? 1
  • +
  • -

#4 halrox  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 11-August 08

Re: Visual Basic problem using loop

Post icon  Posted 11 August 2008 - 09:19 AM

I need some help very badly
I can't figure out how to fix this problem in my book
It's a debug problem, which means we have to fix a minor detail in the pre existing code
the program itself is supposed to count the number of positive, negative integers entered and zeros entered, via an inputbox.

the original code looks like this:
Private Sub enterButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles enterButton.Click
		' displays the number of positive integers, the number of negative integers,
		' and the number of zeros entered

		Dim inputNumber As String
		Dim number As Integer
		Dim positiveCounter As Integer
		Dim negativeCounter As Integer
		Dim zeroCounter As Integer
		Dim isConverted As Boolean

		Do While inputNumber <> ""
			isConverted = Integer.TryParse(inputNumber, number)
			If isConverted Then
				' update appropriate counter
				If number > 0 Then
					positiveCounter = number + 1
				ElseIf number < 0 Then
					negativeCounter = number + 1
				Else
					zeroCounter = number + 1
				End If
			Else
				MessageBox.Show("Please enter a number", "Number Entry", _
					 MessageBoxButtons.OK, MessageBoxIcon.Information)
			End If
			inputNumber = InputBox("Enter an integer. Click Cancel to end. ", _
				"Number Entry", "0")
		Loop

		' display counters
		positiveLabel.Text = Convert.ToString(positiveCounter)
		negativeLabel.Text = Convert.ToString(negativeCounter)
		zeroLabel.Text = Convert.ToString(zeroCounter)
	End Sub



I need some help very badly
I can't figure out how to fix this problem in my book
It's a debug problem, which means we have to fix a minor detail in the pre existing code
the program itself is supposed to count the number of positive, negative integers entered and zeros entered, via an inputbox.

the original code looks like this:

Private Sub enterButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles enterButton.Click
        ' displays the number of positive integers, the number of negative integers,
        ' and the number of zeros entered

        Dim inputNumber As String
        Dim number As Integer
        Dim positiveCounter As Integer
        Dim negativeCounter As Integer
        Dim zeroCounter As Integer
        Dim isConverted As Boolean

        Do While inputNumber <> ""
            isConverted = Integer.TryParse(inputNumber, number)
            If isConverted Then
                ' update appropriate counter
                If number > 0 Then
                    positiveCounter = number + 1
                ElseIf number < 0 Then
                    negativeCounter = number + 1
                Else
                    zeroCounter = number + 1
                End If
            Else
                MessageBox.Show("Please enter a number", "Number Entry", _
                     MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
            inputNumber = InputBox("Enter an integer. Click Cancel to end. ", _
                "Number Entry", "0")
        Loop

        ' display counters
        positiveLabel.Text = Convert.ToString(positiveCounter)
        negativeLabel.Text = Convert.ToString(negativeCounter)
        zeroLabel.Text = Convert.ToString(zeroCounter)
    End Sub



I've tried a number of different things, by switching the loop to Loop until, loop while, etc. But I think it has something to do with the counter itself, I just don't know! Please help.
Was This Post Helpful? 0
  • +
  • -

#5 dineeshd  Icon User is offline

  • member icon

Reputation: 38
  • View blog
  • Posts: 619
  • Joined: 30-June 08

Re: Visual Basic problem using loop

Posted 11 August 2008 - 09:26 AM

Go to this link --> Click Here
Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Visual Basic problem using loop

Posted 11 August 2008 - 10:59 AM

Please don't start duplicate topics. Threads merged :)
Was This Post Helpful? 0
  • +
  • -

#7 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: Visual Basic problem using loop

Posted 11 August 2008 - 05:41 PM

is that ur hm wrk?
did you run this program ?
then point out the error ?

This post has been edited by thava: 11 August 2008 - 05:42 PM

Was This Post Helpful? 0
  • +
  • -

#8 WayneSpangler  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 106
  • Joined: 22-March 08

Re: Visual Basic problem using loop

Posted 12 August 2008 - 05:59 PM

I'll give you a hint. In the following code:
Do While inputNumber <> ""
inputNumber will always be nothing (or null or empty).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1