Results 1 to 7 of 7

Thread: [RESOLVED] Not handling IF statement comparisons properly

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2007
    Posts
    22

    Resolved [RESOLVED] Not handling IF statement comparisons properly

    I have a particular sub routine in VS 2010 that does not seem to be performing the comparisons in IF statement conditions properly. During debugging it seems to skip some entirely. A fellow developer and I have been looking at them for the past day or so and it seems like it should work just fine (they arent that complicated). I am hoping we are just burnt out and missing something obvious...

    In particular, it seems to fail when comparing strings. I had a FOR EACH loop that was comparing column values in a datatable, but it seemed like when I used the .ToString method it wouldnt ever trigger a match when comparing a .ToString item from a DataRow to a string value constant. So I had to make separate string variables and initialize them to items from the DataRow and THEN use those variables in the IF statement condition.

    Now I am facing another problem in the same sub routine where the IF statement condition wont even be processed. I have set BREAK points around the entire section of code, and it doesnt ever seem to trigger and break on specific conditions.


    For some addition Info the SubmitRequest() function returns the string of "success" when performed correctly.

    The condition that never triggers is:
    Code:
     Result = SubmitRequest(TestPhoneHome, TestZipCode)
    If Result = "success" Then                             
            UpdateRpvLog(TestFLID, "home", "submit", Date.Now.ToString)
    Else

    Any help would be GREATLY appreciated! thanks!!!



    See below code:
    Code:
    Private Sub RpvProcess()
            Dim Result As String = ""
            'For some reason Visual Studio would NOT correctly compare values from dr.item("<ColumnName>").ToString = "<String Expression>" properly - 2013-03-11 
            Dim TestFLID As String = ""
            Dim TestPhoneMobile As String = ""
            Dim TestPhoneHome As String = ""
            Dim TestMPhoneSubmitDate As String = ""
            Dim TestMPhoneResultDate As String = ""
            Dim TestMPhoneResult As String = ""
            Dim TestHPhoneSubmitDate As String = ""
            Dim TestHPhoneResultDate As String = ""
            Dim TestHPhoneResult As String = ""
            Dim TestZipCode As String = ""
    
    
    
            'TEMPORARILY DISABLED until loop issue resolved. do not want new records added.
            'For Each dr0 As DataRow In RetrievePhones().Rows
            '    If InsertRpvLogStart(dr0.Item("FinanceLeadID"), dr0.Item("PhoneMobile"), dr0.Item("PhoneHome"), dr0.Item("ZipCode")) = False Then
            '        WriteToLog("Failed to insert new record into tRpvLog")
            '        GoTo EndOfCheck
            '    End If
            'Next
    
    
    
    
    
    
    
    
            '////////Submitting phone number
            For Each dr As DataRow In RetrieveRpvPhones().Rows
                TestFLID = Trim(dr.Item("FinanceLeadID").ToString)
                TestPhoneMobile = Trim(dr.Item("PhoneMobile").ToString)
                TestPhoneHome = Trim(dr.Item("PhoneHome").ToString)
                TestMPhoneSubmitDate = Trim(dr.Item("MPhoneSubmitDate").ToString)
                TestMPhoneResultDate = Trim(dr.Item("MPhoneResultDate").ToString)
                TestMPhoneResult = Trim(dr.Item("MPhoneResult").ToString)
                TestHPhoneSubmitDate = Trim(dr.Item("HPhoneSubmitDate").ToString)
                TestHPhoneResultDate = Trim(dr.Item("HPhoneResultDate").ToString)
                TestHPhoneResult = Trim(dr.Item("HPhoneResult").ToString)
                TestZipCode = Trim(dr.Item("ZipCode").ToString)
    
    
                'see if Mobile phone is formatted correctly
    
    
                If IsNumeric(TestPhoneMobile) = False Or TestPhoneMobile.Length <> 10 Or TestMPhoneResult = "disconnected" Then
    
    
                    '******HOME PHONE **************
                    'set Mobile Phone Submit Result to "disconnected" if it fails general formatting
                    If TestMPhoneResult <> "disconnected" Then UpdateRpvLog(TestFLID, "mobile", "submit", , "disconnected")
    
                    'set Home Phone Submit Result to "disconnected" if it fails general formatting
                    If IsNumeric(TestPhoneHome) = False Or TestPhoneHome.Length <> 10 Then
                        UpdateRpvLog(TestFLID, "home", "submit", , "disconnected")
                    Else
    
                        'check if number was already submitted
                        If TestHPhoneSubmitDate = "" And TestHPhoneResult <> "disconnected" Then
                            Result = ""
                            Result = SubmitRequest(TestPhoneHome, TestZipCode)
    
                            If Result = "success" Then
                                UpdateRpvLog(TestFLID, "home", "submit", Date.Now.ToString)
                            Else
                                WriteToLog("FinanceLeadID - " & TestFLID & " : Home Phone =PUT= returned: " & Result)
                            End If
                        End If
                        'END of check if number was already submitted
    
    
                    End If
                    '******END OF HOME PHONE *******
                Else
    
                    '******MOBILE PHONE ************
                    'check if number was already submitted
                    If TestMPhoneSubmitDate = "" And TestMPhoneResult <> "disconnected" Then
                        Result = ""
                        Result = SubmitRequest(TestPhoneMobile, TestZipCode)
                        If Result = "success" Then
                            UpdateRpvLog(TestFLID, "mobile", "submit", Date.Now.ToString)
                        Else
                            WriteToLog("FinanceLeadID - " & TestFLID & " : Mobile Phone =PUT= returned: " & Result)
                        End If
    
                    End If
                    '******END OF MOBILE PHONE *****
                End If
    
    
    
            Next
            '//////// End of submit
    
    
            'Catch ex As Exception
            '    'TODO: finish exception handling. duplicate exception handling on the GET as well.
            'End Try
    
    
    
    
    
    
            '////////Get phone number status
            For Each dr As DataRow In RetrieveRpvPhones().Rows
    
                TestFLID = Trim(dr.Item("FinanceLeadID").ToString)
                TestPhoneMobile = Trim(dr.Item("PhoneMobile").ToString)
                TestPhoneHome = Trim(dr.Item("PhoneHome").ToString)
                TestMPhoneSubmitDate = Trim(dr.Item("MPhoneSubmitDate").ToString)
                TestMPhoneResultDate = Trim(dr.Item("MPhoneResultDate").ToString)
                TestMPhoneResult = Trim(dr.Item("MPhoneResult").ToString)
                TestHPhoneSubmitDate = Trim(dr.Item("HPhoneSubmitDate").ToString)
                TestHPhoneResultDate = Trim(dr.Item("HPhoneResultDate").ToString)
                TestHPhoneResult = Trim(dr.Item("HPhoneResult").ToString)
                TestZipCode = Trim(dr.Item("ZipCode").ToString)
    
                If TestMPhoneResult = "disconnected" Then
    
    
                    '******HOME PHONE **************
    
                    '--see if home phone has already been checked
                    If TestHPhoneResult = "" Then
    
                        Result = ""
                        Result = CheckResult(TestPhoneHome, TestZipCode)
    
                        If Result = "connected" Or Result = "disconnected" Then
                            UpdateRpvLog(TestFLID, "home", "check", Date.Now.ToString, Result)
                        Else
                            WriteToLog("FinanceLeadID - " & TestFLID & " : Home Phone =GET= returned: " & Result)
                        End If
    
    
                    End If
                    '******END OF HOME PHONE *******
                Else
    
                    '******MOBILE PHONE ************
                    '--see if mobile phone has already been checked
                    If TestMPhoneResult = "" Then
    
                        Result = ""
                        Result = CheckResult(TestPhoneMobile, TestZipCode)
    
                        If Result = "connected" Or Result = "disconnected" Then
                            UpdateRpvLog(TestFLID, "mobile", "check", Date.Now.ToString, Result)
                        Else
                            WriteToLog("FinanceLeadID - " & TestFLID & " : Mobile Phone =GET= returned: " & Result)
                        End If
    
    
                    End If
                    '******END OF MOBILE PHONE *****
                End If
    
    
    
            Next
            '//////// End of get status
    
    
    
    
    
            
    
    
    
    
    EndOfCheck:
        End Sub

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Not handling IF statement comparisons properly

    So we have code still using GoTo statements and it keeps 'skipping' code? Now what could possibly be the cause of that?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2007
    Posts
    22

    Re: Not handling IF statement comparisons properly

    dunfiddlin:
    I do not think that is the answer. The only GOTO statement is commented out, there is NO "on error resume next", and the even if there was a GOTO, the only destination is at the end of the code, which is not where the logic resumes when it skips the if statement. It always skips down to the
    Code:
     '////////Get phone number status
    section.

    I think the machine might be messed up, I rebuilt the project on a different machine and I do not seem to get the same results. Of course, I have not checked to see if the string comparison issue listed in the top of the commented code still occurs on the new machine.

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Not handling IF statement comparisons properly

    I'm not sure I understand what your problem is. Are you telling us that after the call to SubmitRequest() it just jumps out of your For Each loop? That doesn't make any sense. Are you sure that you even reach the line with the SubmitRequest() call?

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Not handling IF statement comparisons properly

    In all that you have posted, I see no SubmitRequest method. From what you have described, the most likely answer is that you are not returning the right thing. How did you diagnose this? What you should have done is put a breakpoint on the call to SubmitRequest and stepped through the code to see what was happening, but it isn't clear whether you did or not.

    One thing I will say is that you should never have a method that returns a string that you will compare. For one thing, comparing two strings is slow, but aside from that it is error prone. All you need is to change the spelling slightly, or just the capitalization, and your comparison will fail even when you didn't expect it to. Better by far would be to return a Boolean if there are only two possible results, or an integer (or Enum) if there are more.
    My usual boring signature: Nothing

  6. #6
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Not handling IF statement comparisons properly

    I can assure you that there is no bug in the "If" statement. If "Result" equaled "success" then it would work.

    Put a break point at this line,
    If Result = "success" Then
    Then check the value of Result.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Dec 2007
    Posts
    22

    Re: Not handling IF statement comparisons properly

    I only posted the code for the sub that was containing issues, not for SubmitRequest(). It would seem it was skipping logic only on the one machine.

    I did put break points in all areas suggested from the beginning, and it was just skipping over the one IF statement....until I open and ran project on a separate machine.

    The web service for which I referenced returns strings, that is why i was doing comparisons as such. I originally had all things set with the .ToLower ...but took them off as I was playing around in troubleshooting.

    I am going to say this issue was resolved as far as skipping logic since it seemingly only happened on the one problematic machine. There must have been a built application in memory that was missing something... I am not sure.. but the same project goes through the code when examined on a different machine.

Tags for this Thread

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