473,378 Members | 1,471 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,378 software developers and data experts.

I learned something today (.NET and VB6)

As they say in South Park... "Well, I learned something today."

This is valid in both VB6 and 9 versions:

Select Case TrySelect
Case 1, 3
Debug.Print "1"
Case 2
Debug.Print "2"
Case 3
Debug.Print "3"
End Select

Of course, the "Case 3" never gets executed due to the "Case 1, 3"
catching the 3. I cannot imagine it is even legal to code but does not
even get a simple warning flag in VB9. Good languages will flag code
that cannot get executed. VB6 and 9 both ignore the situation.

Calling this with 1 then 2 then 3 prints 1 then 2 then 1 again.

I accidentally left a duplicate of a Case "test expression" in a program
I am working on. It was a leftover from a change I made some time back.
It had no code in it so I did not notice it until I was reworking the
routine a bit, yesterday. I was amazed that this is even allowed. It
is not allowed in at least one other language I have worked in, possibly
two others. What's the point?

Live and learn!

Mike

Apr 10 '08 #1
2 979
"AMercer" <AM*****@discussions.microsoft.comschrieb:
Dim i As Integer = 3
Dim j As Integer = 3
Select Case j
Case i : whatever
Case 3 : whatever
End Select

No diagnostic is possible at compile time. What do you want this
construct
to do - throw an exception at runtime when i=3? There are two case
clauses
that match the select clause, but only one will run. I don't think an
exception is useful, and I don't think you do either. Maybe VB allowing
expressions where C allows only constants explains VB's keep-it-simple
approach.
I'd prefer an optional warning or rule which makes the developer aware that
he is writing useless code. However, even 'If False Then...' is permitted
by the compiler.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Apr 10 '08 #2
If False then ... INDEED!
End if

Well, one can shot oneself in the foot, if desired, I guess. I was just
wishing for a warning, at least, when you write something a little more
complex and then it might not run as you think or not run at all.

Thanks for the laugh!

Remember, Fornapulation is fun!

Mike

On Fri, 11 Apr 2008 01:39:12 +0200, in
microsoft.public.dotnet.languages.vb "Herfried K. Wagner [MVP]"
<hi***************@gmx.atwrote:
>"AMercer" <AM*****@discussions.microsoft.comschrieb:
> Dim i As Integer = 3
Dim j As Integer = 3
Select Case j
Case i : whatever
Case 3 : whatever
End Select

No diagnostic is possible at compile time. What do you want this
construct
to do - throw an exception at runtime when i=3? There are two case
clauses
that match the select clause, but only one will run. I don't think an
exception is useful, and I don't think you do either. Maybe VB allowing
expressions where C allows only constants explains VB's keep-it-simple
approach.

I'd prefer an optional warning or rule which makes the developer aware that
he is writing useless code. However, even 'If False Then...' is permitted
by the compiler.
Jun 27 '08 #3

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

Similar topics

4
by: Joseph Geretz | last post by:
Our company develops and markets a client/server application which is written in VB6 as a rich Win32 Client/Server application. For a variety of technological reasons we are looking to migrate...
9
by: James Lee | last post by:
Hi, char **ipaddress; ipaddress = malloc(N * sizeof(char*)); for (i=0; ;i++) { ipaddress = fxn_that_returns_pointer_to_char; }
4
by: Dennis Burdett | last post by:
I have a pretty complex control which use to be a C# windows form that I am trying to make into a control that can be dragged onto a VB6 form. I was able to make it into a com class that I could...
1
by: duha | last post by:
I get this "Run-Time error '13': Type Mismatch" when I run the sample code below. The debugger highlight the line "Set MSHFlexGrid1.DataSource = rs" Any ideas? I am using VB6. Thanks, duha ...
2
by: Wim | last post by:
Hi, I looking for a way to read all binary data on Compact Flash card when the CF card is not formated in FAT or FAT32. Excisting software ok , or is it possible write something in VB6 or...
45
by: John Salerno | last post by:
Because of my 'novice-ness' in programming, I had always thought that C was replaced by C++ and wasn't really used anymore today. I know that's not the case at all now, but I'm still curious how...
4
by: james | last post by:
Hi I am in the process of developing a simple web-downloadable application to be run on multiple users machines. Your thoughts would be appreciated as to whether VB6 or C#.net would be the...
20
by: James | last post by:
I am new to vb.net (I am an old vb6 programmer). I cannot figure out an easy way to watch variables. In vb6 all I did was right click and could chose to stop execution when a variable chances as...
11
by: Vanessa | last post by:
I have a class library developed in VB.NET. Inside there is a form with a button1. I add this class library to a VB6 Project. I do a Dim a as new classlibrary.form1 SetParent a.GetHwnd,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: 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...

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.