Results 1 to 18 of 18

Thread: [RESOLVED] How can I loop an InputBox to have different function

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2020
    Posts
    18

    Resolved [RESOLVED] How can I loop an InputBox to have different function

    I have here a code that displays an InputBox when I item of the combobox is selected.
    I want my application to display different InputBoxes ......for Eg. after asking the user for their last name , it should also ask for their gender and continuously
    Code:
            If ComboBox1.Text = "General Science" Then
                Dim lname As String = InputBox("Enter your Last Name", Me.Text, "NoName")
    
             
            End If
    
        End Sub
    Attached Images Attached Images  

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: How can I loop an InputBox to have different function

    You don't need a loop etc, you just need to add more lines that will show an InputBox, eg:
    Code:
            If ComboBox1.Text = "General Science" Then
                Dim lname As String = InputBox("Enter your Last Name", Me.Text, "NoName")
                Dim gender As String = InputBox("Enter your Gender", Me.Text, "NoGender")
                Dim somethingElse As String = InputBox("Enter Something Else", Me.Text, "NothingElse")
             
            End If
    ...however, wouldn't it be better to show a form which has textboxes for each of the items you want to enter?

    Maybe even have the controls on your current form, and just have them hidden (perhaps by putting them in a Panel and hiding that) until you want them displayed.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2020
    Posts
    18

    Re: How can I loop an InputBox to have different function

    Hello si_the_geek i tried what you said and it worked, thank you for that but how can your suggestion be done does it mean that i should have 13 forms which have textboxes on each of them. Because when i use the inputbox, i will want it to display 13 times

    below is a picture of what i'm to do but I want to know what you would have if asked that as the programmer
    the number 3
    Attachment 177724

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,039

    Re: How can I loop an InputBox to have different function

    You REALLY don't want either of those solutions. Just think about using a program that pops up 13 inputboxes in a row. How annoying would that be? They wouldn't even show up at the same place, so you'd be chasing them around the screen. It would be horrible. When people want to ask thirteen questions, they make a single form with thirteen questions on it and thirteen textboxes on it.
    My usual boring signature: Nothing

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: How can I loop an InputBox to have different function

    You should have all 13 textboxes on just one form.

    I would recommend having them one under the other, with a Label to the left of each to say what you are supposed to enter (eg: "Last Name" and "Gender").



    edit: oops, it seems I was slow!

  6. #6

    Thread Starter
    Junior Member
    Join Date
    May 2020
    Posts
    18

    Re: How can I loop an InputBox to have different function

    wait if i want to understand you better the textboxes will be under one another and the labels will be hidden till i click the value from the combobox to show it, right?
    but won't this make the application faulty since i was not asked to add any button to show next textbox.
    this image is what i should follow to build my application
    Attachment 177725
    so i want to know what best is suitable for my application

    thanks for all suggestions @Shaggy Hiker and si_the_geek

  7. #7
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: How can I loop an InputBox to have different function

    Your attachment link doesn't work.

  8. #8
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: How can I loop an InputBox to have different function

    Quote Originally Posted by Shaggy Hiker View Post
    You REALLY don't want either of those solutions. Just think about using a program that pops up 13 inputboxes in a row. How annoying would that be? They wouldn't even show up at the same place, so you'd be chasing them around the screen. It would be horrible. When people want to ask thirteen questions, they make a single form with thirteen questions on it and thirteen textboxes on it.
    Can't really veer to far from the assigned form layout and methods. Could hurt the grade.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,039

    Re: How can I loop an InputBox to have different function

    Quote Originally Posted by Nana5 View Post
    wait if i want to understand you better the textboxes will be under one another and the labels will be hidden till i click the value from the combobox to show it, right?
    but won't this make the application faulty since i was not asked to add any button to show next textbox.
    this image is what i should follow to build my application
    Attachment 177725
    so i want to know what best is suitable for my application

    thanks for all suggestions @Shaggy Hiker and si_the_geek
    It very well might make it faulty. If you have a requirement, then you have to meet that requirement. I was thinking this wasn't an assignment, in which case you make it useable. If this is an assignment, you have to follow the assignment, whether the end result is good or bad.

    The attachment clearly didn't work, but what was it supposed to be? You added a picture, earlier, and as you have probably noticed, pictures don't work very well on this site. They tend to be shrunk down to the point where they aren't readable. If the assignment is text, you would be better off copying and pasting it into a post.
    My usual boring signature: Nothing

  10. #10

    Thread Starter
    Junior Member
    Join Date
    May 2020
    Posts
    18

    Re: How can I loop an InputBox to have different function

    2. On the “Check Eligibility” form, the applicant must select from a drop-down control the
    following programmes (General Science, Business Administration, General Arts).

    3. For each option selected, the applicant must be able to enter their results based on the
    subjects specific to the choice. Also, the applicant must be able to enter their name (first
    name, last name), Date of Birth, Gender, Name of previous school. The “Check” button on this
    form must be inactive until the applicant enters all required fields.

    4. After clicking “Check” the program should calculate the applicant’s grade, verify if they qualify
    for admission for the selected programmed and display a message to that effect. The details
    of the applicant should be saved in a table “Applicants” and the “Qualified” column of the
    table should be “Yes”. For unsuccessful applicants the data should be saved into the same
    table and “No” saved into the “Qualified” column.

    Okay @ShaggyHiker so that is what can be found in the picture..i'm on number 3 but i'm kinda confused on what to use
    whether the inputbox or textbox for such a process

  11. #11
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,039

    Re: How can I loop an InputBox to have different function

    That does make it more clear. I don't believe they want you to be using InputBox at all for this. I also understand your confusion, the question is poorly worded. The first sentence and the second sentence could have been two entirely separate points, rather than being stuffed into number 3. At best, they would have been 3a, 3b, and 3c, the way I see it.

    What I believe they want would best be seen by reading the second sentence first, then the first sentence, and finally the third. So, what I would be expecting is a textbox for first name, a textbox for last name, a DateTimePicker for date of birth (a textbox would also work, but would be MUCH harder to get right), two or more radio buttons for gender, then another textbox for previous school.

    There would also be the combobox, or a listbox (take your pick), as you currently have, which I would put below those other controls. However, I don't know what this means:

    the applicant must be able to enter their results based on the
    subjects specific to the choice
    They have to enter something based on a selection. Can they select more than one thing, or only one? Also, what are their results? Is that a number, text, or something else? The way that is worded, I'm not sure if it is one value or many values. Depending on what that means, the solution to that could be as simple as a textbox, or as complicated as an entire second form.

    Finally, the third sentence is clear, but can be a bit tricky to implement. All that means is that there is a button that is set to .Enabled = False to begin with. Whenever the user enters anything into any of the other controls, you'd have to check that something valid has been entered into ALL the controls, and if every control has a valid value, then the button .Enabled should be set to True. Doing that well, is difficult. Fortunately, since this is an assignment, doing it well isn't a requirement.
    My usual boring signature: Nothing

  12. #12
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    Re: How can I loop an InputBox to have different function

    For the check button, inactive doesn't necessarily mean enabled = false , it could be also : "nothing happen if you click and one or more textbox is empty" (I happen to have a input form just like that in an application)

    Code:
     Private Sub OK_Button_Click(sender As System.Object, e As System.EventArgs) Handles OK_Button.Click
            For Each ctrl As TextBox In Me.Controls.OfType(Of TextBox)()
                If ctrl.Text = "" Then Exit Sub
            Next
    
            'do what you want here if it is ok
        End Sub
    Last edited by Delaney; Jun 30th, 2020 at 05:31 PM.
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  13. #13

    Thread Starter
    Junior Member
    Join Date
    May 2020
    Posts
    18

    Re: How can I loop an InputBox to have different function

    @ShaggyHiker subjects specific to the choice that refers to the grades of some subjects found in the programme selected
    For eg, General Science can have subjects like Biology, Chemistry and Physics ......where grades are from A1 to F9 but the check button will find the total of the numbers only

  14. #14
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,039

    Re: How can I loop an InputBox to have different function

    If you are entering "A1" or "F9", then a textbox would likely work best. If you are just entering 1 for A or 9 for F, then using a NumericUpDown control would be much better than using a textbox.

    So, if I understand it right, there is a drop down that has General Science in it. If they select that, then they are asked for Biology, then Chemistry, then Physics?
    My usual boring signature: Nothing

  15. #15

    Thread Starter
    Junior Member
    Join Date
    May 2020
    Posts
    18

    Re: How can I loop an InputBox to have different function

    Yes they ask of grades of these subjects (Physics, Biology and Chemistry) when General Science is selected from the drop down list or General Arts (History, Literature, French)

    Also, is there a possibility that having a textbox that i enter A1, B2, B3 to F9 as the grades of these subjects I can sum the numbers only?

  16. #16
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,039

    Re: How can I loop an InputBox to have different function

    As long as a grade is always one character followed by a number, then there is a way. You might do this, for example:
    Code:
    Dim yourString as String = "A1"
    Dim num As Integer = CInt(yourString,1)
    That's not a great solution, but it's a simple one. It will crash if the string is anything other than a single character followed by a number, and it will give you the wrong answer if the string was something like "10", but it would work for the exact situation you described. A safer solution, that would handle typos, and other errors, better, would be much more involved.

    If there are always just three courses, then that would be simple. Beside the combobox (or listbox), you could have three labels with three textboxes to the right of them. When the user clicks a selection in the combobox, you would handle the SelectedIndexChanged event. In there, you'd see what they selected, then fill the three labels with the three course names. The user would then be able to enter the three grades into the three textboxes.

    That would look fine, as long as every selection in the combobox results in the same number of subjects (could be all three, all four, or something else). If you don't have the same number of subjects for each selection, then you'd want to hide the label and textbox for any that weren't used.

    Alternatively, you could actually use InputBox for this, so I see where you were coming from with that. It doesn't look like the assignment requires you to do so, though, and it wouldn't be a good thing to do. With InputBox, people would really only get one chance to get it right. You wouldn't have any easy way to go back to the last one, fix just one, or get out before the end. You could come up with a much more complicated interface that did allow you to do that, but it would be....much more complicated. Keeping it all on one form will ultimately be easier.
    My usual boring signature: Nothing

  17. #17

    Thread Starter
    Junior Member
    Join Date
    May 2020
    Posts
    18

    Re: How can I loop an InputBox to have different function

    yes, now yo got me anyways thanks very much. I was able to move forward on my project with the suggestions I had from @ShaggyHiker and everyone who helped. So therefore I will move this thread to a resolved one. Thank you

  18. #18
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: How can I loop an InputBox to have different function

    Quote Originally Posted by Delaney View Post
    For the check button, inactive doesn't necessarily mean enabled = false , it could be also : "nothing happen if you click and one or more textbox is empty" (I happen to have a input form just like that in an application)

    Code:
     Private Sub OK_Button_Click(sender As System.Object, e As System.EventArgs) Handles OK_Button.Click
            For Each ctrl As TextBox In Me.Controls.OfType(Of TextBox)()
                If ctrl.Text = "" Then Exit Sub
            Next
    
            'do what you want here if it is ok
        End Sub
    Thats' not the way to go about validating textboxes. You should be handling the Validating event of each TextBox. Then call ValidateChildren().

    Either way

    Code:
    Public Class Form1
        Private Function CheckFields()
            Return Me.Controls.OfType(Of TextBox)().Any(Function(tb) tb.Text = String.Empty)
        End Function
    End Class

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width