Wrox Programmer Forums
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 17th, 2005, 02:51 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mega
Default Using IS in Select Case

Hi all.

It might be the late hour but I can't figure out why this little piece of code won't work when I apply it in the real world:
Code:
' selectTest should eval to true...
Sub doTest()
selectTest 543
End Sub

Function selectTest(intAntal%)
Select Case (intAntal)
  Case ((30 / 20) * 100), Is >= 100
    selectTest= True
    Exit Function
  Case Else
    selectTest= False
End Select
End Function
While this work, the equaling real code won't:
Code:
With objStation.Parkeringer(intP).Taellinger(intT)
  Select Case (.intAntalPladser)
    Case 0
      SkalMed = True
      If .intAntalParkeret = 0 Then
        MsgBox "PÃ¥ " & objStation.strNavn & " er der en tælling med" & _
               " 0 P-pladser og 0 parkeret." & Chr(10) & _
               "Stationen kommer med i rapporten.", vbInformation, "Advarsel"
        End If
      Exit Function
    Case ((.intAntalParkeret / .intAntalPladser) * 100), Is >= intBelaegningsprocent
      SkalMed = True
      Exit Function
    Case 1345, Is > 90 ' the code should at least stop here... but doesn't
      Stop
    Case Else
      SkalMed = False
  End Select
End With
The above select case (almost) always returns false. It seems like it works sometimes. Like when intBelaegningsprocent is set to 5 but not 80 or 90.

Any ideas on why this happens?!?

 - mega
Moving to C# .NET
__________________
- mega
Aspiring JavaScript Ninja
 
Old August 18th, 2005, 04:02 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

what do you mean with "the code should at least stop here"
VB checks the case statements in sequential order, executes the first true condition and then exits the select case.
In your case, for example, if .intAntalPladser= 100 and intBelaegningsprocent=10, the second case is executed
Marco
 
Old August 20th, 2005, 05:26 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mega
Default

Allow me to elaborate on that.

The second case should be executed if the sum of ((.intAntalParkeret / .intAntalPladser) * 100) is equal or more than intBelaegningsprocent. I've been running test against data I know got higher percentages than intBelaegningsprocent and therefore my function should return True, but it doesn't. That's why I made the third condition Case 1345, Is > 90 witch normally always would return True. I'm thinking I don't know the right syntax or something. Perhaps there is a bug in VB6?

I appreciate your help Marco, thanks.

 - mega
Moving to C# .NET
 
Old August 20th, 2005, 09:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

you are using the case in the wrong way :)

Quote:
quote:
"The second case should be executed if the sum of ((.intAntalParkeret / .intAntalPladser) * 100) is equal or more than intBelaegningsprocent."
this if false b/c your select case is comparing that sum with .intAntalPladser and only entering if they are the same, and also is trying intAntalPladser >= intBelaegningsprocent. If any of this 2 if true then it get inside. but it not comparing the sum with intBelaegningsprocent. The is refers to the variable in the select statement.

you always compare a case with the select statemen...

Msdn link:
http://msdn.microsoft.com/library/de...selectcase.asp

HTH

Gonzalo
 
Old August 22nd, 2005, 08:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mega
Default

You are sooo right. I've never used IS in a select case and that lead me to believe I could use the select case statement in an If Else way. Of course that's not true - thanks for pointing that out...

 - mega
Moving to C# .NET





Similar Threads
Thread Thread Starter Forum Replies Last Post
select case bacster Classic ASP Basics 2 May 1st, 2006 06:31 PM
select case yuvalk SQL Server 2000 4 August 25th, 2004 02:33 PM
Select Case morpheus VB How-To 1 August 13th, 2003 09:14 AM
Select Case andy24 Classic ASP Databases 5 July 25th, 2003 07:52 AM
Select Case ziwez0 .NET Web Services 8 July 11th, 2003 02:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.