Results 1 to 7 of 7

Thread: jump in code?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2004
    Location
    Utah, USA
    Posts
    353

    jump in code?

    Is there a way to jump to a different spot in my coding if I get to this?:

    Catch exp As Exception

    Thanks!

    Brenda

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    well what do you mean by JUMP??? it sounds like a dreaded GOTO if you are talking about what I think you are talking about... but lets say you had a sub routine to handle something, you could certainly call it from the catch block
    VB Code:
    1. Try
    2.     'Code here
    3. Catch exp As Exception
    4.     MySubroutine 'calls subroutine to do stuff
    5. End Try
    but please clarify what you mean exactly.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2004
    Location
    Utah, USA
    Posts
    353
    OK. This is what I have:

    VB Code:
    1. ElseIf dr("PartNumber") = 5 Then
    2.             Dim Insert_case As String
    3.             Insert_case = "INSERT INTO tblCapRec (CaseNumber,PartNumber,Status,InGDB, " & _
    4.             "DocsOrdered,DocsHere,AppHere,Ubum,Suspended,Trace,SentToHUD,SentToTSI, " & _
    5.             "SentToCredit,SpanishCase,PropAddress,PropCity,PropState,PropZipCode,Updated, " & _
    6.             "MailKey,MailedFirst,MortgageAmt,PaidUpFront,EndorseDate,Term,MatureDate,EncumDate, " & _
    7.             "HoldingMor,ServingMor,RcvdFromOld,RcvdFromRegular,RcvdFromRtn,RcvdFrom2s,RefundAmt, " & _
    8.             "RateCharged,FeeAmount,RemainingDue,AfterFee,AmtPaid,LateFees,LastName,FirstName, " & _
    9.             "MailAddress,MailCity,MailState,MailZipCode,HomePhone)  " & _
    10.             "SELECT CaseNumber,6,2,0,0,0,0,0,0,0,0,0,0,0,PropAddress,PropCity,PropState, " & _
    11.             "PropZipCode,GETDATE(),1,GETDATE(),MortgageAmt,PaidUpFront,EndorseDate,Term, " & _
    12.             "MatureDate,EncumDate,HoldingMor,ServingMor,0,0,0,0,RefundAmt,RateCharged, " & _
    13.             "FeeAmount,RemainingDue,AfterFee,0,0,'" & txtLastName.Text & "','" & txtFirstName.Text & "', " & _
    14.             "'" & txtAddress.Text & "','" & txtCity.Text & "','" & cbStates.Text & "', " & _
    15.             "'" & txtZipCode.Text & "','" & txtPhone.Text & "'  " & _
    16.             "FROM tblCapRec WHERE CaseNumber = '" & g_CaseNum & "' AND PartNumber = " & g_PartNum & ""
    17.  
    18.             Dim SqlConn1 As SqlConnection = New SqlConnection(strConnectionString)
    19.             Dim cmdSqlCommand1 As SqlCommand = New SqlCommand(Insert_case, SqlConn1)
    20.             Try
    21.                 g_PartNum = 6
    22.                 cmdSqlCommand1.Connection.Open()
    23.                 cmdSqlCommand1.ExecuteScalar()
    24.             [color=red]Catch exp As Exception[/color]
    25.                 MessageBox.Show(exp.Message)
    26.                 Exit Sub
    27.             Finally
    28.                 If SqlConn1.State = ConnectionState.Open Then
    29.                     SqlConn1.Close()
    30.                 End If
    31.             End Try

    If it gets to the Catch Exception, I would like to jump to the next ElseIf Statement. Or is that bad to do?

    Brenda

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    you cant do that without a goto, is goto even supported anymore in .net?? If it is its for backwards compatibility (very backwards). even if it was, it would be HIGHLY HIGHLY NOT RECOMMENDED to use it... that being said, what is the next elseif anyway? if it is just some cleanup code or something like that, put it in its own subroutine, so you can call it from wherever you need to call it from and you wont have nasty spaghetti code.

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by kleinma
    you cant do that without a goto, is goto even supported anymore in .net??
    Yes it is.

    brendalisalowe, what happens in the next ElseIf statement? Would that ElseIf block be called ONLY if there's an exception?

    Also, shouldn't you be checking for SQLException?

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2004
    Location
    Utah, USA
    Posts
    353
    So this is better to do?:

    Catch exp As SqlException


    I need to think more about what I am trying to do in my coding with the ElseIF. I'll let you know what I think later today. Thanks!

    Brenda

  7. #7
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Your next elseif should be checking for another part #, not checking for some database error.
    Besides the subroutine method described above, you can throw the exception and have it caught elsewhere. But the next elseif isn't a good place to do that.
    Tengo mas preguntas que contestas

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