vbYesNo Message Box


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: vbYesNo Message Box

  1. #1
    Join Date
    Nov 2004
    Location
    UK
    Posts
    185

    vbYesNo Message Box

    Hi All,

    A very simple question, I have a msgbox which gives a user the option to save file to Floppy Disk YES or NO.
    Code:
    MsgBox "Please insert Floppy Disk:?", vbYesNo, "Export"
     FileCopy "d:\tmp\Test1.txt", "a:\data_" & Format(Now, "yyyy-mm-dd HhNn") & ".txt"
    From the above code it would copy the file even if the user selected the option NO.

    Not sure how to write a loop, i.e .

    if vbYesNo = Yes then
    FileCopy "d:\tmp\Test1.txt", "a:\data_" & Format(Now, "yyyy-mm-dd HhNn")
    end if
    Thankyou

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Look up the MsgBox function in VB's online help. At the top of the Help topic, there's a link labeled "Example."
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Sep 2004
    Location
    Northampton,United Kingdom
    Posts
    230

    Post

    Hi try this
    I was just working on a message box so I still had the code fresh in my mind

    hope that helps

    Drew

    Code:
    Dim Example As Integer
    Example = MsgBox "Please insert Floppy Disk:?", vbYesNo, "Export")
     
        If Example = VbYes Then
        FileCopy "d:\tmp\Test1.txt", "a:\data_" & Format(Now, "yyyy-mm-dd HhNn") & ".txt"
        end if
    
        If Example = VBNo Then
        ' what ever you want to do with a no reponse
        End If

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    The only way I would change Drew's example is to declare the Example variable as VbMsgBoxResult rather than Integer (and give it a more meaningful name ;-):

    Dim Response As VbMsgBoxResult
    Response = MsgBox ...

    If Response = vbYes...
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  5. #5
    Join Date
    Nov 2005
    Posts
    14
    'Try this...

    Dim Answer as integer
    Answer=Msgbox("Your prompt",vbyesno,"Your title")


    'if Answer = 6
    'then
    'Answer = vbyes

    'if Answer = 7
    'then
    'Answer = vbno



    .
    Last edited by sarun101; 11-09-2005 at 05:52 AM.

  6. #6
    Join Date
    Feb 2004
    Location
    Sydney, Australia
    Posts
    498
    Or simply ....

    Code:
    If MsgBox ("Please insert Floppy Disk:?", vbYesNo + vbQuestion, "Export") = VbYes Then
        FileCopy "d:\tmp\Test1.txt", "a:\data_" & Format(Now, "yyyy-mm-dd HhNn") & ".txt"
    Else
        'The user selected 'No'
    End If
    Note the '+ vbQuestion' - this gives a 'big' question mark on your message box.

    With Drew's example, the 'If Then' for 'Yes' should have an 'Else' instead of another 'If' following the first one ... ;-)
    Last edited by gupex; 11-08-2005 at 06:57 AM.

Similar Threads

  1. Message Box
    By lady_campari in forum VB Classic
    Replies: 2
    Last Post: 07-11-2005, 06:52 PM
  2. message box
    By computergeek in forum VB Classic
    Replies: 2
    Last Post: 04-29-2005, 04:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center