Connecting Tech Pros Worldwide Forums | Help | Site Map

Help with new window in InputBox

Newbie
 
Join Date: Mar 2007
Posts: 6
#1: Mar 19 '07
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

Dököll's Avatar
Moderator
 
Join Date: Nov 2006
Location: Upstate NY - US
Posts: 2,268
#2: Mar 20 '07

re: Help with new window in InputBox


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
Lives Here
 
Join Date: Oct 2006
Posts: 1,626
#3: Mar 20 '07

re: Help with new window in InputBox


Hi Kubo. I see that you need code urgently. Can you tell us why that is?
Newbie
 
Join Date: Mar 2007
Posts: 6
#4: Mar 20 '07

re: Help with new window in InputBox


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
Member
 
Join Date: Mar 2007
Location: Mississippi
Posts: 36
#5: Mar 20 '07

re: Help with new window in InputBox


a select case is where if there is more than one thing happening in a singel event it will have somthing there for it
Newbie
 
Join Date: Mar 2007
Posts: 6
#6: Mar 20 '07

re: Help with new window in InputBox


OK, thanks. Any ideas?
Dököll's Avatar
Moderator
 
Join Date: Nov 2006
Location: Upstate NY - US
Posts: 2,268
#7: Mar 21 '07

re: Help with new window in InputBox


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
Dököll's Avatar
Moderator
 
Join Date: Nov 2006
Location: Upstate NY - US
Posts: 2,268
#8: Mar 21 '07

re: Help with new window in InputBox


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...
yoda's Avatar
Needs Regular Fix
 
Join Date: Dec 2006
Location: canada
Posts: 273
#9: Mar 21 '07

re: Help with new window in InputBox


Quote:

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:

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
Newbie
 
Join Date: Mar 2007
Posts: 6
#10: Mar 21 '07

re: Help with new window in InputBox


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!!!
Newbie
 
Join Date: Mar 2007
Posts: 6
#11: Mar 21 '07

re: Help with new window in InputBox


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
SammyB's Avatar
Moderator
 
Join Date: Mar 2007
Location: Springfield, Ohio
Posts: 729
#12: Mar 21 '07

re: Help with new window in InputBox


Quote:

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?"
SammyB's Avatar
Moderator
 
Join Date: Mar 2007
Location: Springfield, Ohio
Posts: 729
#13: Mar 21 '07

re: Help with new window in InputBox


Quote:

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:
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
Dököll's Avatar
Moderator
 
Join Date: Nov 2006
Location: Upstate NY - US
Posts: 2,268
#14: Mar 22 '07

re: Help with new window in InputBox


Quote:

Originally Posted by SammyB

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.
Dököll's Avatar
Moderator
 
Join Date: Nov 2006
Location: Upstate NY - US
Posts: 2,268
#15: Mar 22 '07

re: Help with new window in InputBox


Quote:

Originally Posted by Kubo

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...
Dököll's Avatar
Moderator
 
Join Date: Nov 2006
Location: Upstate NY - US
Posts: 2,268
#16: Mar 22 '07

re: Help with new window in InputBox


Right, use vbNewLine to get to next line...
Dököll's Avatar
Moderator
 
Join Date: Nov 2006
Location: Upstate NY - US
Posts: 2,268
#17: Mar 22 '07

re: Help with new window in InputBox


Quote:

Originally Posted by Kubo

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
Newbie
 
Join Date: Mar 2007
Posts: 6
#18: Mar 22 '07

re: Help with new window in InputBox


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!!!
SammyB's Avatar
Moderator
 
Join Date: Mar 2007
Location: Springfield, Ohio
Posts: 729
#19: Mar 22 '07

re: Help with new window in InputBox


Quote:

Originally Posted by Kubo

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
Dököll's Avatar
Moderator
 
Join Date: Nov 2006
Location: Upstate NY - US
Posts: 2,268
#20: Mar 22 '07

re: Help with new window in InputBox


Fantastic, good luck Kubo, great help, Sammy...

See you soon!

Dököll
Reply