By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,101 Members | 1,387 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,101 IT Pros & Developers. It's quick & easy.

Help with new window in InputBox

P: 6
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:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim Test As String = ""
  3.         Dim Info As TextBox
  4.         Do While Test = ""
  5.             Test = InputBox( _
  6.             "Enter the food you want and press enter.", _
  7.             "What food?", "")
  8.                     Loop
  9.         MsgBox("This is the food: " & Test)
  10.  
  11.     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
Mar 19 '07 #1
Share this Question
Share on Google+
19 Replies


Dököll
Expert 100+
P: 2,364
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
Mar 20 '07 #2

100+
P: 1,646
Hi Kubo. I see that you need code urgently. Can you tell us why that is?
Mar 20 '07 #3

P: 6
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:
Expand|Select|Wrap|Line Numbers
  1. Dim Info As TextBox
Now I need to write what the "Info" will be set. I wrote:
Expand|Select|Wrap|Line Numbers
  1. 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:
Expand|Select|Wrap|Line Numbers
  1. If Test ("soup") Then
  2. 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
Mar 20 '07 #4

P: 36
a select case is where if there is more than one thing happening in a singel event it will have somthing there for it
Mar 20 '07 #5

P: 6
OK, thanks. Any ideas?
Mar 20 '07 #6

Dököll
Expert 100+
P: 2,364
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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Form_Load()
  3.  
  4. Dim s As String
  5.  
  6. s = InputBox("What type of food do you like?", "User input", "Add food here...") 'you can get rid of "Add food here..."
  7.  
  8. If s = "Pita" Then 'You'd have to figure out a case sensitive method
  9. Textbox1 = "Pita is good for ya"
  10.  
  11. Image1.Visible = True 'load images to form first
  12. Image2.Visible = False
  13.  
  14. ElseIf s = "Cantaloupes" Then
  15. Textbox2 = "Cantaloupes are excellent"
  16.  
  17. Image2.Visible = True
  18. Image1.Visible = False
  19.  
  20. Else
  21.  
  22. MsgBox "Please enter correct food items to continue"
  23.  
  24. Unload Me
  25. FormWithFoodHere.Show 'form with Food items and snapshots
  26. End If
  27.  
  28. End Sub
  29.  
  30.  
  31. 'You can revert to the InputBox by adding this code to a button, if you do not already have one on your form
  32.  
  33. Private Sub ReloadForUserInput_Click() 'button toget added info from user
  34. Unload Me
  35. FormWithFoodHere.Show 'form with Food items and snapshots
  36. End Sub
  37.  
  38.  
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
Mar 21 '07 #7

Dököll
Expert 100+
P: 2,364
Nuts, I did it again, two many notes:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Form_Load()
  3. Dim s As String
  4.  
  5. s = InputBox("What type of food do you like?", "User input", "Add food here...") 
  6. If s = "Pita" Then
  7. Textbox1 = "Pita is good for ya"
  8.  
  9. Image1.Visible = True
  10. Image2.Visible = False
  11.  
  12. ElseIf s = "Cantaloupes" Then
  13. Textbox2 = "Cantaloupes are excellent"
  14.  
  15. Image2.Visible = True
  16. Image1.Visible = False
  17.  
  18. Else
  19. MsgBox "Please enter correct food items to continue"
  20.  
  21.  
  22. Unload Me
  23. FormWithFoodHere.Show
  24. End If
  25.  
  26. End Sub
  27.  
  28.  
  29. Private Sub ReloadForUserInput_Click()
  30. Unload Me
  31. FormWithFoodHere.Show
  32. End Sub
  33.  
  34.  
There...
Mar 21 '07 #8

yoda
100+
P: 291
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:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim Test As String = ""
  3.         Dim Info As TextBox
  4.         Do While Test = ""
  5.             Test = InputBox( _
  6.             "Enter the food you want and press enter.", _
  7.             "What food?", "")
  8.                     Loop
  9.         MsgBox("This is the food: " & Test)
  10.  
  11.     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
Mar 21 '07 #9

P: 6
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!!!
Mar 21 '07 #10

P: 6
Oh come on... why me?!When I put
Expand|Select|Wrap|Line Numbers
  1. 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
Mar 21 '07 #11

SammyB
Expert 100+
P: 807
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?"
Mar 21 '07 #12

SammyB
Expert 100+
P: 807
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:
Expand|Select|Wrap|Line Numbers
  1.         Dim v As Object
  2.         v = InputBox("Gimme number:")
  3.         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
Mar 21 '07 #13

Dököll
Expert 100+
P: 2,364
Sample code for InputBox:
Expand|Select|Wrap|Line Numbers
  1.         Dim v As Object
  2.         v = InputBox("Gimme number:")
  3.         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.
Mar 21 '07 #14

Dököll
Expert 100+
P: 2,364
Oh come on... why me?!When I put
Expand|Select|Wrap|Line Numbers
  1. 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...
Mar 21 '07 #15

Dököll
Expert 100+
P: 2,364
Right, use vbNewLine to get to next line...
Mar 21 '07 #16

Dököll
Expert 100+
P: 2,364
Oh come on... why me?!When I put
Expand|Select|Wrap|Line Numbers
  1. 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
Quick way to get to form load is to fire your app:

(1) Got to View above, left
(2) Choose Code
(3) Look for form in General dropdown

Once form is selected, VB will add part of the code. You should delete the VB generated code then add what you have with Form_Load in it, that should set you right. Take Sammy's advice and modify to Textbox1.Text, Textbox2.Text respectively, and Pita should be good for you this time :-)

Have fun!

Dököll
Mar 21 '07 #17

P: 6
Wow, thanks, everything works now. Hey guys, now that I'm finished, to make an .exe file (only an exe file) of my project, where do I go? I want only the .exe file, and btw I'm using Visual Basic 2005 Express Edition. So could you help me with this final thing? I would appreciate it much if you did. Thanks for everything!!!
Mar 22 '07 #18

SammyB
Expert 100+
P: 807
Wow, thanks, everything works now. Hey guys, now that I'm finished, to make an .exe file (only an exe file) of my project, where do I go? I want only the .exe file, and btw I'm using Visual Basic 2005 Express Edition. So could you help me with this final thing? I would appreciate it much if you did. Thanks for everything!!!
See http://www.thescripts.com/forum/thread620624.html
Mar 22 '07 #19

Dököll
Expert 100+
P: 2,364
Fantastic, good luck Kubo, great help, Sammy...

See you soon!

Dököll
Mar 22 '07 #20

Post your reply

Sign in to post your reply or Sign up for a free account.