if statment...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?a2FyaW0=?=

    if statment...

    Hello All,
    I have this simple if statment, but under the (IF) there is that blue line
    for errors. what is wrong with it?


    Private Sub Button27_Click( ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button27.Click
    If
    System.Diagnost ics.Process.Sta rt("H:\")
    Else
    MsgBox("the drive is not linked")
    End If

    End Sub
  • kimiraikkonen

    #2
    Re: if statment...

    On Oct 3, 10:54 am, karim <ka...@discussi ons.microsoft.c omwrote:
    Hello All,
    I have this simple if statment, but under the (IF) there is that blue line
    for errors. what is wrong with it?
    >
    Private Sub Button27_Click( ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button27.Click
            If
                System.Diagnost ics.Process.Sta rt("H:\")
            Else
                MsgBox("the drive is not linked")
            End If
    >
        End Sub
    Hi,
    Because you're not evaluating any expression and an expression is
    truly expected, you must define a condition after "If" followed by
    "then" to get rid of error.
    Also it would be nice to explain what you're exactly aiming at doing.

    Look at:


    '-------------------------------------------------------
    If condition [ Then ]
    [ statements ]
    [ ElseIf elseifcondition [ Then ]
    [ elseifstatement s ] ]
    [ Else
    [ elsestatements ] ]
    End If

    ' or

    If condition Then [ statements ] [ Else [ elsestatements ] ]
    '------------------------------------------------------

    Thanks,

    Onur Güzel

    Comment

    • kimiraikkonen

      #3
      Re: if statment...

      On Oct 3, 11:26 am, karim <ka...@discussi ons.microsoft.c omwrote:
      hello kimiraikkonen
                     thanks for your help. to answer you question for what i'm
      aiming at, i'm trying to have a button to open a drive on the network. but i
      want it to display a msg if that drive is not mapped or linked to the current
      computer.
      Hi,
      I'm not fully sure about how to determine if a drive is mapped through
      an API call, however based on a logic, you may also consider using
      DriveInfo object to determine if the specified drive IsReady, then if
      it's ready, explore drive content:

      '---------------------------------
      Private Sub Button27_Click( ByVal sender As System.Object, _
      ByVal e As System.EventArg s) Handles Button27.Click

      ' Where letter "Z:" is supposed to be your network drive
      Dim mydrive As New IO.DriveInfo("Z :")
      If mydrive.IsReady = True Then
      ' If it's ready, explore drive using Windows Explorer
      System.Diagnost ics.Process.Sta rt("Z:")
      Else
      MsgBox("Drive not ready/unavailable")
      End If

      End Sub
      '------------------------------

      Hope that makes a bit sense,

      Onur Güzel

      Comment

      • Cor Ligthert[MVP]

        #4
        Re: if statment...

        Karim,
        System.Diagnost ics.Process.Sta rt("H:\")

        This does not give back automaticly a boolean.
        Although I don't know what the "H:\" is that you want to start.



        Cor



        "karim" <karim@discussi ons.microsoft.c omschreef in bericht
        news:8CEA9A20-1293-4A95-853B-115B0A2B002D@mi crosoft.com...
        Hello All,
        I have this simple if statment, but under the (IF) there is that blue line
        for errors. what is wrong with it?
        >
        >
        Private Sub Button27_Click( ByVal sender As System.Object, ByVal e As
        System.EventArg s) Handles Button27.Click
        If
        System.Diagnost ics.Process.Sta rt("H:\")
        Else
        MsgBox("the drive is not linked")
        End If
        >
        End Sub

        Comment

        • =?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=

          #5
          Re: if statment...

          karim wrote:
          hello kimiraikkonen
          thanks for your help. to answer you question for what i'm
          aiming at, i'm trying to have a button to open a drive on the network. but i
          want it to display a msg if that drive is not mapped or linked to the current
          computer.
          Use the DriveInfo.GetDr ives method to get an array of the drives that
          exist on the system. Loop through the array to check if the desired
          drive is available or not.

          --
          Göran Andersson
          _____
          Göran Anderssons privata hemsida.

          Comment

          • James Hahn

            #6
            Re: if statment...

            Try / Catch is the correct way to try to do something and present a message
            (or whatever) if it fails. Your code would therefore be:

            Try
            System.Diagnost ics.Process.Sta rt("H:\")
            <do whatever processing is needed>
            Catch exc as Exception
            MsgBox("the drive is not linked") 'Or a message based on the
            actual exception
            exit sub
            End try

            But note that a drive letter is not a process that can be started, so
            Process.Start is probably not what you need.

            "karim" <karim@discussi ons.microsoft.c omwrote in message
            news:0D960915-285D-491F-89EF-AFB22E207C5D@mi crosoft.com...
            >
            hello kimiraikkonen
            thanks for your help. to answer you question for what i'm
            aiming at, i'm trying to have a button to open a drive on the network. but
            i
            want it to display a msg if that drive is not mapped or linked to the
            current
            computer.

            Comment

            • =?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=

              #7
              Re: if statment...

              James Hahn wrote:
              Try / Catch is the correct way to try to do something and present a
              message (or whatever) if it fails.
              Unless of course you can determine beforehand if the operation would
              fail or not without having it to actually fail. In this case this is
              possible by checking if the drive is available or not.

              --
              Göran Andersson
              _____
              Göran Anderssons privata hemsida.

              Comment

              • Herfried K. Wagner [MVP]

                #8
                Re: if statment...

                "Göran Andersson" <guffa@guffa.co mschrieb:
                >Try / Catch is the correct way to try to do something and present a
                >message (or whatever) if it fails.
                >
                Unless of course you can determine beforehand if the operation would fail
                or not without having it to actually fail. In this case this is possible
                by checking if the drive is available or not.
                Well, the availability of a drive can change at any point of time, so
                checking if the drive is available beforehand does not replace exception
                handling for other statements accessing the drive.

                --
                M S Herfried K. Wagner
                M V P <URL:http://dotnet.mvps.org/>
                V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

                Comment

                • James Hahn

                  #9
                  Re: if statment...

                  Checking 'beforehand' is not recommended for a multitasking system.

                  "Göran Andersson" <guffa@guffa.co mwrote in message
                  news:%23Y28mSiJ JHA.728@TK2MSFT NGP04.phx.gbl.. .
                  James Hahn wrote:
                  >Try / Catch is the correct way to try to do something and present a
                  >message (or whatever) if it fails.
                  >
                  Unless of course you can determine beforehand if the operation would fail
                  or not without having it to actually fail. In this case this is possible
                  by checking if the drive is available or not.
                  >
                  --
                  Göran Andersson
                  _____
                  http://www.guffa.com

                  Comment

                  Working...