none
HELP PLEASE Visual Basic RRS feed

  • Question

  • Write a visual basic program that has two list boxes a button and a textbox.  The first list box will have each digit of your N-number as a separate list item.  

    Write a sub that takes an integer parameter that puts the numbers from 0 to its parameter in the number list box using a For loop.

    Write a sub that takes a list box parameter and a string parameter that adds the string to the beginning of the list box.

    Have the form load event call the sub just above to put the numbers from 0 to the number of lines in your N-number list - 1 into the number list box.

    • When you select an item in the n-number list, select the position of the item in the number list.
    • When you select a number in the number list select the item at that postion in the n-number list.
    • When you click on the button:
      • if the text in the textbox already is in the n-number list box select the item in the n-number listbox
      • if the text in the textbox is not in the n-number listbox:
        • add the text in the textbox to the begining of the  n-number listbox using the sub that adds an item to the begining of a list mentioned previously.
        • clear the number listbox
        • put into the number listbox the numbers from 0 to the number of items in the letter lisbox -1 using the sub mentioned previously that fills listboxes.
    new codes
    
    
    Public Class frm1
        Private Sub lstbox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstbox1.SelectedIndexChanged
            lstbox2.SelectedIndex = lstbox1.SelectedIndex
        End Sub
    
        Private Sub lstbox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstbox2.SelectedIndexChanged
            lstbox1.SelectedIndex = lstbox2.SelectedIndex
        End Sub
        Private Sub Mysub1(p As Integer)
            Dim i As Integer
            For i = 0 To p
                lstbox1.Items.Add(i)
            Next
        End Sub
        Private Sub Mysub2(lb As ListBox, s As String)
            lb.Items.Insert(0, s)
        End Sub
    
        Private Sub btn_Click(sender As Object, e As EventArgs) Handles btn.Click
            Dim i As Integer
            If lstbox1.Items.Contains(txtbox.Text) Then
                lstbox1.SelectedIndex = lstbox1.Items.IndexOf(txtbox.Text)
            Else
                Mysub2(lstbox1, txtbox.Text)
                lstbox2.Items.Clear()
                For i = lstbox1.Items.Count - 1 To 0 Step -1
                    Mysub2(lstbox2, i.ToString())
                Next
            End If
        End Sub
    End Class


    • Edited by JattBoi Friday, May 10, 2019 2:25 AM
    Thursday, May 2, 2019 11:24 PM

Answers

  • Hi

    You will get all the help you need, but, only if you do the coding. This forum is not a software writing service, especially not a homework writing service.

    What you need to do:

    Write, or start writing, the code, You have a set of directives that lay out the basic design for you.

    Step by step, add to your code, testing as you go.

    *

    Whatever else you learn today, one of them is that just posting your assignment to a forum does not result in having your homework done by cut and paste.

    When you run into problems, post back here, showing the code you have, and any exception messages - or where the problem is happening.


    Regards Les, Livingston, Scotland

    • Marked as answer by JattBoi Thursday, May 9, 2019 10:50 AM
    Thursday, May 2, 2019 11:41 PM
  • (this is what i came up with)

    Public Class frm1
        Sub clearnumberList()
            lst1.Items.Clear()
        End Sub
        Sub putnumberonlist(ByVal x As Integer)
            Dim i As Integer
            For i = 0 To x - 1
                lst1.Items.Add(i)
            Next
        End Sub

        Private Sub lst2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lst2.SelectedIndexChanged
            Dim num As Integer
            num = lst2.Items.Count
            putnumberonlist(num)

        End Sub

        Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
            Dim flag As Integer = 0
            For i As Integer = 0 To lst2.Items.Count - 1
                If txt1.Text = lst2.Items.Item(i).ToString Then
                    lst2.SelectedIndex = i
                    flag = 1
                    Exit For

                End If
            Next
            If flag = 0 Then
                clearnumberList()
                lst2.Items.Add(txt1.Text)
                putnumberonlist(lst2.Items.Count)
            End If

        End Sub

    End Class


    Did you not read my request to post code in a code block? 

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by JattBoi Thursday, May 9, 2019 10:49 AM
    Thursday, May 9, 2019 1:11 AM
    Moderator
  • Hi
    Well done, you have made a good start. However, just posting a piece of code without any indication of a question, or errors encountered or methology problems will not get you much in any answer.
    Although I don't fully understand the directives given in their entirety, I can figure out some of them.
    *
    1.  Write a visual basic program that has two list boxes a button And a textbox.
    DONE OK
    *
    2. Write a sub that takes an integer parameter that puts the numbers from 0 to its parameter in the number list box using a For loop.
    Your Sub putnumberonlist(ByVal x As Integer) does that OK.
    DONE OK - but, if the actual number is needed then omit the -1 in the loop
    *
    3. Write a sub that takes a list box parameter and a string parameter that adds the string to the beginning of the list box.
    NOT DONE - something like:
    Sub AddStringToLB(LB As ListBox, str As String) needed, and, an Insert to the ListBox (NOT an Add)
    *
    4.  Have the form load event call the sub just above to put the numbers from 0 to the number of lines in your N-number list - 1 into the number list box.
    Seems like you also have another list of data that you need - is that the case? If not, then I am at a loss without further explanation. Is that the ENTIRE Q|UESTION details you were given?
    Lets sort this out before proceeding further. Maybe I am not understanding, but is the N-number list referring to the first listbox?

    Regards Les, Livingston, Scotland

    • Marked as answer by JattBoi Friday, May 10, 2019 2:28 AM
    Thursday, May 9, 2019 2:10 AM

All replies

  • Hi

    You will get all the help you need, but, only if you do the coding. This forum is not a software writing service, especially not a homework writing service.

    What you need to do:

    Write, or start writing, the code, You have a set of directives that lay out the basic design for you.

    Step by step, add to your code, testing as you go.

    *

    Whatever else you learn today, one of them is that just posting your assignment to a forum does not result in having your homework done by cut and paste.

    When you run into problems, post back here, showing the code you have, and any exception messages - or where the problem is happening.


    Regards Les, Livingston, Scotland

    • Marked as answer by JattBoi Thursday, May 9, 2019 10:50 AM
    Thursday, May 2, 2019 11:41 PM
  • Hello,

    In addition to Les post in regards to writing code, you need to make an effort and when you run into a problem research the problem, read Microsoft documentation and if still at a point where you need assistance post only relevant code using code blocks. In addition to posting code don't say something like "I'm stuck" or "I got this error" without indicating the offending code.

    Always post code using the following button.

    Indicate what .NET Framework is being used and what version of Visual Studio is being used.

    Following my advice and Les's advice will speed along the learning process.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Friday, May 3, 2019 1:04 AM
    Moderator
  • (this is what i came up with)

    Public Class frm1
        Sub clearnumberList()
            lst1.Items.Clear()
        End Sub
        Sub putnumberonlist(ByVal x As Integer)
            Dim i As Integer
            For i = 0 To x - 1
                lst1.Items.Add(i)
            Next
        End Sub
    
        Private Sub lst2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lst2.SelectedIndexChanged
            Dim num As Integer
            num = lst2.Items.Count
            putnumberonlist(num)
    
        End Sub
    
        Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
            Dim flag As Integer = 0
            For i As Integer = 0 To lst2.Items.Count - 1
                If txt1.Text = lst2.Items.Item(i).ToString Then
                    lst2.SelectedIndex = i
                    flag = 1
                    Exit For
    
                End If
            Next
            If flag = 0 Then
                clearnumberList()
                lst2.Items.Add(txt1.Text)
                putnumberonlist(lst2.Items.Count)
            End If
    
        End Sub
    
    End Class
    
    


    Thursday, May 9, 2019 12:53 AM
  • (this is what i came up with)

    Public Class frm1
        Sub clearnumberList()
            lst1.Items.Clear()
        End Sub
        Sub putnumberonlist(ByVal x As Integer)
            Dim i As Integer
            For i = 0 To x - 1
                lst1.Items.Add(i)
            Next
        End Sub

        Private Sub lst2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lst2.SelectedIndexChanged
            Dim num As Integer
            num = lst2.Items.Count
            putnumberonlist(num)

        End Sub

        Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
            Dim flag As Integer = 0
            For i As Integer = 0 To lst2.Items.Count - 1
                If txt1.Text = lst2.Items.Item(i).ToString Then
                    lst2.SelectedIndex = i
                    flag = 1
                    Exit For

                End If
            Next
            If flag = 0 Then
                clearnumberList()
                lst2.Items.Add(txt1.Text)
                putnumberonlist(lst2.Items.Count)
            End If

        End Sub

    End Class


    Did you not read my request to post code in a code block? 

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by JattBoi Thursday, May 9, 2019 10:49 AM
    Thursday, May 9, 2019 1:11 AM
    Moderator
  • Hi
    Well done, you have made a good start. However, just posting a piece of code without any indication of a question, or errors encountered or methology problems will not get you much in any answer.
    Although I don't fully understand the directives given in their entirety, I can figure out some of them.
    *
    1.  Write a visual basic program that has two list boxes a button And a textbox.
    DONE OK
    *
    2. Write a sub that takes an integer parameter that puts the numbers from 0 to its parameter in the number list box using a For loop.
    Your Sub putnumberonlist(ByVal x As Integer) does that OK.
    DONE OK - but, if the actual number is needed then omit the -1 in the loop
    *
    3. Write a sub that takes a list box parameter and a string parameter that adds the string to the beginning of the list box.
    NOT DONE - something like:
    Sub AddStringToLB(LB As ListBox, str As String) needed, and, an Insert to the ListBox (NOT an Add)
    *
    4.  Have the form load event call the sub just above to put the numbers from 0 to the number of lines in your N-number list - 1 into the number list box.
    Seems like you also have another list of data that you need - is that the case? If not, then I am at a loss without further explanation. Is that the ENTIRE Q|UESTION details you were given?
    Lets sort this out before proceeding further. Maybe I am not understanding, but is the N-number list referring to the first listbox?

    Regards Les, Livingston, Scotland

    • Marked as answer by JattBoi Friday, May 10, 2019 2:28 AM
    Thursday, May 9, 2019 2:10 AM
  • Hey, are the codes right or wrong?

    Hi

    Some are right (as I pointed out in my last post), some I don't know because I can't get it all to do very much (I would like to know what it is supposed to do)

    Is there any data not shown in your original post?


    Regards Les, Livingston, Scotland


    • Edited by leshay Thursday, May 9, 2019 1:05 PM
    Thursday, May 9, 2019 1:05 PM
  • yes n-number list is referring to lstbox1
    Friday, May 10, 2019 2:28 AM
  • yes n-number list is referring to lstbox1

    Hi

    If you are just going to give simplistic one line information we will still be working on this next year.

    Give a step by step explanation of what you want to happen

    For example.

    1.User enters a number in TextBox1

    2. Code takes the string in TextBox1 and splits it into single characters and puts into ListBox1

    etc etc etc

    *

    Over to you.

    *

    Remember, the quality of the answer depends on the quality of the question.


    Regards Les, Livingston, Scotland

    Friday, May 10, 2019 12:13 PM