Results 1 to 19 of 19

Thread: Quick Watch returns wrong value

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    Villiers, South Africa
    Posts
    301

    Quick Watch returns wrong value

    I have a very strange problem. I have this line of code:

    Code:
    Dim Phrase (1 to 300) as string
      if Phrase(2) = Phrase(287) then ...
    Now this doesn't work, even if Phrase(2) and Phrase(287) have exactly the same values ("Grade" in this case). When I break at this point and hover the mouse over Phrase(2) and Phrase(287), they both show "Grade". However, when I hit Shift + F9, Phrase(2) shows "Grade" but Phrase(287) shows "__. How can that be?

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Quick Watch returns wrong value

    Could you try something this and tell us the result?
    Code:
    Msgbox Phrase(2),,Phrase(287)
    if Phrase(2) = Phrase(287) then
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    Villiers, South Africa
    Posts
    301

    Re: Quick Watch returns wrong value

    Result:
    Grade

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    Villiers, South Africa
    Posts
    301

    Re: Quick Watch returns wrong value

    No, sorry... It shows "Grade" and "Grade"

  5. #5
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Quick Watch returns wrong value

    How about the title of the Msgbox? Nothing showed? If none then there is no value for Phrase(287).
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  6. #6
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Quick Watch returns wrong value

    Could you try this if it works then?

    Code:
    if CStr(Phrase(2)) = CStr(Phrase(287)) then
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  7. #7
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Quick Watch returns wrong value

    You may also try this.

    Code:
    If LCase$(Trim$(Phrase(2))) = LCase$(Trim$(Phrase(287))) Then
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    Villiers, South Africa
    Posts
    301

    Re: Quick Watch returns wrong value

    No, VB does not regard the two values as the same. Again CStr(Phrase(287)) gives a no value when using Shift&F9, but moving the mouse over it shows "Grade"

  9. #9
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Quick Watch returns wrong value

    Have you tried post #7?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    Villiers, South Africa
    Posts
    301

    Re: Quick Watch returns wrong value

    Yes; it also does not work.
    I have other similar lines of code which does work, it seems as if it is only Phrase(287) which gives this problem...

  11. #11
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Quick Watch returns wrong value

    How are you setting the value of Phrase(287)? There is also the StrComp function that you could try also.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  12. #12
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Quick Watch returns wrong value

    This is my best bet, there could be a vbNullChar in your Phrase(287), I tested this and here's what I came up with.
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
        Dim Phrase(1 To 300) As String
        Dim a As Long
        
        For a = LBound(Phrase) To UBound(Phrase)
            Phrase(a) = "Grade"
        Next
        
        'will work
        If Trim$(Phrase(2)) = Trim$(Phrase(287)) Then
            MsgBox "x"
        End If
            
        Phrase(287) = Phrase(287) & vbNullChar
        
        'will not work
        If Trim$(Phrase(2)) = Trim$(Phrase(287)) Then
            MsgBox "x"
        End If
        
        Phrase(287) = Replace$(Phrase(287), vbNullChar, vbNullString)
        
        'will work
        If Trim$(Phrase(2)) = Trim$(Phrase(287)) Then
            MsgBox "x"
        End If
    End Sub
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    Villiers, South Africa
    Posts
    301

    Re: Quick Watch returns wrong value

    Thanks for the help; I'm going to try it tomorrow. It is now over midnight in my country...

  14. #14
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Quick Watch returns wrong value

    You could also try to determine what consists the Phrase(287).

    Code:
    Private Sub Test()
        ExtractCharacters Phrase(287)
    End Sub
    
    Private Sub ExtractCharacters(ByVal s As String)
        Dim a As Long
        For a = 1 To Len(s)
            Debug.Print Asc(Mid$(s, a, 1))
        Next
    End Sub
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  15. #15

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    Villiers, South Africa
    Posts
    301

    Re: Quick Watch returns wrong value

    Yes, just before I read your post, I tried this and Len(Phrase(2)) = 5, but Len(Phrase(287)) = 6. However, Trim does not change the lengths.

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2001
    Location
    Villiers, South Africa
    Posts
    301

    Re: Quick Watch returns wrong value

    I also tried the code that dee-u suggested and the first character of Phrase(287) is Chr(10). I think I understand now...

  18. #18
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Quick Watch returns wrong value

    See post #14 and #12.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  19. #19
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Quick Watch returns wrong value

    Try this then
    Code:
    Phrase(287) = Replace$(Phrase(287), Chr$(10), vbNullString)
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

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