Getting the highest value from 3 arrays - arrays

first of all thanks for your time.
I have a program where I roll 2 dices 3 times, their values get stored in 2 arrays.
Dim Attacker(3) As Integer
Dim Defender(3) As Integer
Dim i As Integer = 0
For Each pb As PictureBox In New PictureBox() {Steen1, Steen2, Steen3}
i += 1
Select Case RandomNumber.Next(1, 7)
Case 1 : pb.Image = Game.My.Resources.Een
Attacker([i]) = 1
Case 2 : pb.Image = Game.My.Resources.Twee
Attacker([i]) = 2
Case 3 : pb.Image = Game.My.Resources.Drie
Attacker([i]) = 3
Case 4 : pb.Image = Game.My.Resources.Vier
Attacker([i]) = 4
Case 5 : pb.Image = Game.My.Resources.Vijf
Attacker([i]) = 5
Case 6 : pb.Image = Game.My.Resources.Zes
Attacker([i]) = 6
End Select
Next
i = 0
For Each pb As PictureBox In New PictureBox() {Steen4, Steen5, Steen6}
i += 1
Select Case RandomNumber.Next(1, 7)
Case 1 : pb.Image = Game.My.Resources.Een
Defender([i]) = 1
Case 2 : pb.Image = Game.My.Resources.Twee
Defender([i]) = 2
Case 3 : pb.Image = Game.My.Resources.Drie
Defender([i]) = 3
Case 4 : pb.Image = Game.My.Resources.Vier
Defender([i]) = 4
Case 5 : pb.Image = Game.My.Resources.Vijf
Defender([i]) = 5
Case 6 : pb.Image = Game.My.Resources.Zes
Defender([i]) = 6
End Select
Next
Now I would like to let the highest the second highest and the lowest value's 'fight' each other:
Highest value Attacker against highest value Defender,
Second highest value Attacker against second highest value Defender,
Lowest...
Is there a standard method to do this or do I have to work with 'a hundred' if statements?
Thanks again!
P.S: I am a 17 year old recreational programmer so I probably don't have all the basics yet.

You could order the lists, and then iterate through them together using Zip.
Attacker = Attacker.OrderByDescending(Function(x) x).ToArray()
Defender = Defender.OrderByDescending(Function(x) x).ToArray()
For Each pair In Attacker.Zip(Defender, Function(attack, defend) _
New With { attack, defend })
' have the numbers "fight"
Next
To break down the individual parts in the ordering line:
OrderByDescending
orders the array based on the elements selected by the given
function.
Function(x) x is a function that simply returns what is
passed into it. Since we want to order by the Integers that are in
the array (instead of, e.g. some property on the Integer), this is
the function we want to use.
Since OrderByDescending returns a new
IEnumerable(Of Integer) while we want to modify our array, we then
use ToArray to convert it
And then we store
it (the Attacker = part).

You can sort the array.
Array.Sort(Attacker)
Array.Sort(Defender)
Then you can compare index 0 of both array together and continue with index 1 and 2.

Related

Finding all possible combos for n * m array, excluding certain values

I have an array that can vary in size, with n columns and m rows, and I need to find all the combinations of one element for each row/column combination, but exclude any combinations where the element is zero. So, in practice, if I have:
Row
Item1
Item2
Item3
1
A
B
C
2
D
E
F
I will have 2^3 = 8 possible combinations: ABC, ABF, AEC, AEF, DBC, DBF, DEC, DEF.
But if instead of B I have a zero in row 1 Item2, I want to exclude that cell from the list of combinations (in bold above), so I would end up with: AEC, AEF, DEC and DEF.
I found some code that give me all the possible combinations on a fixed number of columns (Macro to make all possible combinations of data in various columns in excel sheet), but it doesn't account for an array that can change dimensions, or for the exclusion rule above.
I'm just going to post the code for the simple (no zeroes) case so you can see where I'm going with this (of course I have realised that Base switches over to letters for radix 11 onwards so this might not be the smartest approach :) )
Function ListCombos(r As Range)
Dim s As String, result As String
Dim arr()
Dim j As Integer, offset As Integer
Dim rows As Integer, cols As Integer
Dim nComb As Long, i As Long
rows = r.rows.Count
cols = r.Columns.Count
nComb = rows ^ cols
ReDim arr(1 To nComb)
For i = 1 To nComb
s = Application.Base(i - 1, rows, cols)
result = ""
For j = 1 To cols
offset = CInt(Mid(s, j, 1))
result = result & r.Cells(1, 1).offset(offset, j - 1)
Next j
arr(i) = result
Next i
ListCombos = arr
End Function
This is the version skipping combinations which contain zeroes. The method is to move non-zero values to the first rows of a holding array so effectively if you start with something like this
You make it look like this
So you don't have to generate or check all the combinations that contain zeroes.
Then use mixed radix to cycle through the combinations:
Option Explicit
Option Base 1
Function ListCombosWithZeroes(r As Range)
Dim s As String, result As String
Dim arr()
Dim i As Integer, j As Integer, offset As Integer, count As Integer, carry As Integer, temp As Integer
Dim rows As Integer, cols As Integer
Dim nComb As Long, iComb As Long
Dim holdingArr(20, 20) As String
Dim countArr(20) As Integer
Dim countUpArr(20) As Integer
rows = r.rows.count
cols = r.Columns.count
' Move non-zero cells to first rows of holding array and establish counts per column
For j = 1 To cols
count = 0
For i = 1 To rows
If r.Cells(i, j) <> 0 Then
count = count + 1
holdingArr(count, j) = r.Cells(i, j)
End If
Next i
countArr(j) = count
Next j
' Calculate number of combos
nComb = 1
For j = 1 To cols
nComb = nComb * countArr(j)
Next j
ReDim arr(1 To nComb)
'Loop through combos
For iComb = 1 To nComb
result = ""
For j = 1 To cols
offset = countUpArr(j)
result = result & holdingArr(offset + 1, j)
Next j
arr(iComb) = result
'Increment countup Array - this is the hard part.
j = cols
'Set carry=1 to force increment on right-hand column
carry = 1
Do
temp = countUpArr(j) + carry
countUpArr(j) = temp Mod countArr(j)
carry = temp \ countArr(j)
j = j - 1
Loop While carry > 0 And j > 0
Next iComb
ListCombosWithZeroes = arr
End Function
You don't have to have equal numbers of letters per column.
Here's a solution. Probably not most efficient, since it is O(n2), but it works.
Caveats
I put a '.' instead of zero to avoid dealing with numeric vs alphanumeric values, but you can easily change this
Since I build the strings incrementally I need indices to be predictable. Hence I fill all the possible combinations and then remove the ones containing a '.' in a second pass
Global aws As Worksheet
Global ur As Range
Global ccount, rcount, size, rptline, rptblock, iblk, iln, idx As Integer
Global tempcombos(), combos() As String
Public Sub Calc_combos()
Set aws = Application.ActiveSheet
Set ur = aws.UsedRange
ccount = ur.Columns.Count
rcount = ur.Rows.Count
size = (rcount - 1) ^ (ccount - 1)
ReDim tempcombos(size - 1)
ReDim combos(size - 1)
rptline = size / (rcount - 1)
rptblock = 1
For c = 2 To ccount
idx = 0
For iblk = 1 To rptblock
For r = 2 To rcount
For iln = 1 To rptline
tempcombos(idx) = tempcombos(idx) & Cells(r, c)
idx = idx + 1
Next iln
Next r
Next iblk
rptline = rptline / (rcount - 1)
rptblock = rptblock * (rcount - 1)
Next c
idx = 0
For iln = 0 To size - 1
If InStr(tempcombos(iln), ".") = 0 Then
combos(idx) = tempcombos(iln)
idx = idx + 1
End If
Next iln
End Sub
The Python way:
from dataclasses import dataclass, field
from itertools import product
from random import randint
from typing import Dict, List
#dataclass
class PriceComparison():
rows : int
cols : int
maxprice : int = 50
threshold : int = 0
itemcodes : List[List[str]] = field(init=False)
pricelist : Dict[str, int] = field(init=False)
def __post_init__(self):
##create sample data
self.itemcodes = [[f'A{r+self.cols*c:03d}' for c in range(self.rows)] for r in range(self.cols)]
print(self.itemcodes)
self.pricelist = {self.itemcodes[c][r]:randint(0,self.maxprice) for r in range(self.rows) for c in range(self.cols)}
##remove items with price = 0
for col in self.itemcodes:
for item in col[:]:
if self.pricelist[item] == 0:
print(f'removing {item} from {col}')
col.remove(item)
del self.pricelist[item]
def find_cheapest(self):
iterations = 1
for col in self.itemcodes:
iterations *= len(col)
print(f'this may require {iterations} iterations!')
cheapest = self.maxprice * self.cols + 1
for i, combo in enumerate(product(*self.itemcodes)):
##dummy price calculation
price = sum([self.pricelist[item] for item in combo]) * randint(1,10) // 10
if price < cheapest:
print(f'current cheapest is {price} at iteration {i}')
cheapest = price
if price < self.threshold:
print('under threshold: returning')
break
return cheapest
Some notes:
I assume the cheapest combo is not simply given by selecting the cheapest item in each column, otherwise we would not need all this complicated machinery; so I inserted a random coefficient while calculating the total price of a combo - this should be replaced with the actual formula
I also assume we have item codes in our input table, with prices for each item stored elsewhere. As sample data I create codes from 'A000' to 'Axxx', and assign a random price between 0 and a maxprice to each one
Items with price = 0 are removed immediately, before the search for the cheapest combo
For large input tables the search will take a very long time. So although it wasn't requested I also added an optional threshold parameter: if we find a total price under that value we consider it is cheap enough and stop the search
EDIT
The following is a Python 3.5 compatible version.
However it must be noted that with a 10x15 input table the number of required iterations will be somewhere near 1E+15 (something less actually, depending on how many cells we are able to ignore as "obvious outliers"). Even if we check 1 million combos per second it will still run for (something less than) 1E+09 seconds, or about 32 years.
So we need a way to improve our strategy. I integrated two options:
Setting a threshold, so that we don't search for the actual best price but stop as soon as we find an "acceptable" one
Splitting the tables in "zones" (subsets of columns), looking for the best partial solution for each zone and then combining them.
Sample runs:
##10 x 15, 5 zones, each 3 columns wide
this may require up to 1.000000e+03 iterations!
...
current best price is 1 at iteration 71 in 0.06 secs
this may require up to 1.000000e+03 iterations!
...
current best price is 2 at iteration 291 in 0.11 secs
this may require up to 1.000000e+03 iterations!
...
current best price is 1 at iteration 330 in 0.07 secs
this may require up to 8.100000e+02 iterations!
...
current best price is 4 at iteration 34 in 0.09 secs
this may require up to 1.000000e+03 iterations!
...
current best price is 1 at iteration 82 in 0.07 secs
['A000', 'A106', 'A017', 'A033', 'A139', 'A020', 'A051', 'A052', 'A008', 'A009', 'A055', 'A131', 'A147', 'A133', 'A044']
##10 x 15, no zones, threshold = 25
this may require up to 8.100000e+14 iterations!
...
current best price is 24 at iteration 267493282 in 1033.24 secs
under threshold: returning
['A000', 'A001', 'A002', 'A003', 'A004', 'A005', 'A051', 'A052', 'A008', 'A039', 'A055', 'A071', 'A042', 'A133', 'A044']
Code follows:
from itertools import product
from random import randint
from time import time
class PriceComparison():
def __init__(self, rows, cols, zones = [], maxprice = 50, threshold = 0):
self.rows = rows
self.cols = cols
if zones == []:
self.zones = [cols]
else:
self.zones = zones
self.maxprice = maxprice
self.threshold = threshold
self.__post_init__()
def __post_init__(self):
##create sample data
self.itemcodes = [['A%03d' % (r+self.cols*c) for c in range(self.rows)] for r in range(self.cols)]
print(self.itemcodes)
self.pricelist = {self.itemcodes[c][r]:randint(0,self.maxprice) for r in range(self.rows) for c in range(self.cols)}
##remove items with price = 0
for col in self.itemcodes:
for item in col[:]:
if self.pricelist[item] == 0:
print('removing %s from %s' % (item, col))
col.remove(item)
del self.pricelist[item]
def find_cheapest(self, lo, hi):
iterations = 1
for col in self.itemcodes[lo:hi]:
iterations *= len(col)
start = time()
print('\nthis may require up to %e iterations!' % (iterations))
bestprice = self.maxprice * self.cols + 1
for i, combo in enumerate(product(*self.itemcodes[lo:hi])):
##dummy price calculation
price = sum([self.pricelist[item] for item in combo]) * randint(1,10) // 10
if price < bestprice:
elapsed = time() - start
print('current best price is %d at iteration %d in %.2f secs' % (price, i, elapsed))
cheapest = combo
bestprice = price
if price < self.threshold:
print('under threshold: returning')
break
return cheapest
def find_by_zones(self):
print(self.zones)
fullcombo = []
lo = 0
for zone in self.zones:
hi = lo + zone
fullcombo += self.find_cheapest(lo, hi)
lo = hi
return fullcombo

How can I find the nonzero values in a MATLAB cells array?

The following code generates an cell array Index [1x29], where each cell is an array [29x6]:
for i = 1 : size(P1_cell,1)
for j = 1 : size(P1_cell,2)
[Lia,Lib] = ismember(P1_cell{i,j},PATTERNS_FOR_ERANOS_cell{1},'rows');
Index1(i,j) = Lib % 29x6
end
Index{i} = Index1; % 1x29
end
How can I find the nonzero values in Index array?, i.e. generate an array with the number of non-zero values in each row of the Index1 array. I tried the following loop, but it doesn't work, it creates conflict with the previous one:
for i = 1 : length(Index)
for j = 1 : length(Index)
Non_ceros = length(find(Index{:,i}(j,:))); %% I just need the length of the find function output
end
end
I need help, Thanks in advance.
The nnz() (number of non-zeros) function can be used to evaluate the number of non-zero elements. To obtain the specific positive values you can index the array by using the indices returned by the find() function. I used some random test data but it should work for 29 by 6 sized arrays as well.
%Random test data%
Index{1} = [5 2 3 0 zeros(1,25)];
Index{2} = [9 2 3 1 zeros(1,25)];
Index{3} = [5 5 5 5 zeros(1,25)];
%Initializing and array to count the number of zeroes%
Non_Zero_Counts = zeros(length(Index),1);
for Row_Index = 1: length(Index)
%Evaluating the number of positive values%
Array = Index{Row_Index};
Non_Zero_Counts(Row_Index) = nnz(Array);
%Retrieving the positive values%
Positive_Indices = find(Array);
PositiveElements{Row_Index} = Array(Positive_Indices);
disp(Non_Zero_Counts(Row_Index) + " Non-Zero Elements ");
disp(PositiveElements{Row_Index});
end
Ran using MATLAB R2019b
for i = 1 : length(Index)
for j = 1 : length(Index)
Non_ceros(i,j) = nnz(Index{:,i}(j,:));
end
end

Output Array Contents without selecting each element

I have the following multidimensional array structure
Type Wedge
C407 As Long
C417 As Long
C507 As Long
C516 As Long
C607 As Long
C617 As Long
C707 As Long
C716 As Long
C807 As Long
C817 As Long
C907 As Long
C916 As Long
End Type
The above has about 35 elements to it
Global myWedge() As Wedge
ReDim myWedge(99, 4)
I have populated the array but now want to output the contents of the array to a worksheet. Previously in other smaller arrays I have outputted each element as below.
'Output IOTT Number and Duration
For a = 1 To 4
If YGBL(x, a).IOTT > 0 Then sOutput.Cells(x + 4, IOTTCol) = YGBL(x, a).IOTT
IOTTCol = IOTTCol + 2
If YGBL(x, a).IOTTDUR > 0 Then sOutput.Cells(x + 4, IOTTDUR) = YGBL(x, a).IOTTDUR
IOTTDUR = IOTTDUR + 2
Next a
But given the number of elements I just want to loop through the elements and put this into a sheet without have to do the above for each elements.
Is this possible
Thanks
Use a function....
Function PropertyOf(wedgeType As Wedge, index As Integer) As Long
Dim w As Long
With wedgeType
Select Case index
Case 1
w = .C407
Case 2
w = .C417
Case 3
w = .C507
....
End Select
End With
PropertyOf = w
End Function
Then
Dim w As Wedge
For a = 1 To 4
w = myWedge(x, a)
For c = 1 To 35
p = PropertyOf(w, c)
If p > 0 Then
' Do your stuff here
End If
Next c
Next i

Reverse lookup with non-unique values

What I'm trying to do
I have an array of numbers:
>> A = [2 2 2 2 1 3 4 4];
And I want to find the array indices where each number can be found:
>> B = arrayfun(#(x) {find(A==x)}, 1:4);
In other words, this B should tell me:
>> for ii=1:4, fprintf('Item %d in location %s\n',ii,num2str(B{ii})); end
Item 1 in location 5
Item 2 in location 1 2 3 4
Item 3 in location 6
Item 4 in location 7 8
It's like the 2nd output argument of unique, but instead of the first (or last) occurrence, I want all the occurrences. I think this is called a reverse lookup (where the original key is the array index), but please correct me if I'm wrong.
How can I do it faster?
What I have above gives the correct answer, but it scales terribly with the number of unique values. For a real problem (where A has 10M elements with 100k unique values), even this stupid for loop is 100x faster:
>> B = cell(max(A),1);
>> for ii=1:numel(A), B{A(ii)}(end+1)=ii; end
But I feel like this can't possibly be the best way to do it.
We can assume that A contains only integers from 1 to the max (because if it doesn't, I can always pass it through unique to make it so).
That's a simple task for accumarray:
out = accumarray(A(:),(1:numel(A)).',[],#(x) {x}) %'
out{1} = 5
out{2} = 3 4 2 1
out{3} = 6
out{4} = 8 7
However accumarray suffers from not being stable (in the sense of unique's feature), so you might want to have a look here for a stable version of accumarray, if that's a problem.
Above solution also assumes A to be filled with integers, preferably with no gaps in between. If that is not the case, there is no way around a call of unique in advance:
A = [2.1 2.1 2.1 2.1 1.1 3.1 4.1 4.1];
[~,~,subs] = unique(A)
out = accumarray(subs(:),(1:numel(A)).',[],#(x) {x})
To sum up, the most generic solution, working with floats and returning a sorted output could be:
[~,~,subs] = unique(A)
[subs(:,end:-1:1), I] = sortrows(subs(:,end:-1:1)); %// optional
vals = 1:numel(A);
vals = vals(I); %// optional
out = accumarray(subs, vals , [],#(x) {x});
out{1} = 5
out{2} = 1 2 3 4
out{3} = 6
out{4} = 7 8
Benchmark
function [t] = bench()
%// data
a = rand(100);
b = repmat(a,100);
A = b(randperm(10000));
%// functions to compare
fcns = {
#() thewaywewalk(A(:).');
#() cst(A(:).');
};
% timeit
t = zeros(2,1);
for ii = 1:100;
t = t + cellfun(#timeit, fcns);
end
format long
end
function out = thewaywewalk(A)
[~,~,subs] = unique(A);
[subs(:,end:-1:1), I] = sortrows(subs(:,end:-1:1));
idx = 1:numel(A);
out = accumarray(subs, idx(I), [],#(x) {x});
end
function out = cst(A)
[B, IX] = sort(A);
out = mat2cell(IX, 1, diff(find(diff([-Inf,B,Inf])~=0)));
end
0.444075509687511 %// thewaywewalk
0.221888202987325 %// CST-Link
Surprisingly the version with stable accumarray is faster than the unstable one, due to the fact that Matlab prefers sorted arrays to work on.
This solution should work in O(N*log(N)) due sorting, but is quite memory intensive (requires 3x the amount of input memory):
[U, X] = sort(A);
B = mat2cell(X, 1, diff(find(diff([Inf,U,-Inf])~=0)));
I am curious about the performance though.

Comparing arrays with numbers in vb.net

I need a way to compare two arrays in vb.net and save result in third array:
Dim KonRes(3) As Integer
Dim UserRes(3) As Integer
Dim YelRed(3) As Integer
KonRes(0) = 1
KonRes(1) = 2
KonRes(2) = 3
KonRes(3) = 4
UserRes(0) = 4
UserRes(1) = 3
UserRes(2) = 2
UserRes(3) = 1
How to compare those arrays so in declared variable YelRed I should have results like this:
If UserRes(0) = KonRes(0) Then
YelRed(0) = 2
If UserRes(0) = KonRes(1 or 2 or 3) Then
YelRed(0) = 1
If UserRes(0) does not contain any number like in KonRes then YelRed(0) should be 0. Also it should not make duplicate results, in other words if it already checked UserRes(0) = KonRes(0) then it should not check KonRes(0) in next check. It's not a problem to compare if those arrays are completely same, my problem is comparing each value of one array with other one, and collect results. Any suggestions?
There are a few basic ways of checking for a value in an integer array. The first is to manually search by looping through each value in the array, which may be what you want if you need to do complicated comparisons.
Second is the .Contains() method. It is simpler to use but will only give you a Boolean indicating whether the value is in the array or not. Example:
If KonRes.Contains(UserRes(0)) Then YelRed(0) = 1
Lastly, there's the IndexOf() function. It searches for a match and returns the index of a match if found, or one below the lower bound of the array if not (-1 for typical 0-based arrays). As I understand your needs from your comments above, this code should do the trick:
For i As Integer = 0 To 3
Select Case IndexOf(KonRes, UserRes(i))
Case i 'Matching postion
YelRed(i) = 2
Case -1 'No match found
YelRed(i) = 0
Case Else 'Match found at another position
YelRed(i) = 1
End Select
Next i
EDIT: I misunderstood the qualification about duplicates until #Sastreen clarified it. Here's a rewrite tailored to not count the same index as a match twice:
Dim processed(3) As Boolean
For i As Integer = 0 To 3
YelRed(i) = 0
If KonRes(i) = UserRes(i) And Not processed(i) Then
processed(i) = True
YelRed(i) = 2
Else
For j As Integer = 0 To 3
If KonRes(j) = UserRes(i) Then
processed(j) = True
YelRed(i) = 1
Exit For
End If
Next j
End If
Next i
If UserRes(0) = KonRes(0) that mean they are in same position in two
arrays, then YelRed(0) = 2, if UserRes(0) = KonRes(1,2,3) so number is
there and but not in same position, so YelRed(0) =1 and if the number
is not in second array it must be 0.
Use a For-Loop:
For i As Int32 = 0 To KonRes.Length - 1
If KonRes(i) = UserRes(i) Then
' Same position '
YelRed(i) = 2
ElseIf UserRes.Contains(KonRes(i)) Then
' Other position '
YelRed(i) = 1
Else
' Not contained '
YelRed(i) = 0
End If
Next
You can use nested For loops to go through the two arrays to compare, and then use Exit For to leave at any time.
The indicesToIgnore is for making sure it does not "make duplicate results" (this is harder to achieve with the IndexOf and contains methods).
Also it should not make duplicate results, in other words if it already checked UserRes(0) = KonRes(0) then it should not check KonRes(0) in next check.
Dim indicesToIgnore as New List(Of Integer)
'go through first array
For i as Integer = 0 to UserRes.length - 1 Step 1
'go through second array
For j as Integer = 0 to KonRes.length- 1 Step 1
'if the values are equal, check whether same index, then exit for
If (Not indicesToIgnore.contains(j) AndAlso UserRes(i) = KonRes(j)) Then
If i=j Then
YelRed(i) = 2
indicesToIgnore.add(j)
Else
YelRed(i) = 1
End If
Exit For
End If
Next
Next
You don't need to set YelRed(i) to 0 at any time because it defaults as this. You just need to make sure YelRed has the same size as the other arrays.
If you also want it to not look at the KonRes value (for duplicates) if it contains it at a different index, simply add indicesToIgnore.add(j) at the end of the Else (after YelRed(i) = 1) as well.
I think this will do the job, if KonRes(0) = UserRes(0) then YelRed(0) = 1 else YelRed(0) = 2
Dim KonRes(3) As Integer
Dim UserRes(3) As Integer
Dim YelRed(3) As Integer
KonRes(0) = 1
KonRes(1) = 2
KonRes(2) = 3
KonRes(3) = 4
UserRes(0) = 4
UserRes(1) = 2
UserRes(2) = 2
UserRes(3) = 1
Dim Uindex As Integer = 0
For Each item In UserRes
Dim Kindex As Integer = 0
For Each i In KonRes
If item = i Then
If Kindex = Uindex Then
YelRed(Uindex) = 1
Else
YelRed(Uindex) = 2
End If
End If
Kindex += 1
Next
Uindex += 1
Next
You didn't told us what the output should be. It's a bit confusing. In my case, it will be {1, 1, 0, 0}. If was to be done with 2 for loop. On that loops everything in KonRes while the other only loop what wasn't checked yet in UserRes.
For k As Integer = 0 To KonRes.Length - 1
If KonRes(k) = UserRes(k) Then
YelRed(k) = 2
Else
YelRed(k) = 0
For u As Integer = k + 1 To UserRes.Length - 1
If KonRes(k) = UserRes(u) Then
YelRed(k) = 1
Exit For
End If
Next
End If
Next
You could use the comparison from the array.
Dim iNextActivityTypeCd As Integer = 18400
Dim activities() As Integer = {1,18400, 2300, 3423}
If activities.Contains(iNextActivityTypeCd) Then
Dim foo = 1
End If

Resources