PDA

View Full Version : Solved: Greater Than Or Equal To etc



bopo
01-11-2008, 04:00 AM
Hi

Well basically this code isnt working, I dont know if its my logic that is causing it though, could someone take a look at the code below and see what you think.

If StoreMM >= 10 <= 11 Then
Season = "off peak"
ElseIf StoreMM >= 4 <= 8 Then
Season = "peak"
ElseIf StoreMM >= 12 <= 1 Then
MsgBox ("Holidays cannot be booked from 01/12 until 31/01")
ElseIf StoreMM >= 2 <= 3 Then
Season = "off peak"
End If
End If
End If

ps StoreMM holds an integer value

DarkSprout
01-11-2008, 04:27 AM
Use Select Case, much Simpler:
Select Case StoreMM
Case Is < 1, Is > 12
MsgBox "Holidays cannot be booked from 01/12 until 31/01", vbInformation, "Input Error"
Case 1 To 3, 9 To 12
Season = "off peak"
Case 4 To 8
Season = "peak"
End Select

bopo
01-11-2008, 04:42 AM
Hi

Thanks for the code, however the integer value I am storing usually starts with zero for each month e.g. 01, 09 etc, therefore this only works with 10, 11 & 12.

I was wondering if you had any suggestions regarding how to get rid of the zero, thats if the month starts with a zero.

Thanks

ALe
01-11-2008, 04:51 AM
try using Cint(StoreMM) function

bopo
01-11-2008, 04:58 AM
Yep that worked, thanks :)

DarkSprout
01-11-2008, 04:59 AM
Turn The String Into a Numeric:

Select Case Val(StoreMM)

ALe
01-11-2008, 05:23 AM
both work. Given the fact that you are working with numbers from 1 to 12 it's more efficient to use Cint than Val function because with Cint you get Integers (they use less space than Doubles returned by the Val function).