By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,745 Members | 1,897 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,745 IT Pros & Developers. It's quick & easy.

VB range of values

P: 6
Apologies for the simple question. I started a Visual Basic 2005 course in September and somehow I don't think we ever discussed it. Googling has been difficult because I don't know what it is called.

In SQL, you can specify a range of values. For instance:
Select *
from MyTable
where MyField in (1, 2, 3, 4)

What is the equivalent in vb. I'm using integers. I want to say
If Now.Year.ToString.Substring(3, 1) "in" and I want to show the even numbers, then do something else.

Is this simple?

Thank you in advance.
Apr 23 '07 #1
Share this Question
Share on Google+
3 Replies


Expert 5K+
P: 8,434
It's possible that the In() function is supported in VB2005. (I use the much older VB6 so I don't know).

If not, then you'll have to work around it in some way. For example, write your own function which accepts a string and an array, and returns true if the string matches any of the array entries.

The actual logic to check is quite simple - just loop through the array until you find something that matches (True) or pass the end of the array (False).

Don't forget to be on the lookout for alternative ways of solving problems, though. For instance, if you want to know whether the year is even, just use the modulo function. Not sure of the syntax in your VB version (just check the doco) but in Vb6, YourValue Mod 2 returns 0 (even) or 1 (odd).
Apr 24 '07 #2

P: 6
Thank you so much. I learned 2 things in one.

So far as I can tell, I can't use "in" in VB 2005. In the future I'll use an array, and as for this problem it was easily solved with Mod. Thanks again.
Apr 24 '07 #3

Expert 5K+
P: 8,434
Thank you so much. I learned 2 things in one.

So far as I can tell, I can't use "in" in VB 2005. In the future I'll use an array, and as for this problem it was easily solved with Mod. Thanks again.
Glad to help. :)
Apr 25 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.