none
Why does it hit this else statement and how to fix it? RRS feed

  • Question

  • So I am new to visual basic and I need to know what is happening in this snippet of code and why it won't hit the if statement.

    Dim loWCChecks As WCChecks = New WCChecks
                    'Save the check records in the HOLD table
                    Dim lbHoldChecks As Boolean = False
                    lbHoldChecks = loWCChecks.LoadPrintCheckHold(loUser.Account.ToUpper, Now.ToShortDateString, liHoldCount)
                    If lbHoldChecks = True Then
                        lsMessage = liHoldCount & " checks saved in hold table for reprint if necessary."
                    Else
                        lsErrorMessage = "Checks were not saved in hold table."
                    End If

    Friday, June 24, 2016 2:02 PM

Answers

  • Mostly if you have ostriched your code with a head in the sand part.

    It looks like this

    Try
    ..... your code
    Catch
    'if it goes wrong, then I don't care
    End Try

    It is not the cause of the problem but put Option Strict On in top of your code, the errors will be shown better


    Success
    Cor


    Friday, June 24, 2016 2:13 PM
  • Marshall,

    Put a break point in and step into the code, line by line. You'll likely figure out what's going on with it, and you'll have learned something in the process.


    In the middle of difficulty ... lies opportunity. -- Albert Einstein

    Friday, June 24, 2016 2:13 PM
  • Check What data you have store to your lbHoldChecks Variables.

    you have store wrong data. in this line.

      lbHoldChecks = loWCChecks.LoadPrintCheckHold(loUser.Account.ToUpper, Now.ToShortDateString, liHoldCount)
    

    Here is problem. where your software exit to sub with error, So After This line no code is executed.

    So Your If statement is not working.

    If you want to know error Then use your code Like this.

    Try
    
    Dim loWCChecks As WCChecks = New WCChecks
                    
                    Dim lbHoldChecks As Boolean = False
                    lbHoldChecks = loWCChecks.LoadPrintCheckHold(loUser.Account.ToUpper, Now.ToShortDateString, liHoldCount)
                    If lbHoldChecks = True Then
                        lsMessage = liHoldCount & " checks saved in hold table for reprint if necessary."
                    Else
                        lsErrorMessage = "Checks were not saved in hold table."
                    End If
    
    Catch ex As Exception
    
    msgbox (Ex.message)
    
    End Try
    
    
    

    If you like it. mark as answer.

    Thanks

    Friday, June 24, 2016 8:53 PM

All replies

  • Mostly if you have ostriched your code with a head in the sand part.

    It looks like this

    Try
    ..... your code
    Catch
    'if it goes wrong, then I don't care
    End Try

    It is not the cause of the problem but put Option Strict On in top of your code, the errors will be shown better


    Success
    Cor


    Friday, June 24, 2016 2:13 PM
  • Marshall,

    Put a break point in and step into the code, line by line. You'll likely figure out what's going on with it, and you'll have learned something in the process.


    In the middle of difficulty ... lies opportunity. -- Albert Einstein

    Friday, June 24, 2016 2:13 PM
  • Check What data you have store to your lbHoldChecks Variables.

    you have store wrong data. in this line.

      lbHoldChecks = loWCChecks.LoadPrintCheckHold(loUser.Account.ToUpper, Now.ToShortDateString, liHoldCount)
    

    Here is problem. where your software exit to sub with error, So After This line no code is executed.

    So Your If statement is not working.

    If you want to know error Then use your code Like this.

    Try
    
    Dim loWCChecks As WCChecks = New WCChecks
                    
                    Dim lbHoldChecks As Boolean = False
                    lbHoldChecks = loWCChecks.LoadPrintCheckHold(loUser.Account.ToUpper, Now.ToShortDateString, liHoldCount)
                    If lbHoldChecks = True Then
                        lsMessage = liHoldCount & " checks saved in hold table for reprint if necessary."
                    Else
                        lsErrorMessage = "Checks were not saved in hold table."
                    End If
    
    Catch ex As Exception
    
    msgbox (Ex.message)
    
    End Try
    
    
    

    If you like it. mark as answer.

    Thanks

    Friday, June 24, 2016 8:53 PM