CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2009
    Posts
    27

    New to VB, need help with Try/Catch

    Hi there,

    I'm familiar with Visual C# and the try/catch for that but I cannot seem to figure out how to do the same thing in VB.

    Basically I can't figure out how to get the try/catch to work with text boxes and input from the user and whatnot.

    I've tried setting the textbox.text property = "" but that has no use, I've been trying to find something on google about it but I cannot seem to find a single thing about textbox try/catch statements. Is it possible to do it with text boxes?

  2. #2
    Join Date
    Sep 2000
    Location
    FL
    Posts
    1,452

    Re: New to VB, need help with Try/Catch

    It is basically the same as c#.

    Paste your C# code and we should be able to translate it for you.

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: New to VB, need help with Try/Catch

    Have a look at this FAQ :

    http://www.codeguru.com/forum/showthread.php?t=383057

    The FAQ's are still growing, unfortunately too slow for my liking, but still. Here are also some VB.NET FAQ's :

    http://www.codeguru.com/forum/forumdisplay.php?f=76

  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: New to VB, need help with Try/Catch

    Having seen you posted question in Vb 6.0 forum, let me clarify this:

    Try..Catch...Finally...End Try is in Visual Basic Dot Net

    You will not find it in Vb 6.0, where you have to use
    On Error statement
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  5. #5
    Join Date
    Sep 2009
    Posts
    27

    Re: New to VB, need help with Try/Catch

    Code:
    Try
                txtBoxAmount.Text = String.Empty
            Catch ex As Exception
                Beep()
                MessageBox.Show("Error: ")
            End Try
    I can't seem to find out how to make it throw the error when I push a button with a blank text box field. It shows no errors but the message box will not pop up, what am I doing wrong?

  6. #6
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: New to VB, need help with Try/Catch

    you stated in your code that textbox should be assigned an empty
    string, which is perfectly legal and throw no error at all.
    If you want to throw exception when it happens, use If
    to test, and then throw your exception...

    hile debugging, debugger will intercept the exception alting
    execution of code, you will have to make it run clicking on green arrow...

    Code:
    Try
            if     String.IsNullOrEmpty(txtBoxAmount.Text.Trim) then
                 throw new exception ("The text cannot be empty!")
            end if
            Catch ex As Exception
                Beep()
                MessageBox.Show("Error: " & ex.message())
     End Try
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

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

Featured