Results 1 to 25 of 25

Thread: My general Question thread about VB Coding! [General Questions & Answers]

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    14

    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^^

  2. #2
    Addicted Member MetalInquisitor's Avatar
    Join Date
    Sep 2012
    Posts
    143

    Re: My general Question thread about VB Coding! [General Questions & Answers]

    You can use either an InputBox or create your own.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: My general Question thread about VB Coding! [General Questions & Answers]

    Quote Originally Posted by cocobrico View Post
    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
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Addicted Member
    Join Date
    Jan 2013
    Posts
    177

    Re: My general Question thread about VB Coding! [General Questions & Answers]

    Quote Originally Posted by cocobrico View Post
    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

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: My general Question thread about VB Coding! [General Questions & Answers]

    Quote Originally Posted by MetalInquisitor View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: My general Question thread about VB Coding! [General Questions & Answers]

    Quote Originally Posted by Crzyrio View Post
    I repeat: do not use InputBox.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Addicted Member MetalInquisitor's Avatar
    Join Date
    Sep 2012
    Posts
    143

    Re: My general Question thread about VB Coding! [General Questions & Answers]

    Quote Originally Posted by jmcilhinney View Post
    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.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: My general Question thread about VB Coding! [General Questions & Answers]

    Quote Originally Posted by MetalInquisitor View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: My general Question thread about VB Coding! [General Questions & Answers]

    Quote Originally Posted by jmcilhinney View Post
    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)
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  10. #10

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    14

    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

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  12. #12

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    14

    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

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  14. #14

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    14

    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?

  15. #15
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: My general Question thread about VB Coding! [General Questions & Answers]

    Read post #11.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  16. #16
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    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:-
    Code:
    dialogue.TextBox2
    That's a fundamental of .net programming. Whenever you want to get at a property or method of a thing you do:-
    Code:
    thing.property
    or
    Code:
    thing.method()
    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

  17. #17
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  18. #18
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: My general Question thread about VB Coding! [General Questions & Answers]

    Quote Originally Posted by jmcilhinney View Post
    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
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  19. #19

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    14

    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

  20. #20
    Addicted Member
    Join Date
    Jan 2013
    Posts
    177

    Re: My general Question thread about VB Coding! [General Questions & Answers]

    Quote Originally Posted by cocobrico View Post
    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.

  21. #21

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    14

    Re: My general Question thread about VB Coding! [General Questions & Answers]

    Thank you +Rep!

  22. #22
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: My general Question thread about VB Coding! [General Questions & Answers]

    Quote Originally Posted by cocobrico View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  23. #23
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    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

  24. #24

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    14

    Re: My general Question thread about VB Coding! [General Questions & Answers]

    Quote Originally Posted by Shaggy Hiker View Post
    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")

  25. #25
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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
  •  



Click Here to Expand Forum to Full Width