Error handling

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Spudgun

    Error handling

    Ive written a pretty basic program for work that offers the user a number of
    buttons to selct that then open an Excel Template.

    The code is basically as shown below, the first section sets the base path
    for the Templates and gives the user the option to cahnge should the network
    position move. The second part is the code for loading the file on
    activation of the corresponding button.

    All very simple and functional.

    What it doesnt od though is raise an error if the template does not exist.

    I would be grateful if someone could give me a clue as to how to go about
    this.

    Private Sub Menu_Click()
    Dim sNewPath As String

    sNewPath = InputBox("Enter new location of template files:", ,
    "\\agb-dds01\hdd3\Requ est-templates\")

    If Len(Trim(sNewPa th)) > 0 Then
    m_sBasePath = sNewPath
    MsgBox "Base Path changed."
    End If
    End Sub

    Private Sub Command1_Click( )

    If Right$(m_sBaseP ath, 1) <> "\" Then
    m_sBasePath = m_sBasePath & "\"
    End If

    ShellEx m_sBasePath & "Static Airbag Template.xlt", , , , "open",
    Me.hWnd
    Unload Me

    End Sub

    Drink and drugs cause amnesia and other things I can't remember... Another
    meaningless e-mail brought to you by Dave Wateridge PLC. A member of the Sad
    Bastard Group





  • Steve Gerrard

    #2
    Re: Error handling


    "Spudgun" <not@here.com > wrote in message
    news:chvp27$igj $1@hercules.bti nternet.com...
    | Ive written a pretty basic program for work that offers the user a
    number of
    | buttons to selct that then open an Excel Template.
    |
    | The code is basically as shown below, the first section sets the base
    path
    | for the Templates and gives the user the option to cahnge should the
    network
    | position move. The second part is the code for loading the file on
    | activation of the corresponding button.
    |
    | All very simple and functional.
    |
    | What it doesnt od though is raise an error if the template does not
    exist.
    |
    | I would be grateful if someone could give me a clue as to how to go
    about
    | this.
    |

    If Dir(m_sBasePath & "Static Airbag Template.xlt") = "" Then
    Msgbox "Can't find " & m_sBasePath & "Static Airbag Template.xlt"
    Else
    ShellEx m_sBasePath & "Static Airbag Template.xlt", , , , "open",
    Me.hWnd
    End If


    Comment

    • Spudgun

      #3
      Re: Error handling

      Using that code returned the following error message

      Run time error 52 - bad file name or number, this relates to the line
      starting If Dir(m_s....etc

      I almost had a psychic girlfriend but she left me before we met. Another
      meaningless e-mail brought to you by Dave Wateridge PLC. A member of the Sad
      Bastard Group




      "Steve Gerrard" <mynamehere@com cast.net> wrote in message
      news:QuqdnV-69sRnMd7cRVn-pQ@comcast.com. ..[color=blue]
      >
      > "Spudgun" <not@here.com > wrote in message
      > news:chvp27$igj $1@hercules.bti nternet.com...
      > | Ive written a pretty basic program for work that offers the user a
      > number of
      > | buttons to selct that then open an Excel Template.
      > |
      > | The code is basically as shown below, the first section sets the base
      > path
      > | for the Templates and gives the user the option to cahnge should the
      > network
      > | position move. The second part is the code for loading the file on
      > | activation of the corresponding button.
      > |
      > | All very simple and functional.
      > |
      > | What it doesnt od though is raise an error if the template does not
      > exist.
      > |
      > | I would be grateful if someone could give me a clue as to how to go
      > about
      > | this.
      > |
      >
      > If Dir(m_sBasePath & "Static Airbag Template.xlt") = "" Then
      > Msgbox "Can't find " & m_sBasePath & "Static Airbag Template.xlt"
      > Else
      > ShellEx m_sBasePath & "Static Airbag Template.xlt", , , , "open",
      > Me.hWnd
      > End If
      >
      >[/color]


      Comment

      • build

        #4
        Re: Error handling

        Steve Gerrard wrote:
        [color=blue]
        > "Spudgun" <not@here.com > wrote in message
        > news:chvp27$igj $1@hercules.bti nternet.com...
        > | Ive written a pretty basic program for work that offers the user a
        > number of
        > | buttons to selct that then open an Excel Template.
        > |
        > | The code is basically as shown below, the first section sets the base
        > path
        > | for the Templates and gives the user the option to cahnge should the
        > network
        > | position move. The second part is the code for loading the file on
        > | activation of the corresponding button.
        > |
        > | All very simple and functional.
        > |
        > | What it doesnt od though is raise an error if the template does not
        > exist.
        > |
        > | I would be grateful if someone could give me a clue as to how to go
        > about
        > | this.
        > |
        >
        > If Dir(m_sBasePath & "Static Airbag Template.xlt") = "" Then
        > Msgbox "Can't find " & m_sBasePath & "Static Airbag Template.xlt"
        > Else
        > ShellEx m_sBasePath & "Static Airbag Template.xlt", , , , "open",
        > Me.hWnd
        > End If
        >[/color]
        G'day Steve,
        Sorry to jump into someone else's thread.
        2 quick questions.
        1). Why the "Me.hWnd"?
        2). How would I check if a folder existed?
        tia
        build

        Comment

        • Steve Gerrard

          #5
          Re: Error handling


          "build" <build02@datafa st.net.au> wrote in message
          news:4144da38$1 @news.alphalink .com.au...
          | Steve Gerrard wrote:
          |
          | > If Dir(m_sBasePath & "Static Airbag Template.xlt") = "" Then
          | > Msgbox "Can't find " & m_sBasePath & "Static Airbag
          Template.xlt"
          | > Else
          | > ShellEx m_sBasePath & "Static Airbag Template.xlt", , , ,
          "open",
          | > Me.hWnd
          | > End If
          | >
          | G'day Steve,
          | Sorry to jump into someone else's thread.
          | 2 quick questions.
          | 1). Why the "Me.hWnd"?
          | 2). How would I check if a folder existed?
          | tia
          | build

          1. ShellEx is a Windows API call. If a Windows API call asks for a
          window handle, you give it a window handle, and don't ask why. :)

          2. Here is a simple function demonstrating use of Dir and GetAttr:

          Private Sub Command1_Click( )
          CheckPath "C:\Program Files"
          CheckPath "C:\Windows\not epad.exe"
          CheckPath "Sheer Nonsense"
          End Sub

          Private Sub CheckPath(Path As String)
          If Dir(Path, vbDirectory) = "" Then
          MsgBox Path & " not found"
          ElseIf (GetAttr(Path) And vbDirectory) = 0 Then
          MsgBox Path & " is a file"
          Else
          MsgBox Path & " is a folder"
          End If
          End Sub





          Comment

          • build

            #6
            Re: Error handling (THX)

            Steve Gerrard wrote:[color=blue]
            > "build" <build02@datafa st.net.au> wrote in message
            > news:4144da38$1 @news.alphalink .com.au...
            > | Steve Gerrard wrote:
            > | > If Dir(m_sBasePath & "Static Airbag Template.xlt") = "" Then
            > | > Msgbox "Can't find " & m_sBasePath & "Static Airbag
            > | > Template.xlt"
            > | > Else
            > | > ShellEx m_sBasePath & "Static Airbag Template.xlt", , , ,
            > | > "open",
            > | > Me.hWnd
            > | > End If
            > | >
            > | G'day Steve,
            > | Sorry to jump into someone else's thread.
            > | 2 quick questions.
            > | 1). Why the "Me.hWnd"?
            > | 2). How would I check if a folder existed?
            > | tia
            > | build
            >
            > 1. ShellEx is a Windows API call. If a Windows API call asks for a
            > window handle, you give it a window handle, and don't ask why. :)
            >
            > 2. Here is a simple function demonstrating use of Dir and GetAttr:
            >
            > Private Sub Command1_Click( )
            > CheckPath "C:\Program Files"
            > CheckPath "C:\Windows\not epad.exe"
            > CheckPath "Sheer Nonsense"
            > End Sub
            >
            > Private Sub CheckPath(Path As String)
            > If Dir(Path, vbDirectory) = "" Then
            > MsgBox Path & " not found"
            > ElseIf (GetAttr(Path) And vbDirectory) = 0 Then
            > MsgBox Path & " is a file"
            > Else
            > MsgBox Path & " is a folder"
            > End If
            > End Sub
            >[/color]
            Thx Steve, just what I was after, appreciate your taking the time :-)

            Comment

            Working...