Most Efficient Ways To Compare Multiple Array Values in VBA? - arrays

Before I begin, let me say that I know this probably isn't best done in excel and VBA, but my hands are tied in that regard.
I have a spreadsheet of 29 columns (always), and anywhere between 100 and 10,000 rows each day.
I need a way to automatically move rows from one sheet to another based on multiple criteria. The basic logic is that it needs to search the first sheet, and if C OR D equal a certain text value, AND Y contains a certain numeric value, it needs to be added to the second sheet and removed from the first.
The problem is that I've built a test version that only looks at ONE of the three criteria, and it is already very slow - If I had two more arrays and if/and/or logic, I don't think this is going to be usable on the 10,000 row days.
What can I do to speed this up? I feel like there has to be a better/faster way than arrays and for loops. I'm very much a novice, so I'm sure this is a very bad solution.
Option Explicit
Sub MacroSoFar()
Dim lColumnLength As Long
Dim intArrayCounter As Integer
Dim TestArray(165) As String
TestArray(0) = "4"
TestArray(1) = "5"
TestArray(2) = "6"
TestArray(3) = "7"
TestArray(4) = "8"
TestArray(5) = "9"
TestArray(6) = "10"
TestArray(7) = "11"
TestArray(8) = "12"
TestArray(9) = "14"
TestArray(10) = "19"
TestArray(11) = "20"
TestArray(12) = "21"
TestArray(13) = "25"
TestArray(14) = "30"
TestArray(15) = "35"
TestArray(16) = "36"
TestArray(17) = "37"
TestArray(18) = "41"
TestArray(19) = "42"
TestArray(20) = "43"
TestArray(21) = "46"
TestArray(22) = "47"
TestArray(23) = "48"
TestArray(24) = "51"
TestArray(25) = "52"
TestArray(26) = "53"
TestArray(27) = "60"
TestArray(28) = "63"
TestArray(29) = "65"
TestArray(30) = "66"
TestArray(31) = "67"
TestArray(32) = "68"
TestArray(33) = "69"
TestArray(34) = "70"
TestArray(35) = "71"
TestArray(36) = "72"
TestArray(37) = "73"
TestArray(38) = "74"
TestArray(39) = "75"
TestArray(40) = "76"
TestArray(41) = "77"
TestArray(42) = "78"
TestArray(43) = "79"
TestArray(44) = "80"
TestArray(45) = "81"
TestArray(46) = "82"
TestArray(47) = "83"
TestArray(48) = "84"
TestArray(49) = "85"
TestArray(50) = "86"
TestArray(51) = "87"
TestArray(52) = "88"
TestArray(53) = "89"
TestArray(54) = "90"
TestArray(55) = "91"
TestArray(56) = "92"
TestArray(57) = "93"
TestArray(58) = "94"
TestArray(59) = "96"
TestArray(60) = "97"
TestArray(61) = "98"
TestArray(62) = "99"
TestArray(63) = "101"
TestArray(64) = "102"
TestArray(65) = "103"
TestArray(66) = "106"
TestArray(67) = "107"
TestArray(68) = "108"
TestArray(69) = "109"
TestArray(70) = "111"
TestArray(71) = "112"
TestArray(72) = "113"
TestArray(73) = "115"
TestArray(74) = "116"
TestArray(75) = "117"
TestArray(76) = "118"
TestArray(77) = "121"
TestArray(78) = "122"
TestArray(79) = "125"
TestArray(80) = "129"
TestArray(81) = "130"
TestArray(82) = "131"
TestArray(83) = "132"
TestArray(84) = "133"
TestArray(85) = "134"
TestArray(86) = "137"
TestArray(87) = "138"
TestArray(88) = "142"
TestArray(89) = "143"
TestArray(90) = "144"
TestArray(91) = "145"
TestArray(92) = "146"
TestArray(93) = "147"
TestArray(94) = "155"
TestArray(95) = "156"
TestArray(96) = "157"
TestArray(97) = "158"
TestArray(98) = "159"
TestArray(99) = "161"
TestArray(100) = "162"
TestArray(101) = "169"
TestArray(102) = "170"
TestArray(103) = "173"
TestArray(104) = "174"
TestArray(105) = "175"
TestArray(106) = "176"
TestArray(107) = "180"
TestArray(108) = "181"
TestArray(109) = "182"
TestArray(110) = "183"
TestArray(111) = "184"
TestArray(112) = "185"
TestArray(113) = "186"
TestArray(114) = "187"
TestArray(115) = "188"
TestArray(116) = "189"
TestArray(117) = "190"
TestArray(118) = "192"
TestArray(119) = "193"
TestArray(120) = "194"
TestArray(121) = "195"
TestArray(122) = "196"
TestArray(123) = "201"
TestArray(124) = "202"
TestArray(125) = "205"
TestArray(126) = "206"
TestArray(127) = "207"
TestArray(128) = "208"
TestArray(129) = "211"
TestArray(130) = "212"
TestArray(131) = "214"
TestArray(132) = "215"
TestArray(133) = "217"
TestArray(134) = "218"
TestArray(135) = "220"
TestArray(136) = "221"
TestArray(137) = "222"
TestArray(138) = "223"
TestArray(139) = "224"
TestArray(140) = "225"
TestArray(141) = "226"
TestArray(142) = "228"
TestArray(143) = "229"
TestArray(144) = "230"
TestArray(145) = "235"
TestArray(146) = "236"
TestArray(147) = "237"
TestArray(148) = "240"
TestArray(149) = "241"
TestArray(150) = "242"
TestArray(151) = "244"
TestArray(152) = "249"
TestArray(153) = "250"
TestArray(154) = "251"
TestArray(155) = "255"
TestArray(156) = "256"
TestArray(157) = "259"
TestArray(158) = "260"
TestArray(159) = "262"
TestArray(160) = "263"
TestArray(161) = "264"
TestArray(162) = "265"
TestArray(163) = "266"
TestArray(164) = "267"
TestArray(165) = "269"
For intArrayCounter = 0 To 165 Step 1
For lColumnLength = Cells(Rows.Count, 25).End(xlUp).Row To 1 Step -1
If InStr(Cells(lColumnLength, 25), TestArray(intArrayCounter)) > 0 Then
Range("a" & lColumnLength & ":AC" & lColumnLength).Copy Sheet10.Cells(Rows.Count, 1).End(xlUp).Offset(1)
Cells(lColumnLength, 29).EntireRow.Delete
End If
Next
Next
End Sub

I haven't tested this, but I got to run.
But it may give you some food for thought.
Option Explicit
Sub MacroSoFar()
Dim lColumnLength As Long
Dim intArrayCounter As Integer
Dim TestArray(165) As String
TestArray(0) = "4"
TestArray(1) = "5"
TestArray(2) = "6"
TestArray(3) = "7"
TestArray(4) = "8"
TestArray(5) = "9"
TestArray(6) = "10"
TestArray(7) = "11"
TestArray(8) = "12"
TestArray(9) = "14"
TestArray(10) = "19"
TestArray(11) = "20"
TestArray(12) = "21"
TestArray(13) = "25"
TestArray(14) = "30"
TestArray(15) = "35"
TestArray(16) = "36"
TestArray(17) = "37"
TestArray(18) = "41"
TestArray(19) = "42"
TestArray(20) = "43"
TestArray(21) = "46"
TestArray(22) = "47"
TestArray(23) = "48"
TestArray(24) = "51"
TestArray(25) = "52"
TestArray(26) = "53"
TestArray(27) = "60"
TestArray(28) = "63"
TestArray(29) = "65"
TestArray(30) = "66"
TestArray(31) = "67"
TestArray(32) = "68"
TestArray(33) = "69"
TestArray(34) = "70"
TestArray(35) = "71"
TestArray(36) = "72"
TestArray(37) = "73"
TestArray(38) = "74"
TestArray(39) = "75"
TestArray(40) = "76"
TestArray(41) = "77"
TestArray(42) = "78"
TestArray(43) = "79"
TestArray(44) = "80"
TestArray(45) = "81"
TestArray(46) = "82"
TestArray(47) = "83"
TestArray(48) = "84"
TestArray(49) = "85"
TestArray(50) = "86"
TestArray(51) = "87"
TestArray(52) = "88"
TestArray(53) = "89"
TestArray(54) = "90"
TestArray(55) = "91"
TestArray(56) = "92"
TestArray(57) = "93"
TestArray(58) = "94"
TestArray(59) = "96"
TestArray(60) = "97"
TestArray(61) = "98"
TestArray(62) = "99"
TestArray(63) = "101"
TestArray(64) = "102"
TestArray(65) = "103"
TestArray(66) = "106"
TestArray(67) = "107"
TestArray(68) = "108"
TestArray(69) = "109"
TestArray(70) = "111"
TestArray(71) = "112"
TestArray(72) = "113"
TestArray(73) = "115"
TestArray(74) = "116"
TestArray(75) = "117"
TestArray(76) = "118"
TestArray(77) = "121"
TestArray(78) = "122"
TestArray(79) = "125"
TestArray(80) = "129"
TestArray(81) = "130"
TestArray(82) = "131"
TestArray(83) = "132"
TestArray(84) = "133"
TestArray(85) = "134"
TestArray(86) = "137"
TestArray(87) = "138"
TestArray(88) = "142"
TestArray(89) = "143"
TestArray(90) = "144"
TestArray(91) = "145"
TestArray(92) = "146"
TestArray(93) = "147"
TestArray(94) = "155"
TestArray(95) = "156"
TestArray(96) = "157"
TestArray(97) = "158"
TestArray(98) = "159"
TestArray(99) = "161"
TestArray(100) = "162"
TestArray(101) = "169"
TestArray(102) = "170"
TestArray(103) = "173"
TestArray(104) = "174"
TestArray(105) = "175"
TestArray(106) = "176"
TestArray(107) = "180"
TestArray(108) = "181"
TestArray(109) = "182"
TestArray(110) = "183"
TestArray(111) = "184"
TestArray(112) = "185"
TestArray(113) = "186"
TestArray(114) = "187"
TestArray(115) = "188"
TestArray(116) = "189"
TestArray(117) = "190"
TestArray(118) = "192"
TestArray(119) = "193"
TestArray(120) = "194"
TestArray(121) = "195"
TestArray(122) = "196"
TestArray(123) = "201"
TestArray(124) = "202"
TestArray(125) = "205"
TestArray(126) = "206"
TestArray(127) = "207"
TestArray(128) = "208"
TestArray(129) = "211"
TestArray(130) = "212"
TestArray(131) = "214"
TestArray(132) = "215"
TestArray(133) = "217"
TestArray(134) = "218"
TestArray(135) = "220"
TestArray(136) = "221"
TestArray(137) = "222"
TestArray(138) = "223"
TestArray(139) = "224"
TestArray(140) = "225"
TestArray(141) = "226"
TestArray(142) = "228"
TestArray(143) = "229"
TestArray(144) = "230"
TestArray(145) = "235"
TestArray(146) = "236"
TestArray(147) = "237"
TestArray(148) = "240"
TestArray(149) = "241"
TestArray(150) = "242"
TestArray(151) = "244"
TestArray(152) = "249"
TestArray(153) = "250"
TestArray(154) = "251"
TestArray(155) = "255"
TestArray(156) = "256"
TestArray(157) = "259"
TestArray(158) = "260"
TestArray(159) = "262"
TestArray(160) = "263"
TestArray(161) = "264"
TestArray(162) = "265"
TestArray(163) = "266"
TestArray(164) = "267"
TestArray(165) = "269"
Dim oSheet As Variant, nSheet As Variant, oList As New Collection, nList As New Collection
oSheet = Range("A1:AC" & Cells(Rows.Count, 25).End(xlUp).Row).Value
For intArrayCounter = 0 To 165 Step 1
For lColumnLength = Cells(Rows.Count, 25).End(xlUp).Row To 1 Step -1
If InStr(oSheet(lColumnLength, 25), TestArray(intArrayCounter)) > 0 Then
' Add to list in order
nList.Add Range("a" & lColumnLength & ":AC" & lColumnLength).Value
Else
' Add to list in reverse order
oList.Add Range("a" & lColumnLength & ":AC" & lColumnLength).Value
End If
Next
Next
For i = oList.Count To 1 Step -1
For j = 1 To 29
oSheet(i, j) = oList(i)(1, j)
Next j
Next i
Range("A1:AC" & Cells(Rows.Count, 25).End(xlUp).Row) = oSheet
Range("A" & oList.Count + 1 & ":A" & Cells(Rows.Count, 25).End(xlUp).Row).EntireRow.Delete Shift:=xlUp
nSheet = Sheet10.Range("A1:AC" & nList.Count).Offset(Sheet10.Range("A" & Sheet10.UsedRange.Rows.Count).End(xlUp).Row).Value
For i = nList.Count To 1
For j = 1 To 29
nSheet(i, j) = nList(i)(1, j)
Next j
Next i
Sheet10.Range("A1:AC" & nList.Count).Offset(Sheet10.Range("A" & Sheet10.UsedRange.Rows.Count).End(xlUp).Row) = nSheet
Set nList = Nothing: Set oList = Nothing:Set oSheet = Nothing: Set nSheet = Nothing
End Sub

Related

Add picture to objects from array table in Lua

I am creating 8 images using Cheat Engine Lua script and I want to add some pictures to the images from an array table.
the_famous = {
{photo = "AlbertEinstein.jpg", nickName = "einstein", actorName = "Albert Einstein", profession = "Physicist", creation = "Theory of relativity", nationality = "Germany", life = "14 March 1879 - 18 April 1955"},
{photo = "Mozart.jpg", nickName = "mozart", actorName = "Wolfgang Amadeus Mozart", profession = "Classical Music Composer", creation = "Symphony No.40", nationality = "Austria", life = "27 January 1756 – 5 December 1791"},
{photo = "Guevara.jpg", nickName = "guevara", actorName = "Ernesto 'Che' Guevara", profession = "Revolutionary", creation = "Cuban Revolution", nationality = "Cuba, Argentina ", life = "14 June 1928 - 9 October 1967"},
{photo = "BruceLee.jpg", nickName = "bruce lee", actorName = "Bruce Lee (Lee Jun Fan)", profession = "Martial Artist", creation = "Father of MMA", nationality = "Hongkong, America", life = "27 November 1940 - 20 July 1973"},
{photo = "Marilyn.jpg", nickName = "marilyn monroe", actorName = "Marilyn Monroe (Norma Jeane Mortenson)", profession = "Artist", creation = "The most famous sex symbol", nationality = "America", life = "1 June 1926 - 5 August 1962"}}
function start()
if #the_famous ~= 0 then
the_famous.ItemIndex = 0
local idx = the_famous.ItemIndex
for i = 1, 8 do
local idx = tableTemp.ItemIndex
local img = string.format('image1'..i) -- images name start with 'image11' till 'image18'
local pic = the_famous[i].photo
img.Picture.loadFromFile(path_to_images_stored..tostring(pic))
img.Hint = the_famous[i].nickname
idx = idx + 1
end
end
end
But the function above doesn't work. How I can do it properly?
Solved
I have change my script:
local cleft = 20
local ctop = 20
function getCategory(sender)
local cat = sender.Name
if cat == 'btnFamous' then
while #tableTemp ~= 0 do rawset(tableTemp, #tableTemp, nil) end
tableTemp = {}
for z=1, #the_famous do tableTemp[z] = the_famous[z] end
else
return nil
end
for i = 1, 24 do
local newImg = createImage(mPanel)
newImg.width = 90
newImg.height = 90
newImg.top = ctop
newImg.left = cleft
newImg.Stretch = true
newImg.Picture.loadFromFile(famous_img..tostring(tableTemp[i].photo))
newImg.showHint = true
newImg.Hint = tostring(tableTemp[i].nickName)
newImg.Name = 'pic00'..i
cleft = cleft + 100
if i == 8 or i == 16 then
cleft = 20
ctop = ctop + 100
end
newImg.OnMouseEnter = function()
hglight.visible=true
hglight.setPosition(newImg.Left-10, newImg.Top-10)
end
newImg.OnMouseLeave = function()
hglight.visible=false
hglight.setPosition(newImg.Left-10, newImg.Top-10)
end
end
end
All works properly

AngularJS Getting Data response in console as null but in Postman is not null

Postman and Direct URL Response
"MenuId": 2010,
"KitchenId": 2005,
"Categoryid": 1,
"CategoryName": "Starters",
"SubCategoryId": 1,
"SubCategoryName": "Veg Starters",
"Name": "Paneer Kabab",
"Description": "Paneer fried",
"ImageURL": "noimage.png",
"Foodtype": 1,
"NetPrice": 70.00,
"NetGST": 3.50,
"NetTotal": 83.50,
"ListPrice": 84.00,
"ListGST": 4.20,
"ListTotal": 99.20,
"PackingCharge": 11.00,
"Discount": null,
"TotalOrders": 0.00,
"Ratings": null,
"MenuStatus": 1,
"VegTypeId": 1,
"GetButton_no": [
{
**"ButtonNo_No": 99.20**
}
],
Browser Console
{ "MenuId": 2010,
"KitchenId": 2005,
"Categoryid": 1,
"CategoryName": "Starters",
"SubCategoryId": 1,
"SubCategoryName": "Veg Starters",
"Name": "Paneer Kabab",
"Description": "Paneer fried",
"ImageURL": "noimage.png",
"Foodtype": 1,
"NetPrice": 70.00,
"NetGST": 3.50,
"NetTotal": 83.50,
"ListPrice": 84.00,
"ListGST": 4.20,
"ListTotal": 99.20,
"PackingCharge": 11.00,
"Discount": null,
"TotalOrders": 0.00,
"Ratings": null,
"MenuStatus": 1,
"VegTypeId": 1,
"GetButton_no": [
{
**"ButtonNo_No": null**
}
],
}
Why is the same API Behaving different behaviour , I am using Entity Framework for that.
public IEnumerable<KitchenMenu_CategoryModel> GetKitchenMenubyKitchennew(int kid,string Username)
{
var result = db.tblKitchens.Where(x => x.Id == kid).Select(x => new KitchenMenu_CategoryModel
{
KitchenId = x.Id,
KitchenName = x.KitchenName,
KitchenType = x.KitchenType,
Area = x.Area,
Address1 = x.Address1,
Address2 = x.Address2,
//CId = x.CityId,
Pincode = x.Pincode,
Email = x.Email,
Website = x.Website,
Landline = x.Landline,
Halal = x.Halal,
Category = x.Category,
Branches = x.Branches,
AvgCost = x.AvgCost,
Fssai = x.Fssai,
FssaiPath = x.FssaiPath,
RegisterStatus = x.RegisterStatus,
Logo = db.tblKitchenMedias.Where(r => r.KitchenId == x.Id).Select(r => r).FirstOrDefault().Logo,
Banner = db.tblKitchenMedias.Where(s => s.KitchenId == x.Id).Select(s => s).FirstOrDefault().Banner,
GetCategory = db.tblGetCategories.Where(y => y.Kitchenid == x.Id).Select(y => new CategoryModel
{
CategoryId = y.Categoryid,
Kitchenid = y.Kitchenid,
CategoryName = y.tblCategory.CategoryName,
SubCateogry = db.tblGetSubCategories.Where(z => z.Categoryid == y.Categoryid && z.Kitchenid == y.Kitchenid).Select(z => new SubCategoryModel
{
Categoryid = z.Categoryid,
SubCategoryName = z.tblSubCategory.SubCategoryName,
Kitchenid = z.Kitchenid,
GetMenu = db.tblMenus.Where(a => a.SubCategoryId == z.SubCategoryid && a.KitchenId == z.Kitchenid).Select(a => new MenuModel
{
MenuId = a.MenuId,
Name = a.Name,
Description = a.Description,
Discount = a.Discount,
ImageURL = a.ImageURL,
ListGST = a.ListGST,
ListPrice = a.ListPrice,
ListTotal = a.ListTotal,
NetGST = a.NetGST,
NetPrice = a.NetPrice,
TotalOrders = a.TotalOrders,
KitchenId = a.KitchenId,
SubCategoryId = a.SubCategoryId,
MenuStatus = a.MenuStatus,
NetTotal = a.NetTotal,
VegTypeId = a.VegTypeId,
Categoryid = a.Categoryid,
CategoryName = a.tblCategory.CategoryName,
SubCategoryName = a.tblSubCategory.SubCategoryName,
Ratings = a.Ratings,
Foodtype = a.Foodtype,
PackingCharge = a.PackingCharge,
GetButton_no =db.tblcarts.Where(d => d.Username == Username && d.KitchenId == kid && d.MenuId == a.MenuId).Select(d => new ButtonModel
{
ButtonNo_No =d.TotalPrice,
}
).ToList(),
//ButtonNo_No = db.tblcarts.Where(d => d.Username == Username && d.KitchenId == a.KitchenId && d.MenuId == a.MenuId).Select(d => d).FirstOrDefault().Quantity,
//Button_No =db.spCountCartButton(Username,a.KitchenId,a.MenuId).Select(d=>d).FirstOrDefault(),
GetMenuAttribute = db.tblMenuAttributes.Where(b => b.Menuid == a.MenuId).Select(b => new MenuAttributeModel
{
MenuAttributeId = b.MenuAttributeId,
Menuid = b.Menuid,
AttributeType = b.AttributeType,
MenuAttribute = b.MenuAttribute,
MenuDescription = b.MenuDescription,
NetPrice = b.NetPrice,
NetGST = b.NetGST,
NetTotal = b.NetTotal,
ListPrice = b.ListPrice,
ListGST = b.ListGST,
ListTotal = b.ListTotal,
PackingCharge = b.PackingCharge,
}
).ToList(),
}
).ToList(),
}
).ToList(),
}
).ToList(),
}
).ToList();
return result;
}
--API Controller
[Route("api/GetMenuBykidnew")]
[HttpGet]
public HttpResponseMessage GetMenuBykid(int kid, string Username)
{
//var data = new List();
ApiBusiness ApiBus = new ApiBusiness();
var result = ApiBus.GetKitchenMenubyKitchennew(kid, Username);
return new HttpResponseMessage()
{
Content = new StringContent(JArray.FromObject(result).ToString(), Encoding.UTF8, "application/json")
};
}
The response is very strange getting different response in browser console and postman

Filter 2 struct/ arrays by mapping by specific

Im a new user using swift 3 and xcode 8.3. Currently facing a problem to filter 2 array/struc where in console output as below:
A_List : Optional([117, 115, 18])
B_List : Optional([{
URL = "169.jpeg";
categories = "A";
description = "description XXX";
height = 128;
id = 1;
likes = "1.00";
name = "Cake - Baked";
price = "13.78";
width = 128;
}, {
URL = "1622.jpeg";
categories = "A";
description = "Baked till golden";
height = 128;
id = 15;
likes = "1.00";
name = "Croissant";
price = "3.71";
width = 128;
}, {
URL = "11.jpeg";
categories = "A";
description = "description Crispy.";
height = 128;
id = 18;
likes = "1.00";
name = "Plain";
price = "2.65";
width = 128;
}, {
URL = "1622.jpeg";
categories = "A";
description = "A ";
height = 128;
id = 103;
likes = "1.00";
name = "America Pie";
price = "2.12";
width = 128;
}, {
URL = "11.jpeg";
categories = "B";
description = "Puff";
height = 128;
id = 115;
likes = "1.00";
name = "Puff";
price = "2.12";
width = 128;
}, {
URL = "168.jpeg";
categories = "C";
description = "description YYY";
height = 128;
id = 117;
likes = "1.00";
name = "Normal";
price = "3.18";
width = 128;
}])
I want to return B_List full info as var filtered_List = [AnyObject]() where only contains of A_List id number 117, 115, and 18 which look like as below:
filtered_List : Optional([{
URL = "11.jpeg";
categories = "A";
description = "description Crispy.";
height = 128;
id = 18;
likes = "1.00";
name = "Plain";
price = "2.65";
width = 128;
}, {
URL = "11.jpeg";
categories = "B";
description = "Puff";
height = 128;
id = 115;
likes = "1.00";
name = "Mini Puff";
price = "2.12";
width = 128;
}, {
URL = "168.jpeg";
categories = "C";
description = "description YYY";
height = 128;
id = 117;
likes = "1.00";
name = "Normal";
price = "3.18";
width = 128;
}])
I have tried few code and read tutorial in youtube, but unfortunately did not find any solution and it limited to swift2 sample.
Currently, my code tried as below:
var filtered_List = [AnyObject]()
let fullrList = B_List?.map{$0["id"] as! String}.map{_ in A_List}
filtered_List.append(fullrList as AnyObject )
print("result :\(filtered_List)")
Very Appreciated if someone expert can guide or give your solution here.
You should store your desired IDs in a Set, rather than an Array. You're just need a simple filter operation:
let desiredIds: Set = [117, 115, 18]
B_List.filter{ $0["id"].map{ desiredIds.contains($0) } ?? false } as [AnyObject]
Thanks for everyone who reply this topic specially to #Alexander. Here my solutions to share that may not the perfect one as others.
var resultAnyObject = [AnyObject]()
var aListIds = [String]()
for i in A_List! {
aListIds.append(i as! String)
}
//#Alexander : thanks for code below:
let desiredIds = aListIds
let fullList = B_List?.filter{ $0["id"].map{desiredIds.contains($0 as! String) } ?? false };
resultAnyObject.append(fullList as AnyObject)
print("Result of filtered_List :\(resultAnyObject)")

Excel bracket using VBA not working?

Making an autograde of sorts for an excel bracket with the guesses of each bracket in the ranges marked. Still clearly work in progress, finally have it running through, but the loop isn't working, it's returning pointSum of 0. Trying to sum += 10 when points is true.
Sub foo()
Dim Player(1 To 35) As String
Player(1) = Range("M2")
Player(2) = Range("M4")
Player(3) = Range("M10")
Player(4) = Range("M12")
Player(5) = Range("M22")
Player(6) = Range("M24")
Player(7) = Range("M32")
Player(8) = Range("M34")
Player(9) = Range("L1")
Player(10) = Range("L3")
Player(11) = Range("L5")
Player(12) = Range("L7")
Player(13) = Range("L9")
Player(14) = Range("L11")
Player(15) = Range("L13")
Player(16) = Range("L15")
Player(17) = Range("L20")
Player(18) = Range("L22")
Player(19) = Range("L24")
Player(20) = Range("L26")
Player(21) = Range("L28")
Player(22) = Range("L30")
Player(23) = Range("L32")
Player(24) = Range("L34")
Player(25) = Range("K2")
Player(26) = Range("K6")
Player(27) = Range("K10")
Player(28) = Range("K14")
Player(29) = Range("K21")
Player(30) = Range("K25")
Player(31) = Range("K29")
Player(32) = Range("J4")
Player(33) = Range("J12")
Player(34) = Range("J23")
Player(35) = Range("J31")
Dim Winner(1 To 18) As String
Winner(1) = "Mohler"
Winner(2) = "Scotter"
Winner(3) = "DKGAY"
Winner(4) = "Lassie"
Winner(5) = "Mohler"
Winner(6) = "Gunnar"
Winner(7) = "Gord'n"
Winner(8) = "Hellmers"
Winner(9) = "Evan Brown"
Winner(10) = "Jerru"
Winner(11) = "Case"
Winner(12) = "Lassie"
Winner(13) = "Mohler"
Winner(14) = ""
Winner(15) = ""
Winner(16) = "Mohler"
Winner(17) = "Mohler"
Winner(18) = ""
Dim Guess(1 To 18) As String
Guess(1) = Player(10)
Guess(2) = Player(14)
Guess(3) = Player(18)
Guess(4) = Player(23)
Guess(5) = Player(25)
Guess(6) = Player(26)
Guess(7) = Player(27)
Guess(8) = Player(28)
Guess(9) = Player(29)
Guess(10) = Player(30)
Guess(11) = Player(31)
Guess(12) = Player(32)
Guess(13) = ""
Guess(14) = ""
Guess(15) = ""
Guess(16) = ""
Guess(17) = ""
Guess(18) = ""
Dim points(1 To 18) As Boolean
points(1) = False
points(2) = False
points(3) = False
points(4) = False
points(5) = False
points(6) = False
points(7) = False
points(8) = False
points(9) = False
points(10) = False
points(11) = False
points(12) = False
points(13) = False
points(14) = False
points(15) = False
points(16) = False
points(17) = False
points(18) = False
Dim pointSum As Double
pointSum = 0
Dim pointValue(1 To 6) As Double
pointValue(1) = 10
pointValue(2) = 20
pointValue(3) = 30
pointValue(4) = 40
pointValue(5) = 50
pointValue(6) = 60
For i = 1 To 12 Step 1
If Guess(i) = Winner(i) Then
points(i) = True And pointSum = pointSum + 10
Else
points(i) = False
End If
Next
Range("O1") = pointSum
MsgBox "Done!"
End Sub
For i = 1 To 12 Step 1
If Guess(i) = Winner(i) Then
points(i) = True And pointSum = pointSum + 10
Else
points(i) = False
End If
Next
Ok, several things.
Step 1
That's the default; the Step part of the For loop definition is usually only included when its value is different than 1. But that won't cause any problems.
points(i) = True And pointSum = pointSum + 10
If I understand your question correctly...
the loop isn't working, it's returning pointSum of 0. Trying to sum += 10 when points is true.
You're not assigning pointSum anywhere. The above line of code is interpreted as follows:
points(i) = (True And (pointSum = pointSum + 10))
In other words:
points(i) = (True And False)
In other words:
points(i) = False
When you make an assignment, the variable being assigned to goes on the left side of the assignment operator (=):
foo = 42 'assigns value 42 to foo
The confusion seems to be that in VBA, the comparison operator is also a = token:
If foo = 42 Then 'true when the value of foo is 42
To increment pointSum by 10 when points(i) is True, you can do this:
If points(i) = True Then pointSum = pointSum + 10
Which can be simplified to:
If points(i) Then pointSum = pointSum + 10
Because the (boolean expression) in If (boolean expression) Then doesn't need to be compared to True or False when you're already working with a Boolean variable.
Hope it helps!

lights out game using CORONA SDK

am trying to devalope a lights out game with CORONA SDK
but am not able to figure out a way for looping it !!!
how many functions to create and the way to keep this going
here is my code (its dummy but a friend gave it to me as am trying to go on from there )
obj = nil
px = 35
py = 50
r = 22
xi = 60
yi = 60
x1y1 = display.newCircle(px+xi*0,py+yi*0,r) x1y1.id = "x1y1"
x2y1 = display.newCircle(px+xi*1,py+yi*0,r) x2y1.id = "x2y1"
x3y1 = display.newCircle(px+xi*2,py+yi*0,r) x3y1.id = "x3y1"
x4y1 = display.newCircle(px+xi*3,py+yi*0,r) x4y1.id = "x4y1"
x5y1 = display.newCircle(px+xi*4,py+yi*0,r) x5y1.id = "x5y1"
x1y2 = display.newCircle(px+xi*0,py+yi*1,r) x1y2.id = "x1y2"
x2y2 = display.newCircle(px+xi*1,py+yi*1,r) x2y2.id = "x2y2"
x3y2 = display.newCircle(px+xi*2,py+yi*1,r) x3y2.id = "x3y2"
x4y2 = display.newCircle(px+xi*3,py+yi*1,r) x4y2.id = "x4y2"
x5y2 = display.newCircle(px+xi*4,py+yi*1,r) x5y2.id = "x5y2"
x1y3 = display.newCircle(px+xi*0,py+yi*2,r) x1y3.id = "x1y3"
x2y3 = display.newCircle(px+xi*1,py+yi*2,r) x2y3.id = "x2y3"
x3y3 = display.newCircle(px+xi*2,py+yi*2,r) x3y3.id = "x3y3"
x4y3 = display.newCircle(px+xi*3,py+yi*2,r) x4y3.id = "x4y3"
x5y3 = display.newCircle(px+xi*4,py+yi*2,r) x5y3.id = "x5y3"
x1y4 = display.newCircle(px+xi*0,py+yi*3,r) x1y4.id = "x1y4"
x2y4 = display.newCircle(px+xi*1,py+yi*3,r) x2y4.id = "x2y4"
x3y4 = display.newCircle(px+xi*2,py+yi*3,r) x3y4.id = "x3y4"
x4y4 = display.newCircle(px+xi*3,py+yi*3,r) x4y4.id = "x4y4"
x5y4 = display.newCircle(px+xi*4,py+yi*3,r) x5y4.id = "x5y4"
x1y5 = display.newCircle(px+xi*0,py+yi*4,r) x1y5.id = "x1y5"
x2y5 = display.newCircle(px+xi*1,py+yi*4,r) x2y5.id = "x2y5"
x3y5 = display.newCircle(px+xi*2,py+yi*4,r) x3y5.id = "x3y5"
x4y5 = display.newCircle(px+xi*3,py+yi*4,r) x4y5.id = "x4y5"
x5y5 = display.newCircle(px+xi*4,py+yi*4,r) x5y5.id = "x5y5"
bb = {x1y1,x2y1,x3y1,x4y1,x5y1,x1y2,x2y2,x3y2,x4y2,x5y2,x1y3,x2y3,x3y3,x4y3,x5y3,x1y4,x2y4,x3y4,x4y4,x5y4,x1y5,x2y5,x3y5,x4y5,x5y5}
iClicked = 0
function click(e)
if(e.phase == "ended") then
--circleID = e.target.id
--whichCircle()
print(e.target.id)
obj = e.target
for u=1,25 do
if(obj==bb[u]) then
iClicked = u
end
end
if((iClicked-5) > 0 and (iClicked-5) < 26) then
bb[iClicked-5]:setFillColor(1,0,0)
end
if((iClicked-1) > 0 and (iClicked-1) < 26) then
bb[iClicked-1]:setFillColor(1,0,0)
end
obj:setFillColor(1,0,0)
if((iClicked+1) > 0 and (iClicked+1) < 26) then
bb[iClicked+1]:setFillColor(1,0,0)
end
if((iClicked+5) > 0 and (iClicked+5) < 26) then
bb[iClicked+5]:setFillColor(1,0,0)
end
end
end
for k=1,25 do
bb[k]:addEventListener("touch",click)
end
its all about having 25 circles and lighting them on and off but it doesnt seem to work for me
any good help will be great
Thanks
local myCircles = {}
for y = 1, 5 do
myCircles[y] = {}
for x = 1, 5 do
myCircles[y][x] = display.newCircle(px+xi*0,py+yi*4,r)
myCircles[y][x].id = .id = "x" .. x .. "y" .. y
end
end
or something like that.
Rob

Resources