Consulting

Results 1 to 9 of 9

Thread: Solved: Boolean Working?

  1. #1
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location

    Solved: Boolean Working?

    Could someone please check the following boolean code and see if it is working properly on your computer. It is resulting in FALSE for me regardless of which button I click.

    [VBA]
    delOriginal = MsgBox(Prompt:="Delele the original forwarded email? ", _
    Buttons:=vbYesNo, Title:="Delete Original Contact?")
    If delOriginal = vbYes Then
    MsgBox "TRUE"
    Else: MsgBox "FALSE"
    End If
    [/VBA]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Works fine for me, XL2007, XP pro.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location
    Thanks. That's odd that it works for you. I'm in Outlook 2000 and it's reporting FALSE for both the Yes and No buttons.

  4. #4
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location
    I just tried it in a new clean module, with no other code, and it works for me. For some reason, there is something in my broader script that is causing it to misfire.

  5. #5
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    What is delOriginal dimensioned as?

  6. #6
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location
    Quote Originally Posted by mikerickson
    What is delOriginal dimensioned as?
    Boolean.

    [VBA]
    Sub delOriginal()

    Dim delOriginal As Boolean

    delOriginal = MsgBox(Prompt:="Delele the original forwarded email? ", _
    Buttons:=vbYesNo, Title:="Delete Original Email?")

    If delOriginal = True Then
    MsgBox "True"
    Else: MsgBox "False"
    End If

    End Sub

    [/VBA]

  7. #7
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location
    I restructured the code as follows and it seems to work fine now.

    [VBA]
    Sub delOriginal()
    Dim myPrompt As String
    myPrompt = "Do you want to delete the original forwarded email? "

    If MsgBox(prompt:=myPrompt, _
    Buttons:=vbYesNo, Title:="Delete Original Email?") = vbYes Then
    MsgBox "True"
    Else: MsgBox "False"
    End If

    End Sub
    [/VBA]

  8. #8
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    The value returned from a message box is data type Long, not Boolean.
    Change one line from the original code and all will be well

    [VBA]Sub delOriginal()

    Dim delOriginal As Long

    delOriginal = MsgBox(Prompt:="Delele the original forwarded email? ", _
    Buttons:=vbYesNo, Title:="Delete Original Email?")

    If delOriginal = True Then
    MsgBox "True"
    Else: MsgBox "False"
    End If

    End Sub [/VBA]

  9. #9
    VBAX Expert
    Joined
    Feb 2010
    Posts
    696
    Location
    Quote Originally Posted by mikerickson
    The value returned from a message box is data type Long, not Boolean.
    Change one line from the original code and all will be well

    [vba]Sub delOriginal()

    Dim delOriginal As Long

    delOriginal = MsgBox(Prompt:="Delele the original forwarded email? ", _
    Buttons:=vbYesNo, Title:="Delete Original Email?")

    If delOriginal = True Then
    MsgBox "True"
    Else: MsgBox "False"
    End If

    End Sub [/vba]
    Thanks. I'm glad you cleared that up. It was driving me crazy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •