CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2001
    Location
    Canada
    Posts
    150

    Whats wrong with this code? Msgbox


    private Sub Drive1_Change()
    on error GoTo nodisk
    Dir1.Path = Drive1.Drive
    Text3.Text = Drive1.Drive

    nodisk: MsgBox "There is no disk in that Drive", vbRetryCancel, "a Phrozen error"

    If nodisk = vbRetry then
    Dir1.Path = Drive1.Drive
    Text3.Text = Drive1.Drive
    else
    Drive1.Drive = "c:\"
    Dir1.Path = "c:\"
    Text3.Text = "c:\"
    End If
    End Sub




    Thankz, Drew
    [email protected]?SUBJECT=I Love Your Stuff
    Thanks, Drew

  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Whats wrong with this code? Msgbox

    Either you have an error or not you will get the message "There is no disk in that Drive".

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Jan 2001
    Location
    Canada
    Posts
    150

    Re: Whats wrong with this code? Msgbox

    now VB is returning Errors all over the place in my project. whats wrong?

    Thankz, Drew
    [email protected]?SUBJECT=I Love Your Stuff
    Thanks, Drew

  4. #4
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    Re: Whats wrong with this code? Msgbox

    Put in Exit Sub after this line


    Text3.Text = Drive1.Drive



    David Paulson


  5. #5
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Whats wrong with this code? Msgbox

    Here is your routine revised somewhat.
    You need to do an Option Explicit to ensure all variables are defined. YOu need to Exit the Sub if everything goes well or you will fall into the error routine and execute it. The MsgBox needs to be a function so it can return the users response so I altered it as you can see

    option Explicit ' add this line
    Dim strTemp as string
    private Sub Drive1_Change()
    Dim noDisk as Integer ' add this line
    on error GoTo noDisk
    Dir1.Path = Drive1.Drive
    Text3.Text = Drive1.Drive
    Exit Sub ' Add this line
    noDisk:
    ' next line revised
    noDisk = MsgBox("There is no disk in that Drive", vbRetryCancel, "a Phrozen error")
    If noDisk = vbRetry then
    Dir1.Path = Drive1.Drive
    Text3.Text = Drive1.Drive
    else
    Drive1.Drive = "c:\"
    Dir1.Path = "c:\"
    Text3.Text = "c:\"
    End If
    End Sub




    John G

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

Featured