|
-
Apr 24th, 2013, 08:21 AM
#1
Thread Starter
New Member
My general Question thread about VB Coding! [General Questions & Answers]
Hello guys,
I am learning VB at the moment and I thought its better to do one thread for all questions instead of creating a lot of threads :-)
My first question:
How can I define a MsgBox after clicking on a button which contains a TextBox and other Buttons?
I mean I click on the button and it opens a new Window where I have a TextBox and Buttons.
Hope you get my problem^^
-
Apr 24th, 2013, 08:28 AM
#2
Addicted Member
Re: My general Question thread about VB Coding! [General Questions & Answers]
You can use either an InputBox or create your own.
-
Apr 24th, 2013, 08:29 AM
#3
Re: My general Question thread about VB Coding! [General Questions & Answers]
 Originally Posted by cocobrico
Hello guys,
I am learning VB at the moment and I thought its better to do one thread for all questions instead of creating a lot of threads :-)
My first question:
How can I define a MsgBox after clicking on a button which contains a TextBox and other Buttons?
I mean I click on the button and it opens a new Window where I have a TextBox and Buttons.
Hope you get my problem^^
It absolutely is not better to create one thread for every question you have. You create one thread per topic and you keep each thread to that single topic. Each thread should have a descriptive title. That way things are nice and easy for everyone, including the people asking the questions, the people answering the questions and the people who may search for that information days, months or even years in the future.
As for this question, it is not very clear. You can't define a MsgBox. MsgBox is a function that you can call to display a message window. If you want to display a message window then you can call MsgBox but you should instead call MessageBox.Show. You get to choose the message text, the title, the icon and the buttons, with the last two being chosen from some existing values.
If you want something more than that then you add a new form to your project and design it how you want it to look. You can then display it by creating an instance and calling its ShowDialog method. If you set the DialogResult properties of you Buttons then clicking those Buttons will cause ShowDialog to return that value, allowing you to determine what Button the user clicked, e.g.
Code:
Using dialogue As New Form1
If dialogue.ShowDialog() = DialogResult.OK Then
'The user clicked the OK button.
End If
End Using
-
Apr 24th, 2013, 08:30 AM
#4
Addicted Member
Re: My general Question thread about VB Coding! [General Questions & Answers]
 Originally Posted by cocobrico
Hello guys,
I am learning VB at the moment and I thought its better to do one thread for all questions instead of creating a lot of threads :-)
My first question:
How can I define a MsgBox after clicking on a button which contains a TextBox and other Buttons?
I mean I click on the button and it opens a new Window where I have a TextBox and Buttons.
Hope you get my problem^^
This should help ya 
http://msdn.microsoft.com/en-CA/libr...=vs.80%29.aspx
-
Apr 24th, 2013, 08:30 AM
#5
Re: My general Question thread about VB Coding! [General Questions & Answers]
 Originally Posted by MetalInquisitor
You can use either an InputBox or create your own.
The only time you should ever use InputBox is when you're a student doing an assignment and your teacher tells you to use it. Otherwise, it's cr*p and you should always create your own input form.
-
Apr 24th, 2013, 08:30 AM
#6
Re: My general Question thread about VB Coding! [General Questions & Answers]
 Originally Posted by Crzyrio
I repeat: do not use InputBox.
-
Apr 24th, 2013, 08:33 AM
#7
Addicted Member
Re: My general Question thread about VB Coding! [General Questions & Answers]
 Originally Posted by jmcilhinney
The only time you should ever use InputBox is when you're a student doing an assignment and your teacher tells you to use it. Otherwise, it's cr*p and you should always create your own input form.
Yeah, I've never used an InputBox myself, but it's there and newbies can use it in the meantime while they learn how to create their own.
-
Apr 24th, 2013, 08:38 AM
#8
Re: My general Question thread about VB Coding! [General Questions & Answers]
 Originally Posted by MetalInquisitor
Yeah, I've never used an InputBox myself, but it's there and newbies can use it in the meantime while they learn how to create their own.
They've got to create a main form anyway so why not create a second form to use as a dialogue? It's not like creating forms is some advanced skill that they can't tackle for some time. It's the very first thing they have to do to create a WinForms app so they're already doing it. There's just no reason to use garbage like InputBox.
-
Apr 24th, 2013, 08:42 AM
#9
Re: My general Question thread about VB Coding! [General Questions & Answers]
 Originally Posted by jmcilhinney
The only time you should ever use InputBox is when you're a student doing an assignment and your teacher tells you to use it. Otherwise, it's cr*p and you should always create your own input form.
Tell us how you really feel Jim(sic)
-
Apr 24th, 2013, 08:43 AM
#10
Thread Starter
New Member
Re: My general Question thread about VB Coding! [General Questions & Answers]
Thank you both! I defined a new form as you said. Now I have the problem that I can't connect from Form2 to buttons of Form1. How Can I do that?
Code:
If TextBox1.Text = "Some Text" Then
Button2.Enabled = True
Else
Button2.Enabled = False
End If
Button2 is a Button of Form1
-
Apr 24th, 2013, 08:59 AM
#11
Re: My general Question thread about VB Coding! [General Questions & Answers]
Form2 does have to know anything about Form1. Once ShowDialog returns, Form1 can enable or disable its own Button. If it needs data from Form2 to decide what to do then it gets that data from Form2 after ShowDialog returns. You can add properties to Form2 to expose whatever data is required, e.g.
Code:
Public ReadOnly Property TextBox1Text() As String
Get
Return TextBox1.Text
End Get
End Property
After ShowDialog returns, Form1 tests the value of the dialogue's TextBox1Text property and either enables or disables its own Button. Form2 never even has to know that Form1 exists.
-
Apr 24th, 2013, 09:07 AM
#12
Thread Starter
New Member
Re: My general Question thread about VB Coding! [General Questions & Answers]
Thanks but I think I dont got it^^ I need to Close Form2 with a Button like Me.Close() and also with the click of this button an other button in Form1 must be enabled So?! Please help.
P.S. I am a TOTAL Noob of VB...Started it yesterday
-
Apr 24th, 2013, 09:15 AM
#13
Re: My general Question thread about VB Coding! [General Questions & Answers]
No, the Button in Form2 needs to do one thing and one thing only: close Form2. As I said previously, if a Button on Form1 needs to be enabled or disabled then that should be done in Form1. In Form2 you do two things: close Form2 and expose any data required outside Form2. I showed you how to expose the data in my previous post. In Form1, you call ShowDialog to display Form2, then you get the data from Form2 and enabled or disable the Button.
-
Apr 24th, 2013, 09:20 AM
#14
Thread Starter
New Member
Re: My general Question thread about VB Coding! [General Questions & Answers]
So in form1 i have it like:
Code:
Using dialogue As New Form2
If dialogue.ShowDialog() = DialogResult.OK Then
If TextBox2.Text = "Some Text" Then
Button2.Enabled = True
Else
Button2.Enabled = False
End If
End If
End Using
But how can I say him that the TextBox2 is from Form2?
-
Apr 24th, 2013, 09:43 AM
#15
Re: My general Question thread about VB Coding! [General Questions & Answers]
-
Apr 24th, 2013, 09:45 AM
#16
Re: My general Question thread about VB Coding! [General Questions & Answers]
But how can I say him that the TextBox2 is from Form2?
By putting the name of Form2 before the control your interrogating:-
That's a fundamental of .net programming. Whenever you want to get at a property or method of a thing you do:-
or
The best argument against democracy is a five minute conversation with the average voter - Winston Churchill
Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd
-
Apr 24th, 2013, 09:45 AM
#17
Re: My general Question thread about VB Coding! [General Questions & Answers]
Or, while it's not the best way to do it, just qualify TextBox2 with dialogue because it's that form that it's a member of.
Also, before you go any further, I suggest that you work through this tutorial from start to finish:
http://www.homeandlearn.co.uk/NET/nets8p3.html
-
Apr 24th, 2013, 11:03 PM
#18
Re: My general Question thread about VB Coding! [General Questions & Answers]
 Originally Posted by jmcilhinney
There's just no reason to use garbage like InputBox.
This really made me laugh coming from you as I've never seen such a raw expression of disdain from you before. Now I know how to get you mad lol
-
Apr 25th, 2013, 08:00 AM
#19
Thread Starter
New Member
Re: My general Question thread about VB Coding! [General Questions & Answers]
Thank you guys! I am on a good way!! I got it working now ;-)
Next Problem:
How can I set some time for examle 3sec until and operation will be done?
Example:
Code:
Label1.Text = "Some Text!"
Label1.ForeColor = Color.Green
This will happen by clicking on a button but I want this to wait until like 3 secs... Thank you guys
-
Apr 25th, 2013, 08:14 AM
#20
Addicted Member
Re: My general Question thread about VB Coding! [General Questions & Answers]
 Originally Posted by cocobrico
Thank you guys! I am on a good way!! I got it working now ;-)
Next Problem:
How can I set some time for examle 3sec until and operation will be done?
Example:
Code:
Label1.Text = "Some Text!"
Label1.ForeColor = Color.Green
This will happen by clicking on a button but I want this to wait until like 3 secs... Thank you guys 
You could use a Timer for this. You will see it in your toolbox, just drag and drop it on to your form.
Then under the button click event(Where your taken to when you double click the button). You will have to initialize the button
Code:
Public Class Form1
Dim ticker As Integer = 0 ' to count seconds
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Timer1.Interval = 1000 'Sets the Timer to tick every second
Timer1.Enabled = True 'Starts the timer
End Sub
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick 'every second this function goes off
ticker += 1
If ticker = 3 Then
MsgBox("3 Seconds") 'Your code goes here
Timer.enabled = false 'Turns of the timer.
ticker = 0
End If
End Sub
End Class
Last edited by Crzyrio; Apr 25th, 2013 at 08:28 AM.
-
Apr 25th, 2013, 08:32 AM
#21
Thread Starter
New Member
Re: My general Question thread about VB Coding! [General Questions & Answers]
Thank you +Rep!
-
Apr 25th, 2013, 09:37 AM
#22
Re: My general Question thread about VB Coding! [General Questions & Answers]
 Originally Posted by cocobrico
Thank you guys! I am on a good way!! I got it working now ;-)
Next Problem:
How can I set some time for examle 3sec until and operation will be done?
Example:
Code:
Label1.Text = "Some Text!"
Label1.ForeColor = Color.Green
This will happen by clicking on a button but I want this to wait until like 3 secs... Thank you guys 
As I said back in post #3, please start a new thread when you have a question on a new topic.
-
Apr 25th, 2013, 10:03 AM
#23
Re: My general Question thread about VB Coding! [General Questions & Answers]
You will get the best answers if you have more eyes on the question. You will get the most eyes on the question by asking each question in its own thread with a good subject line (technically, I'm not entirely convinced that the subject line matters, but it is a courtesy to provide a descriptive title for the thread). Therefore, to get the best answers you should start a new thread for each new question. There's a fair amount of speculative psychology behind that conclusion, but I'll spare you.
My usual boring signature: Nothing
 
-
Apr 25th, 2013, 11:51 AM
#24
Thread Starter
New Member
Re: My general Question thread about VB Coding! [General Questions & Answers]
 Originally Posted by Shaggy Hiker
You will get the best answers if you have more eyes on the question. You will get the most eyes on the question by asking each question in its own thread with a good subject line (technically, I'm not entirely convinced that the subject line matters, but it is a courtesy to provide a descriptive title for the thread). Therefore, to get the best answers you should start a new thread for each new question. There's a fair amount of speculative psychology behind that conclusion, but I'll spare you.
I know what you mean, but actually everyone can find those answers & questions when he searches with the option "Search the entire post" so this thread is not 100% useless for others.
And when I have a little little new question I think its better to use this than an other thread.
New question:
Is there any possibility to open a Webadress instead of this code? :
Code:
System.Diagnostics.Process.Start("http://www.google.com")
-
Apr 25th, 2013, 12:06 PM
#25
Re: My general Question thread about VB Coding! [General Questions & Answers]
It is definitely not better.
The only 'good' thing about it is that it saves you a few seconds while posting the question.
There are several bad points, including:
- It wastes other peoples time, as they are likely to read (and think about) lots of posts that are no longer relevant. This can easily apply to hundreds of people, even if only a few are replying.
- Threads like this are nowhere near as useful for searches, no matter which search options are used (again, due to much irrelevant stuff).
- It often leads to confusion for the OP and others, as people tend to make extra comments about earlier topics, thus the 'current' topic gets swamped.
- ...
Whenever you have a question that is not directly related to what you asked in the first post, it does not belong in the thread - so please create a new thread for it.
As you aren't willing to comply with the requests to do that from multiple long-term members, I'm going to force you... this thread is now closed.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|