473,396 Members | 2,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.EventArgs) Handles Button27.Click
If
System.Diagnostics.Process.Start("H:\")
Else
MsgBox("the drive is not linked")
End If

End Sub
Oct 3 '08 #1
8 1097
On Oct 3, 10:54*am, karim <ka...@discussions.microsoft.comwrote:
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.EventArgs) Handles Button27.Click
* * * * If
* * * * * * System.Diagnostics.Process.Start("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:
http://msdn.microsoft.com/en-us/libr...bs(VS.80).aspx

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

' or

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

Thanks,

Onur Güzel
Oct 3 '08 #2
On Oct 3, 11:26*am, karim <ka...@discussions.microsoft.comwrote:
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.EventArgs) 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.Diagnostics.Process.Start("Z:")
Else
MsgBox("Drive not ready/unavailable")
End If

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

Hope that makes a bit sense,

Onur Güzel
Oct 3 '08 #3
Karim,
System.Diagnostics.Process.Start("H:\")

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

http://www.vb-tips.com/StartProcess.aspx

Cor

"karim" <ka***@discussions.microsoft.comschreef in bericht
news:8C**********************************@microsof t.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.EventArgs) Handles Button27.Click
If
System.Diagnostics.Process.Start("H:\")
Else
MsgBox("the drive is not linked")
End If

End Sub
Oct 3 '08 #4
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.GetDrives 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
_____
http://www.guffa.com
Oct 3 '08 #5
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.Diagnostics.Process.Start("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" <ka***@discussions.microsoft.comwrote in message
news:0D**********************************@microsof t.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.
Oct 4 '08 #6
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
Oct 4 '08 #7
"Göran Andersson" <gu***@guffa.comschrieb:
>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/>

Oct 4 '08 #8
Checking 'beforehand' is not recommended for a multitasking system.

"Göran Andersson" <gu***@guffa.comwrote in message
news:%2***************@TK2MSFTNGP04.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
Oct 4 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: e_AK_05 | last post by:
I have a question and I can't figure out how to do it. I have a select statment : SELECT table1.* AS table1.*, table2.* AS table2.* FROM table1, table2 WHERE 1 this does not work...for me at...
1
by: Joe Saliba | last post by:
Hi, would like to know how to write a crosstable select statment in sql server2000 where having: - ItemNumber, ItemDescription, ItemColor, ItemSize as rows - Stores as columns - Qty * Netttc...
9
by: Appel | last post by:
Hallo i have a problem to add to string with a SQL statement. My Table : Tablename NAMES: | Name1 | Name2 | Name3 | John Meyer I search for a SQL statment that update Name3.
1
by: Maria | last post by:
Hello I have not used db2 in a long time, and I have this very long insert script, which is giving me an error of duplicated inserts. My question is how can I put something in the statment so...
8
by: 73blazer | last post by:
Hello, I'm looking for a way to make some of my insert templates more readable by placing comments in between the values. I cannot seem to find a way to do this with DB2, is there a way? I'm...
1
by: Me, Myself, and I | last post by:
First off, i apologize if my terminology is off... I am currently in a project that is basically a front-end to a database. In coding this, I am taking into account that it has the *potential*...
5
by: orencs | last post by:
Hello, I am using Microsoft.Practices.EnterpriseLibrary.Data. I am running the following sqlCommand = "SELECT var1 FROM table1 WHERE var2 IN (4,5,6) ; SELECT var3 FROM table2 WHERE var2 IN...
5
by: vsteshenko | last post by:
Hello, This is my second post to the any usernet group and the first one was posted to the wrong one. I am currently working on creating an order form for sales associates at my work to be used...
4
by: huzzaa | last post by:
I am using a switch statement that will decide from a random number what message to display. I want the random number to be between 0 and 100 and then if the number is say between 1 and 10 to...
1
by: zeebiggie | last post by:
Good morning I have a form with the controls in the insert statment below. table1 has an Auto increment primary key hence is omitted in the insert statment and form. Am getting the error It didnt...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.