7 Replies - 1330 Views - Last Post: 01 May 2012 - 07:05 AM Rate Topic: -----

#1 tazzy0429   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 27-April 12

issue displaying the equation and answers in a listbox

Posted 27 April 2012 - 12:40 PM

I am doing this assignment on a Math tutor program and I am stuck at one point. First off the listbox needs to show the equations for the number entered between 0 and 12 example:
1+1=2
1+2=3
1+3=4
1+4=5
1+5=6
1+6=7
1+7=8
1+8=9
1+9=10
1+10=11
1+11=12
1+12=13

I don't understand how to get that information into a list box
I am also stuck in an infinite loop somehow i think because nothing shows up at all in the listbox and the number the user enters should at least be there. I am assuming the code should be more like
lstbox.items.add(decNumEntered("+1 =")
could someone point to what i am missing or some psuedocode maybe? Thanks
[Option Strict On
[Option Explicit On

[Public Class frmMathTutor

    ['Initialize and define variables
    [Dim strNumEntered As String
   [ Dim decNumEntered As Decimal
    [Dim strInputMessage As String = "Enter a number between 0 and 12"
    [Dim strInputHeading As String = "Number"
    [Dim strNormalMess As String = "Enter a number between 0 and 12"
    [Dim strNumError As String = "Error - You did not enter a number between 0 and 12."
    [Dim decAnswer As Decimal
    [Dim decMax As Decimal = 13
    [Dim decMin As Decimal = 0
    [Dim strCancelClicked As String = ""


   


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




       

    [End Sub

    [Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click
        Close()
    [End Sub

    [Private Sub mnuClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClear.Click
        lstEquations.Items.Clear()
        btnEnter.Enabled = True
        mnuAddition.Checked = False
        mnuMultiplication.Checked = True
    [End Sub

    [Private Sub mnuAddition_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAddition.Click

        mnuAddition.Checked = True
        mnuMultiplication.Checked = False

    [End Sub

    [Private Sub mnuMultiplication_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles [mnuMultiplication.Click

        [mnuMultiplication.Checked = True
        [mnuAddition.Checked = False

   [ End Sub

   [ Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click

      [  strNumEntered = InputBox(strInputMessage, strInputHeading, "")

     [   Do While decNumEntered < decMax Or decNumEntered >= decMin Or strNumEntered = strCancelClicked

          [  If IsNumeric(strNumEntered) Then
             [   decNumEntered = Convert.ToDecimal(strNumEntered)
             [   If decNumEntered > 0 Then
              [      lstEquations.Items.Add(decNumEntered)
[
               [     strInputMessage = strNormalMess
               [ Else
                [    strInputMessage = strNumError

               [ End If
           [ End If
       [ Loop
   [ End Sub
End Class]

This post has been edited by modi123_1: 27 April 2012 - 01:01 PM
Reason for edit:: highlight the lines THEN click the code tags


Is This A Good Question/Topic? 0
  • +

Replies To: issue displaying the equation and answers in a listbox

#2 m_wylie85   User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: issue displaying the equation and answers in a listbox

Posted 27 April 2012 - 12:56 PM

Have not read the code fully (as it not in code tags and that makes it hard to read) just your post you said this: lstbox.items.add(decNumEntered("+1 =")

What about: lstbox.items.add(decNumEntered.tostring & "+1 =")

This post has been edited by m_wylie85: 27 April 2012 - 12:56 PM

Was This Post Helpful? 1
  • +
  • -

#3 m_wylie85   User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: issue displaying the equation and answers in a listbox

Posted 27 April 2012 - 01:46 PM

also i don't think this is right:

Do While decNumEntered < decMax Or decNumEntered >= decMin Or strNumEntered = strCancelClicked


Probably better this way:

If strNumEntered <> strCancelClicked Then
Do While decNumEntered < decMax And decNumEntered >= DecMin
'the rest of the code

Loop
End If

Was This Post Helpful? 1
  • +
  • -

#4 BobRodes   User is offline

  • Product Manager
  • member icon

Reputation: 604
  • View blog
  • Posts: 3,085
  • Joined: 19-May 09

Re: issue displaying the equation and answers in a listbox

Posted 27 April 2012 - 03:06 PM

Quote

Do While decNumEntered < decMax Or decNumEntered >= decMin
Let's simplify this.
Do while x < 100 or x >= 0
If you think about it, you can't give ANY value for x that doesn't satisfy one or the other of these. Any number that isn't less than 100 is still greater than or equal to 0. Any negative number is less than 100. So, unless your max value is less than your min value (which is unlikely), you will have an infinite loop, regardless of whether your last or condition is true or false.

As wylie says, you need and. a number that is greater than zero AND less than 100 is a number between zero and 100. A number that is greater than zero OR less than 100 is any number.
Was This Post Helpful? 1
  • +
  • -

#5 tazzy0429   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 27-April 12

Re: issue displaying the equation and answers in a listbox

Posted 27 April 2012 - 03:18 PM

Thanks all i see my mistake on there "or" it should be " and" instead. That does make more sense here is the adjusted code it looks better than it did. Now what do you do to get the equations and answers to show in the lstbox. I added the suggestion and still nothing shows up. Is there a tutorial that explains this? Is it an array? I am not sure what those are as we have not done anny but my VS asked if it was so I wondered. Thanks all you are being so helpful!

Option Strict On
Option Explicit On

Public Class frmMathTutor

    'Initialize and define variables
    Dim strNumEntered As String
    Dim decNumEntered As Decimal
    Dim strInputMessage As String = "Enter a number between 0 and 12"
    Dim strInputHeading As String = "Number"
    Dim strNormalMess As String = "Enter a number between 0 and 12"
    Dim strNumError As String = "Error - You did not enter a number between 0 and 12."
    Dim decAnswer As Decimal
    Dim decMax As Decimal = 13
    Dim decMin As Decimal = 0
    Dim strCancelClicked As String = ""


   


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




       

    End Sub

    Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click
        Close()
    End Sub

    Private Sub mnuClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClear.Click
        lstEquations.Items.Clear()
        btnEnter.Enabled = True
        mnuAddition.Checked = False
        mnuMultiplication.Checked = True
    End Sub

    Private Sub mnuAddition_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAddition.Click

        mnuAddition.Checked = True
        mnuMultiplication.Checked = False

    End Sub

    Private Sub mnuMultiplication_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuMultiplication.Click

        mnuMultiplication.Checked = True
        mnuAddition.Checked = False

    End Sub

    Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click

        strNumEntered = InputBox(strInputMessage, strInputHeading, "")

        Do While decNumEntered < decMax And decNumEntered >= decMin Or strNumEntered = strCancelClicked

            If IsNumeric(strNumEntered) Then
                decNumEntered = Convert.ToDecimal(strNumEntered)
                If decNumEntered > 0 Then
                    lstEquations.Items.Add(decNumEntered.ToString & "+1 =")


                    strInputMessage = strNormalMess
                Else
                    strInputMessage = strNumError

                End If
            End If
        Loop
    End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#6 tazzy0429   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 27-April 12

Re: issue displaying the equation and answers in a listbox

Posted 29 April 2012 - 02:49 PM

View Postm_wylie85, on 27 April 2012 - 12:56 PM, said:

Have not read the code fully (as it not in code tags and that makes it hard to read) just your post you said this: lstbox.items.add(decNumEntered("+1 =")

What about: lstbox.items.add(decNumEntered.tostring & "+1 =")



Wylie i tried that and still nothing shows in my listbox. I am not sure why not. Take a look again for me since I have figured out the code tags now :) sorry about that.
 Option Strict On
Option Explicit On

Public Class frmMathTutor

    'Initialize and define variables
    Dim strNumEntered As String
    Dim decNumEntered As Decimal
    Dim strInputMessage As String = "Enter a number between 0 and 12"
    Dim strInputHeading As String = "Number"
    Dim strNormalMess As String = "Enter a number between 0 and 12"
    Dim strNumError As String = "Error - You did not enter a number between 0 and 12."
    Dim decAnswer As Decimal
    Dim decMax As Decimal = 13
    Dim decMin As Decimal = 0
    Dim strCancelClicked As String = ""


   


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




       

    End Sub

    Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click
        Close()
    End Sub

    Private Sub mnuClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClear.Click
        lstEquations.Items.Clear()
        btnEnter.Enabled = True
        mnuAddition.Checked = False
        mnuMultiplication.Checked = True
    End Sub

    Private Sub mnuAddition_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAddition.Click

        mnuAddition.Checked = True
        mnuMultiplication.Checked = False

    End Sub

    Private Sub mnuMultiplication_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuMultiplication.Click

        mnuMultiplication.Checked = True
        mnuAddition.Checked = False

    End Sub

    Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click

        strNumEntered = InputBox(strInputMessage, strInputHeading, "")

        Do While decNumEntered < decMax And decNumEntered >= decMin Or strNumEntered = strCancelClicked

            If IsNumeric(strNumEntered) Then
                decNumEntered = Convert.ToDecimal(strNumEntered)
                If mnuAddition.Checked = True Then
                    If decNumEntered > 0 Then
                        lstEquations.Items.Add(decNumEntered.ToString("+ 1 =" & decAnswer))
                        decAnswer += 1
                        strInputMessage = strNormalMess
                    Else
                        strInputMessage = strNumError

                    End If
                End If
            End If
        Loop
    End Sub
End Class


View Postm_wylie85, on 27 April 2012 - 12:56 PM, said:

Have not read the code fully (as it not in code tags and that makes it hard to read) just your post you said this: lstbox.items.add(decNumEntered("+1 =")

What about: lstbox.items.add(decNumEntered.tostring & "+1 =")



Wylie i tried that and still nothing shows in my listbox. I am not sure why not. Take a look again for me since I have figured out the code tags now :) sorry about that.
 Option Strict On
Option Explicit On

Public Class frmMathTutor

    'Initialize and define variables
    Dim strNumEntered As String
    Dim decNumEntered As Decimal
    Dim strInputMessage As String = "Enter a number between 0 and 12"
    Dim strInputHeading As String = "Number"
    Dim strNormalMess As String = "Enter a number between 0 and 12"
    Dim strNumError As String = "Error - You did not enter a number between 0 and 12."
    Dim decAnswer As Decimal
    Dim decMax As Decimal = 13
    Dim decMin As Decimal = 0
    Dim strCancelClicked As String = ""


   


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




       

    End Sub

    Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click
        Close()
    End Sub

    Private Sub mnuClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClear.Click
        lstEquations.Items.Clear()
        btnEnter.Enabled = True
        mnuAddition.Checked = False
        mnuMultiplication.Checked = True
    End Sub

    Private Sub mnuAddition_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAddition.Click

        mnuAddition.Checked = True
        mnuMultiplication.Checked = False

    End Sub

    Private Sub mnuMultiplication_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuMultiplication.Click

        mnuMultiplication.Checked = True
        mnuAddition.Checked = False

    End Sub

    Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click

        strNumEntered = InputBox(strInputMessage, strInputHeading, "")

        Do While decNumEntered < decMax And decNumEntered >= decMin Or strNumEntered = strCancelClicked

            If IsNumeric(strNumEntered) Then
                decNumEntered = Convert.ToDecimal(strNumEntered)
                If mnuAddition.Checked = True Then
                    If decNumEntered > 0 Then
                        lstEquations.Items.Add(decNumEntered.ToString("+ 1 =" & decAnswer))
                        decAnswer += 1
                        strInputMessage = strNormalMess
                    Else
                        strInputMessage = strNumError

                    End If
                End If
            End If
        Loop
    End Sub
End Class

Was This Post Helpful? 0
  • +
  • -

#7 tazzy0429   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 27-April 12

Re: issue displaying the equation and answers in a listbox

Posted 30 April 2012 - 07:05 AM

View PostBobRodes, on 27 April 2012 - 03:06 PM, said:

Quote

Do While decNumEntered < decMax Or decNumEntered >= decMin
Let's simplify this.
Do while x < 100 or x >= 0
If you think about it, you can't give ANY value for x that doesn't satisfy one or the other of these. Any number that isn't less than 100 is still greater than or equal to 0. Any negative number is less than 100. So, unless your max value is less than your min value (which is unlikely), you will have an infinite loop, regardless of whether your last or condition is true or false.

As wylie says, you need and. a number that is greater than zero AND less than 100 is a number between zero and 100. A number that is greater than zero OR less than 100 is any number.



Thanks for the assistance. I only have one remaining issue. My lst box stays blank with a scroll bar. Why doesnt my text show up like it should??? Would you taks a look and see if i have missed something simple? Thanks so much.

Option Strict On
Option Explicit On

Public Class frmMathTutor

    'Initialize and define variables
    Dim strNumEntered As String
    Dim decNumEntered As Decimal
    Dim strInputMessage As String = "Enter a number between 0 and 12"
    Dim strInputHeading As String = "Number"
    Dim strNormalMess As String = "Enter a number between 0 and 12"
    Dim strNumError As String = "Error - You did not enter a number between 0 and 12."
    Dim decAnswer As Decimal
    Dim decMax As Decimal = 13
    Dim decMin As Decimal = 0
    Dim strCancelClicked As String = ""
    Dim i As Integer


   


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




       

    End Sub

    Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click
        Close()
    End Sub

    Private Sub mnuClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClear.Click
        lstEquations.Items.Clear()
        btnEnter.Enabled = True
        mnuAddition.Checked = False
        mnuMultiplication.Checked = True
    End Sub

    Private Sub mnuAddition_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAddition.Click

        mnuAddition.Checked = True
        mnuMultiplication.Checked = False

    End Sub

    Private Sub mnuMultiplication_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuMultiplication.Click

        mnuMultiplication.Checked = True
        mnuAddition.Checked = False

    End Sub

    Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click

        strNumEntered = InputBox(strInputMessage, strInputHeading, "")

        Do While decNumEntered < decMax And decNumEntered >= decMin Or strNumEntered = strCancelClicked
            If IsNumeric(strNumEntered) Then
                decNumEntered = Convert.ToDecimal(strNumEntered)
                For i As Integer = 1 To CInt(decNumEntered)
                    lstEquations.Items.Add(String.Format("1+{0}={1}", i, i + 1))
                Next
                strInputMessage = strNormalMess
            Else
                strInputMessage = strNumError
            End If

        Loop

    End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#8 BobRodes   User is offline

  • Product Manager
  • member icon

Reputation: 604
  • View blog
  • Posts: 3,085
  • Joined: 19-May 09

Re: issue displaying the equation and answers in a listbox

Posted 01 May 2012 - 07:05 AM

Start by looking at your while loop logic. When you first hit line 61, what is the value of decNumEntered? Start with this, and figure it out.

Also, you shouldn't evaluate anything in your while loop that doesn't change during iterations. So evaluate the cancel button before entering the loop, and leave the sub if the user cancels. What's more, you're saying that so long as the user clicks cancel, you should keep going through the loop. Bet you haven't tried clicking your cancel button! :)

Finally, I wouldn't use a while loop at all, I'd use a for loop. Fix the other stuff, and I'll explain why.

This post has been edited by BobRodes: 01 May 2012 - 07:11 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1