none
Someone please show me how to write this RRS feed

  • Question

  • I am having difficulty with my VB class in college. So far I kind of suck as a coder. But regardless it is a requirement. 

    This is my assignment. 

    "Write the Visual Basic code for a pretest loop that uses an Integer variable named
    intEven to display the even integers from 2 through 20 in the lblEven control. Use the
    For...Next statement. Display each number on a separate line in the control. Then create
    an application to test your code using the following names for the solution and project,
    respectively: Even Solution and Even Project. Save the application in the VB2015\
    Chap06 folder. Add a button and a label to the interface. Enter your code in the button’s
    Click event procedure, and then test the application appropriately."


    Thursday, February 8, 2018 1:40 AM

All replies

  • I am having difficulty with my VB class in college. So far I kind of suck as a coder. But regardless it is a requirement. 

    This is my assignment. 

    "Write the Visual Basic code for ..."


    So how far have you gotten?

    How much code have you written for this assignment and what parts of
    the task does it handle?

    On what part of the assignment are you stuck - specifically, not
    generally?

    We try not to do students' assignments for them. That's cheating, and
    while it may appear to have some short term gain for the student it
    actually prevents the student from advancing.

    Try to think modularly about the assignment.

    Try to break the task down into simple subtasks.  Then code and test
    each subtask - starting with those that are easiest for you. As you
    progress you will begin to see how these pieces fit together to form
    the complete program.

    We'll help you to get past specific sticking points, but you have to
    make a real and apparent effort to write some code yourself.

    - Wayne

    Thursday, February 8, 2018 2:39 AM
  • I am having difficulty with my VB class in college. So far I kind of suck as a coder. But regardless it is a requirement. 

    This is my assignment. 

    "Write the Visual Basic code for ..."


    So how far have you gotten?

    How much code have you written for this assignment and what parts of
    the task does it handle?

    On what part of the assignment are you stuck - specifically, not
    generally?

    We try not to do students' assignments for them. That's cheating, and
    while it may appear to have some short term gain for the student it
    actually prevents the student from advancing.

    Try to think modularly about the assignment.

    Try to break the task down into simple subtasks.  Then code and test
    each subtask - starting with those that are easiest for you. As you
    progress you will begin to see how these pieces fit together to form
    the complete program.

    We'll help you to get past specific sticking points, but you have to
    make a real and apparent effort to write some code yourself.

    - Wayne

    This is what I have

    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

            For intEven As Integer = 2 To 20 Step +2
                lblEven.Text = lblEven.Text & intEven.ToString & ControlChars.NewLine


            Next intEven
        End Sub
    End Class

    I am confused about the lblEven control for the separate list. The number should start from 2 on a separate line below the label but it instead the 2 starts next to it and then it goes down a list.  


    • Edited by Oddlamer Thursday, February 8, 2018 4:11 AM
    Thursday, February 8, 2018 3:50 AM
  • Hi Oddlamer,

    If you want to get even number from 2 to 20 in label control, you can use Mod method, please take a look the following code:

    Dim ca As Integer
            For i As Integer = 2 To 20
                ca = i Mod 2
                If ca = 0 Then
                    Label1.Text = i & "," & Label1.Text
                Else
    
                End If
            Next

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, February 8, 2018 4:05 AM
    Moderator
  • This is what I have

    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

            For intEven As Integer = 2 To 20 Step +2
                MessageBox.Show(intEven.ToString)

            Next intEven
        End Sub
    End Class

    This is the bit you are missing: "...display the even integers from 2 through 20 in the lblEven control".

    This is what you need:
    Convert an integer to a string: https://msdn.microsoft.com/en-us/library/6t7dwaa5(v=vs.110).aspx
    String concatenation: https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/operators-and-expressions/concatenation-operators
    Visual Basic Constants - New line :https://msdn.microsoft.com/en-us/library/microsoft.visualbasic.constants.vbcrlf%28v=vs.110%29.aspx
    Label Control Properties: https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.label.text(v=vs.110).aspx

    Thursday, February 8, 2018 4:06 AM
  • Sorry, 

    it was actually 

    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnPush.Click

            For intEven As Integer = 2 To 20 Step +2

                lblEven.Text = lblEven.Text & intEven.ToString & ControlChars.NewLine


            Next intEven
        End Sub
    End Class

    I just cant get the "2" at the beginning of the list to start beneath the label. It starts next to it. 

    Thursday, February 8, 2018 4:19 AM
  • Hi Oddlamer,

    Do you want 2 in the bottom of the label, and so on, 20 ranked at the top of it? If yes, please take a look the following code:

     For intEven As Integer = 2 To 20 Step +2
                lblEven.Text = intEven.ToString & ControlChars.NewLine & lblEven.Text
            Next intEven

    Best regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, February 8, 2018 5:33 AM
    Moderator
  • add this before you start the loop

    LblEven.Text = ""
    

    Thursday, February 8, 2018 5:41 AM
  • I just cant get the "2" at the beginning of the list to start beneath the label. It starts next to it. 

    Do you mean that you want the numbrs to start after the existing text in the label?

    For intEven As Integer = 2 To 20 Step +2
        lblEven.Text &= vbCrLf & intEven.ToString


    Thursday, February 8, 2018 5:56 AM