Help with new window in InputBox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kubo
    New Member
    • Mar 2007
    • 6

    Help with new window in InputBox

    Hello, hope you can help with a problem I have creating a program of mine.
    What I want is when I press a button, an InputBox will appear stating "Write the food you want and press ok". I've done this, but I want that after you press OK a new window will appear and according what food you wrote before some info will come in it, info that I will have put beforehand for each food (not many foods, 3-4). And in the info that is appeared, I also want to put a picture in it. How am I gonna do that?Here's my code:

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim Test As String = ""
            Dim Info As TextBox
            Do While Test = ""
                Test = InputBox( _
                "Enter the food you want and press enter.", _
                "What food?", "")
                        Loop
            MsgBox("This is the food: " & Test)
    
        End Sub
    For example, if somebody enters Spaghetti, then info on spaghetti will appear in new window. Also keep in mind that the info will be more than one line, so also tell me how I can seperate lines. Any other solutions that are of the same type are acceptable, as long as I can view the info with piture nicely. I need the code urgently, so please somebody answer soon!
    Thanks in advance
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    What happens when the user does not enter anything?

    It looks like you'll need a select case or if statement to tell the program what to do for each instance of food found. Especially when nothing is added to box. Do you agree?

    Dököll

    Comment

    • willakawill
      Top Contributor
      • Oct 2006
      • 1646

      #3
      Hi Kubo. I see that you need code urgently. Can you tell us why that is?

      Comment

      • Kubo
        New Member
        • Mar 2007
        • 6

        #4
        Well I've been offered for a project at school, my marks will get really high if I succeed.
        Also I don't understand what you mean with the "select case". Can you explain it a little? Also to put the "if" statement I need to select what the Info is. I wrote:
        Code:
        Dim Info As TextBox
        Now I need to write what the "Info" will be set. I wrote:
        Code:
        Info = TextBox.text ("the message here")
        But it gives me error.
        If I find a code that explains the "Info" then I'll put for example:
        Code:
        If Test ("soup") Then
        Info
        Or something like that, so the "Info" is executed. But the whole problem is how to write the info in the textbox and the open it when a specific food is entered. Oh, and I haven't tried pressing the cancel button before, as what I do when the InputBox appears is write something and see if I succeeded. But I haven't succeeded yet, although I have been trying for a week to get it to work as I want. Please give me a solution, also including how to put images and how to seperate lines. Please, as I need it badly.
        Thanks

        Comment

        • computerenigma13
          New Member
          • Mar 2007
          • 36

          #5
          a select case is where if there is more than one thing happening in a singel event it will have somthing there for it

          Comment

          • Kubo
            New Member
            • Mar 2007
            • 6

            #6
            OK, thanks. Any ideas?

            Comment

            • Dököll
              Recognized Expert Top Contributor
              • Nov 2006
              • 2379

              #7
              Hello Kubo!

              Try to incorporate the below if statement into your code. Mine is a little messy, just worked it out for you, seems to be working:

              Code:
              Private Sub Form_Load()
              
              Dim s As String
              
              s = InputBox("What type of food do you like?", "User input", "Add food here...") 'you can get rid of "Add food here..."
              
              If s = "Pita" Then 'You'd have to figure out a case sensitive method
              Textbox1 = "Pita is good for ya"
              
              Image1.Visible = True 'load images to form first
              Image2.Visible = False
              
              ElseIf s = "Cantaloupes" Then
              Textbox2 = "Cantaloupes are excellent"
              
              Image2.Visible = True
              Image1.Visible = False
              
              Else
              
              MsgBox "Please enter correct food items to continue"
              
              Unload Me
              FormWithFoodHere.Show 'form with Food items and snapshots
              End If
              
              End Sub
              
              
              'You can revert to the InputBox by adding this code to a button, if you do not already have one on your form
              
              Private Sub ReloadForUserInput_Click() 'button toget added info from user
              Unload Me
              FormWithFoodHere.Show 'form with Food items and snapshots
              End Sub
              If you do this while the form loads, it should be good. You can simply load the form then use the button command you have to fire up the Inputbox where needed, that'll be just fine too.

              Go get'em!

              Dököll

              Comment

              • Dököll
                Recognized Expert Top Contributor
                • Nov 2006
                • 2379

                #8
                Nuts, I did it again, two many notes:

                Code:
                Private Sub Form_Load()
                Dim s As String
                
                s = InputBox("What type of food do you like?", "User input", "Add food here...") 
                If s = "Pita" Then
                Textbox1 = "Pita is good for ya"
                
                Image1.Visible = True
                Image2.Visible = False
                
                ElseIf s = "Cantaloupes" Then
                Textbox2 = "Cantaloupes are excellent"
                
                Image2.Visible = True
                Image1.Visible = False
                
                Else
                MsgBox "Please enter correct food items to continue"
                
                
                Unload Me
                FormWithFoodHere.Show
                End If
                
                End Sub
                
                
                Private Sub ReloadForUserInput_Click()
                Unload Me
                FormWithFoodHere.Show
                End Sub
                There...

                Comment

                • yoda
                  Contributor
                  • Dec 2006
                  • 291

                  #9
                  Originally posted by Kubo
                  Hello, hope you can help with a problem I have creating a program of mine.
                  What I want is when I press a button, an InputBox will appear stating "Write the food you want and press ok". I've done this, but I want that after you press OK a new window will appear and according what food you wrote before some info will come in it, info that I will have put beforehand for each food (not many foods, 3-4). And in the info that is appeared, I also want to put a picture in it. How am I gonna do that?Here's my code:

                  Code:
                  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                          Dim Test As String = ""
                          Dim Info As TextBox
                          Do While Test = ""
                              Test = InputBox( _
                              "Enter the food you want and press enter.", _
                              "What food?", "")
                                      Loop
                          MsgBox("This is the food: " & Test)
                  
                      End Sub
                  For example, if somebody enters Spaghetti, then info on spaghetti will appear in new window. Also keep in mind that the info will be more than one line, so also tell me how I can seperate lines. Any other solutions that are of the same type are acceptable, as long as I can view the info with piture nicely. I need the code urgently, so please somebody answer soon!
                  Thanks in advance
                  or a more simpler idea would to put the code Dököll gave and add the info by making atext document in word or something with all the info on the food or u can put in your own code and say in if what ever the food is then open the text document u just made with all the info.

                  Yoda

                  Comment

                  • Kubo
                    New Member
                    • Mar 2007
                    • 6

                    #10
                    THANKS!!!Thanks a lot guys! I'll try it later to see if it works, and I'm sure it does!
                    Btw I thought of the document too but what I want is only the .exe file, nothing else. Anyway, thanks a lot, but can you please also tell me how can I seperate lines within the textbox? I think it has to do something with (Chr(10)) or something like that, but I haven't figured it out yet. But thanks, you don't know how happy I am.
                    Cheers!!!

                    Comment

                    • Kubo
                      New Member
                      • Mar 2007
                      • 6

                      #11
                      Oh come on... why me?!When I put
                      Code:
                      TextBox1 = "Pita is good for ya"
                      It gives me an error:
                      Value of type 'String' cannot be converted to 'System.Windows .Forms.TextBox' .
                      Can you explain me that and a solution to it?And yeah, I have a textbox.Also I haven't tested it yet, so how do you activate the InputBox? You press a button or what?Because before it I pressed the button and it came up. How do I do it now? Sorry for wanting those things immediatly, but I need them as I told you before.
                      Thanks once more

                      Comment

                      • SammyB
                        Recognized Expert Contributor
                        • Mar 2007
                        • 807

                        #12
                        Originally posted by Kubo
                        TextBox1 = "Pita is good for ya" gives me an error
                        Maybe Pita in not good for you! :confused:
                        Seriously, VB is now making you code correctly. It should be TextBox1.Text = "Pizza is good for you?"

                        Comment

                        • SammyB
                          Recognized Expert Contributor
                          • Mar 2007
                          • 807

                          #13
                          Originally posted by Kubo
                          how do you activate the InputBox? You press a button or what?Because before it I pressed the button and it came up. How do I do it now? Sorry for wanting those things immediatly, but I need them as I told you before.
                          Thanks once more
                          Sample code for InputBox:
                          Code:
                          		Dim v As Object
                          		v = InputBox("Gimme number:")
                          		MsgBox(v & " is correct")
                          >Sorry for wanting those things immediatly
                          If you are in a hurry, just type InputBox and press F1.
                          VB is not my primary language, so that's how I figured out the answer to your question. Have fun! --Sam

                          Comment

                          • Dököll
                            Recognized Expert Top Contributor
                            • Nov 2006
                            • 2379

                            #14
                            Originally posted by SammyB
                            Sample code for InputBox:
                            Code:
                            		Dim v As Object
                            		v = InputBox("Gimme number:")
                            		MsgBox(v & " is correct")
                            >Sorry for wanting those things immediatly
                            If you are in a hurry, just type InputBox and press F1.
                            VB is not my primary language, so that's how I figured out the answer to your question. Have fun! --Sam
                            Good catch, Sammy, sorry K man, .text is needed, I worte this up pretty quick for you.

                            Comment

                            • Dököll
                              Recognized Expert Top Contributor
                              • Nov 2006
                              • 2379

                              #15
                              Originally posted by Kubo
                              Oh come on... why me?!When I put
                              Code:
                              TextBox1 = "Pita is good for ya"
                              It gives me an error:
                              Value of type 'String' cannot be converted to 'System.Windows .Forms.TextBox' .
                              Can you explain me that and a solution to it?And yeah, I have a textbox.Also I haven't tested it yet, so how do you activate the InputBox? You press a button or what?Because before it I pressed the button and it came up. How do I do it now? Sorry for wanting those things immediatly, but I need them as I told you before.
                              Thanks once more
                              Add the code in your form load if the InputBox is the first thing you want to pop up. Just go in the dropdown and choose form, Form_Load will be added...

                              Comment

                              Working...