Help with new window in InputBox | Newbie | | Join Date: Mar 2007
Posts: 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: - 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
|  | Moderator | | Join Date: Nov 2006 Location: Upstate NY - US
Posts: 2,268
| | | 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
| | | 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
| | | 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:
Now I need to write what the "Info" will be set. I wrote: - 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: - 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
| | Member | | Join Date: Mar 2007 Location: Mississippi
Posts: 36
| | | 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
| | | re: Help with new window in InputBox
OK, thanks. Any ideas?
|  | Moderator | | Join Date: Nov 2006 Location: Upstate NY - US
Posts: 2,268
| | | 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: -
-
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
|  | Moderator | | Join Date: Nov 2006 Location: Upstate NY - US
Posts: 2,268
| | | re: Help with new window in InputBox
Nuts, I did it again, two many notes: -
-
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...
|  | Needs Regular Fix | | Join Date: Dec 2006 Location: canada
Posts: 273
| | | 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: - 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
| | Newbie | | Join Date: Mar 2007
Posts: 6
| | | 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
| | | re: Help with new window in InputBox
Oh come on... why me?!When I put - 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
|  | Moderator | | Join Date: Mar 2007 Location: Springfield, Ohio
Posts: 729
| | | 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?"
|  | Moderator | | Join Date: Mar 2007 Location: Springfield, Ohio
Posts: 729
| | | 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: - 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
|  | Moderator | | Join Date: Nov 2006 Location: Upstate NY - US
Posts: 2,268
| | | re: Help with new window in InputBox Quote:
Originally Posted by SammyB Sample code for InputBox: - 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.
|  | Moderator | | Join Date: Nov 2006 Location: Upstate NY - US
Posts: 2,268
| | | re: Help with new window in InputBox Quote:
Originally Posted by Kubo Oh come on... why me?!When I put - 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...
|  | Moderator | | Join Date: Nov 2006 Location: Upstate NY - US
Posts: 2,268
| | | re: Help with new window in InputBox
Right, use vbNewLine to get to next line...
|  | Moderator | | Join Date: Nov 2006 Location: Upstate NY - US
Posts: 2,268
| | | re: Help with new window in InputBox Quote:
Originally Posted by Kubo Oh come on... why me?!When I put - 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
| | | 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!!!
|  | Moderator | | Join Date: Mar 2007 Location: Springfield, Ohio
Posts: 729
| | | 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 |  | Moderator | | Join Date: Nov 2006 Location: Upstate NY - US
Posts: 2,268
| | | re: Help with new window in InputBox
Fantastic, good luck Kubo, great help, Sammy...
See you soon!
Dököll
|  | Similar Visual Basic 4 / 5 / 6 bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,471 network members.
|