Can one ►variable◄ have/contain more than one value ?It may be something instead of variable if possible.
21 Replies - 2872 Views - Last Post: 12 December 2010 - 08:02 AM
#1
Can one ►variable◄ have/contain more than one value ?
Posted 08 December 2010 - 01:04 PM
Button 1 clicked
Set variable1 = 5 and 10 and 15 and 21
Set variable2 = 5 and 15
button 2 clicked
If variable1 contain 5 and 15
then...
blablabla
OR(i prefer this one if possible.)
button 2 clicked
if variable1 contain at least 2 number that they are in variable1(variable 2 contain 5 and 15 btw. which are in variable 1 too, so its correct.)
then
blabla
Possible ? if so, how ? id like to see an example code.
Replies To: Can one ►variable◄ have/contain more than one value ?
#2
Re: Can one ►variable◄ have/contain more than one value ?
Posted 08 December 2010 - 01:07 PM
#3
Re: Can one ►variable◄ have/contain more than one value ?
Posted 08 December 2010 - 01:13 PM
#4
Re: Can one ►variable◄ have/contain more than one value ?
Posted 08 December 2010 - 01:34 PM
#5
Re: Can one ►variable◄ have/contain more than one value ?
Posted 08 December 2010 - 01:46 PM
Dim arr() As Integer = New Integer() {5,10,15,21}
If Array.IndexOf(arr,5) >= 0 AndAlso Array.IndexOf(arr, 15) >= 0 Then
''-1 is returned if nothing is found... otherwise a 0 or positive index is returned
''do stuff
End If
@monkeyB - pick up your textbook (preferrably a .Net text, if you don't have one GET ONE) and open to the chapter on arrays. Arrays are one of the simplest structures in programming, you should learn everything you can about them now.
This post has been edited by lordofduct: 08 December 2010 - 01:49 PM
#6
Re: Can one ►variable◄ have/contain more than one value ?
Posted 08 December 2010 - 02:12 PM
Dim myIntegerList As New List(Of Integer)
#7
Re: Can one ►variable◄ have/contain more than one value ?
Posted 08 December 2010 - 02:19 PM
lordofduct, on 08 December 2010 - 12:46 PM, said:
Dim arr() As Integer = New Integer() {5,10,15,21}
If Array.IndexOf(arr,5) >= 0 AndAlso Array.IndexOf(arr, 15) >= 0 Then
''-1 is returned if nothing is found... otherwise a 0 or positive index is returned
''do stuff
End If
@monkeyB - pick up your textbook (preferrably a .Net text, if you don't have one GET ONE) and open to the chapter on arrays. Arrays are one of the simplest structures in programming, you should learn everything you can about them now.
Didnt tried it yet, will try tomorrow or so but i guess it will work.
Thanks.
hawkvalley1, on 08 December 2010 - 01:12 PM, said:
Dim myIntegerList As New List(Of Integer)
Aww, so there is such a thing called list, cool. i will check it out tomorrow
#8
Re: Can one ►variable◄ have/contain more than one value ?
Posted 08 December 2010 - 02:35 PM
they're called 'collections' and exist in the System.Collections namespace:
http://msdn.microsof...ollections.aspx
preferred over collections though is the generic versions of them (which is the List(Of T) that hawkeye brings up). They are in the System.Collections.Generic namespace:
http://msdn.microsof...ns.generic.aspx
Generic versions allow you to hold onto type safety with your collection (by defining the type when you create it).
Where an array is just a simple group of objects or values in a static sized container. These are more dynamic object oriented collections that give you a lot of freedoms over arrays. Most of them can be implemented with an array, but some of the methods would be pretty convoluted when working with an array (for instance add range mid way through an array... requires resizing, shifting existing, and adding the range).
This post has been edited by lordofduct: 08 December 2010 - 02:38 PM
#9
Re: Can one ►variable◄ have/contain more than one value ?
Posted 08 December 2010 - 06:45 PM
Arrays can store MULTIPLE pieces of data at the same time, so long as they are of the SAME DATA TYPE.
Use a STRUCTURE (i.e. array of records) if you want to store multiple columns of data of different types, e.g. string and integer).
Hope that helps!
#10
Re: Can one ►variable◄ have/contain more than one value ?
Posted 09 December 2010 - 12:40 PM
if v1 have at least 2 value in v2 then ?
#11
Re: Can one ►variable◄ have/contain more than one value ?
Posted 09 December 2010 - 12:43 PM
#12
Re: Can one ►variable◄ have/contain more than one value ?
Posted 09 December 2010 - 02:00 PM
hawkvalley1, on 09 December 2010 - 11:43 AM, said:
I will use them as check variables, so they may be string, number(integer) etc. doesnt really matter and i do believe i can change it, and understand it(or at least i will try to do)
off-topic: What are "kudos" ?
#13
Re: Can one ►variable◄ have/contain more than one value ?
Posted 09 December 2010 - 02:13 PM
here's with IList (a lot of collections implement IList, including List and List(Of T)). It's just a naive search and if col1 has duplicates it will consider them as unique. Meaning:
{2,2,1} {2,3} shares 2 because the first has 2 2's in it. Where as if you flipped it would only share 1. Hence why I call it naive.
Public Shared Function SharesSomeValues(ByVal col1 As IList, ByVal col2 As IList, ByVal shareCount As Integer) As Boolean
Dim cnt As Integer = 0
For Each val1 In col1
If col2.Contains(val1) Then
cnt += 1
End If
Next
Return (cnt >= shareCount)
End Function
#14
Re: Can one ►variable◄ have/contain more than one value ?
Posted 09 December 2010 - 08:26 PM
Quote
Kudos are points we receive when we submit tutorials or code snippets. On the Black bar near the top you will find both - explore them both as there you will find much coolness!
#15
Re: Can one ►variable◄ have/contain more than one value ?
Posted 09 December 2010 - 08:33 PM
http://www.dreaminco...lections-lists/
|
|

New Topic/Question
Reply




MultiQuote





|