Hide and Unhide rows based on 9 separate drop downs that update as selections are changed - show-hide

I've only copied a portion of the code I'm working with but its not working to hide unhide rows based on the various selections from 9 separate drop downs. The code should also update the hidden rows when any selection is changed or the clearcontents macro is ran. The closest I can get this is showing only the most recent selection but I need to show the results for all selections at the same time.
Option Explicit
Private Sub InIt()
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i As Range
Dim u As Range
Dim Cel As Range
Set u = Union(Range("J10"), Range("N10"), Range("R10"), Range("V10"), Range("N14"), Range("J14"), Range("N14"), Range("R10"), Range("V14"), Range("I23"))
Set i = Intersect(u, Target)
If i Is Nothing Then Exit Sub
For Each Cel In i
Select Case Target.Value
Case "Yes"
Rows("24:56").Hidden = False
Case "Potatoes (table) growing"
Rows("63:63").Hidden = False
Case "Potatoes (seed) growing"
Rows("64:64").Hidden = False
Case "Growing vegetables and melons and selling them at roadside stands"
Rows("65:65").Hidden = False
Case "Growing vegetables and melons and selling them at market gardens / farmers markets"
Rows("66:66").Hidden = False
Case "Grain growing"
Rows("67:68").Hidden = False
Case "Market gardening except greenhouses"
Rows("69:69").Hidden = False
Case "Mixed vegetables growing except greenhouses"
Rows("70:70").Hidden = False
Case "Citrus groves and farms"
Rows("71:73").Hidden = False
Case "Fruit and tree nut combination farming"
Rows("74:76").Hidden = False
Case "Fruit growers (e.g. pome and stone fruits)"
Rows("77:79").Hidden = False
Case "Non citrus fruit farming"
Rows("80:82").Hidden = False
Case "Small berry fruit farming (e.g. blackberry, blueberry, currant, dewbery, loganberry, raspberry)"
Rows("83:85").Hidden = False
Case "Herb farming (e.g. ginseng, echinacea, etc.) except greenhouses"
Rows("86:86").Hidden = False
Case "Christmas tree growing"
Rows("87:89").Hidden = False
Case "Turf (sod) farming"
Rows("90:90").Hidden = False
Case "Floriculture except greehouses"
Rows("91:91").Hidden = False
Case "Alfalfa, clover, hay or timothy farming"
Rows("92:92").Hidden = False
Case "Fruit and vegetable combination"
Rows("93:93").Hidden = False
Case "Maple syrup and products production"
Rows("94:99").Hidden = False
Case "Combination field crop farming"
Rows("100:101").Hidden = False
Case "Hemp growing"
Rows("102:103").Hidden = False
Case "Hops and grain growing, combination"
Rows("104:104").Hidden = False
Case "Peanut farming"
Rows("105:106").Hidden = False
Case "Seed growers"
Rows("107:108").Hidden = False
Case "Sugar beet farming and grain growing, combination"
Rows("109:110").Hidden = False
Case "Tea farming"
Rows("111:112").Hidden = False
Case "Beef cattle feedlots"
Rows("113:121").Hidden = False
Case "Beef cattle ranching"
Rows("122:130").Hidden = False
Case "Beef cattle finishing - Grassers seasonal"
Rows("131:131").Hidden = False
Case "Dairy cattle and milk production"
Rows("132:136").Hidden = False
Case "Hog - Farrow to Finish - Secondary operations only"
Rows("137:139").Hidden = False
Case "Hog - Finishing only - Secondary operations only"
Rows("140:142").Hidden = False
Case "Chicken egg production"
Rows("143:149").Hidden = False
Case "Broiler and other meat-type chicken production"
Rows("150:156").Hidden = False
Case "Caponor or Cornish hens farming"
Rows("157:163").Hidden = False
Case "Turkey production"
Rows("164:170").Hidden = False
Case "Egg hatcheries, poultry"
Rows("171:179").Hidden = False
Case "Combination poultry and egg production"
Rows("180:186").Hidden = False
Case "Ostrich or emu farming"
Rows("187:188").Hidden = False
Case "Pheasant, geesem, goose, duck quail or guinea fowl farming"
Rows("189:190").Hidden = False
Case "Pigeon or squab farming"
Rows("191:1920").Hidden = False
Case "Lamb or sheep farming, including feedlots"
Rows("193:203").Hidden = False
Case "Milk production, goat farming"
Rows("204:206").Hidden = False
Case "Aquaculture inland operations only"
Rows("207:207").Hidden = False
Case "Apiaries - honey"
Rows("208:211").Hidden = False
Case "Leafcutter bees raising"
Rows("212:213").Hidden = False
Case "Gathering of wild mushrooms and truffles"
Rows("214:214").Hidden = False
Case "Wild berry picking"
Rows("215:215").Hidden = False
Case "Worm gathering"
Rows("216:216").Hidden = False
Case "Custom crop spraying"
Rows("217:225").Hidden = False
Case "Custom granular application (spreading fines)"
Rows("226:232").Hidden = False
Case "Custom seed treating"
Rows("233:235").Hidden = False
Case "Custom soil amendment application"
Rows("236:241").Hidden = False
Case "Custom harvesting"
Rows("242:243").Hidden = False
Case "Custom mobile grain cleaning service"
Rows("244:245").Hidden = False
Case "Custom planting or seeding"
Rows("246:247").Hidden = False
Case "Custom tillage or land breaking"
Rows("248:249").Hidden = False
Case "Orchard cultivation services"
Rows("250:251").Hidden = False
Case "Agronomy"
Rows("252:252").Hidden = False
Case "Farm produce (e.g., fruit, vegetable) packing service"
Rows("253:253").Hidden = False
Case "Seed and / or chemical distributors"
Rows("254:257").Hidden = False
Case "Fruit picking service, hand (e.g., apple, strawberry, blueberry, cherry)"
Rows("258:258").Hidden = False
Case "Custom grain drying service"
Rows("259:261").Hidden = False
Case "Grain fumigation service"
Rows("262:266").Hidden = False
Case "Custom haying and/or chopping"
Rows("267:268").Hidden = False
Case "Hulling and shelling of almonds, filberts, nuts, peanuts, pecans and walnuts"
Rows("269:269").Hidden = False
Case "Animal semen collection, production and storage services"
Rows("270:273").Hidden = False
Case "Artificial insemination services, animal specialties and livestock"
Rows("274:275").Hidden = False
Case "Breeding services for livestock"
Rows("276:277").Hidden = False
Case "Brand inspector"
Rows("278:278").Hidden = False
Case "Catching poultry, with no hauling"
Rows("279:280").Hidden = False
Case "Cattle dehorning and hoof trimming services"
Rows("281:281").Hidden = False
Case "Chick sexing service"
Rows("282:282").Hidden = False
Case "Cleaning poultry houses"
Rows("283:283").Hidden = False
Case "Custom manure hauling, corral and feedlot cleaning, service"
Rows("284:286").Hidden = False
Case "Egg grading station, fee-based"
Rows("287:287").Hidden = False
Case "Embryo transplant service, agricultural"
Rows("288:289").Hidden = False
Case "Farriers (horseshoeing)"
Rows("290:293").Hidden = False
Case "Fur pelting service"
Rows("294:294").Hidden = False
Case "Sheep dipping and shearing services"
Rows("295:296").Hidden = False
Case "Vaccinating livestock (except by veterinarians)"
Rows("297:299").Hidden = False
Case "Electrician (no alarm testing or hook up), farm based business"
Rows("300:306").Hidden = False
Case "Plumbing and heating contractors, farm based business"
Rows("307:330").Hidden = False
Case "Plumbing contractors, farm based business"
Rows("331:338").Hidden = False
Case "Assembly and installation for others of agricultural equipment in farm outbuildings, farm based business"
Rows("339:344").Hidden = False
Case "Automatic gate installation (e.g., garage, lane), farm based business"
Rows("345:350").Hidden = False
Case "Drywall finishing (e.g., sanding, spackling, stippling, taping, texturing), farm based business"
Rows("351:357").Hidden = False
Case "Drywall installation, including the hanging of drywall, sheetrock, plasterboard, gypsum wallboard and subsequent finishing, farm based business"
Rows("358:364").Hidden = False
Case "Heavy machinery painting, farm based business"
Rows("365:372").Hidden = False
Case "Painting contractors, farm based business"
Rows("373:382").Hidden = False
Case "Flooring contractors, excluding hardwood refinishing, farm based business"
Rows("383:383").Hidden = False
Case "Tile and terrazzo contractors, farm based business"
Rows("384:384").Hidden = False
Case "Deck and fence construction (wooden excluding pasture fencing), farm based business"
Rows("385:390").Hidden = False
Case "Brush clearing or cutting, farm based business"
Rows("391:395").Hidden = False
Case "Cutting of rights-of-way contractor, farm based business"
Rows("396:400").Hidden = False
Case "Land clearing contractors farm based business"
Rows("401:407").Hidden = False
Case "Power, communication and pipelines, rights of way clearance (except maintenance), farm based business"
Rows("408:412").Hidden = False
Case "Septic tanks and weeping tile installation, farm based business"
Rows("413:431").Hidden = False
Case "Brick pavers installation (e.g., driveways, patios and sidewalks), farm based business"
Rows("432:437").Hidden = False
Case "Concrete patio construction, farm based business"
Rows("438:446").Hidden = False
Case "Fences and corral installation, erection or repair, farm based business"
Rows("447:452").Hidden = False
Case "Mail boxes erection (single residential/farm - outdoor), farm based business"
Rows("453:455").Hidden = False
Case "Post Hole digging contractors, farm based business"
Rows("456:456").Hidden = False
Case "Dog and cat food manufacturing, excluding supplement additives, farm based business"
Rows("457:461").Hidden = False
Case "Other animal food manufacturing, excluding supplement additives, farm based business"
Rows("462:462").Hidden = False
Case "Barley feed, chopped, crushed or ground, excluding supplement additives, manufacturing, farm based business"
Rows("463:465").Hidden = False
Case "Bird food manufacturing, excluding supplement additives, farm based business"
Rows("466:466").Hidden = False
Case "Complete livestock feed manufacturing, excluding supplement additives, farm based business"
Rows("467:469").Hidden = False
Case "Specialty feed manufacturing excluding supplement additives (e.g., for mice, guinea pig, mink, earthworm, rabbit), farm based business"
Rows("470:470").Hidden = False
Case "Micro and macro feed premixes manufacturing for animals, excluding dogs and cats or supplement additives, farm based business"
Rows("471:471").Hidden = False
Case "Milling grain to make livestock feed excluding supplement additives, farm based business"
Rows("472:474").Hidden = False
Case "Pet food manufacturing excluding dogs and cats or supplement additives, farm based business"
Rows("475:475").Hidden = False
Case "Shell crushing and grinding for animal feed, excluding supplement additives, farm based business"
Rows("476:476").Hidden = False
Case "Flour milling, farm based business"
Rows("477:479").Hidden = False
Case "Rice or corn milling and malt manufacturing, farm based business"
Rows("480:483").Hidden = False
Case "Tapioca manufacturing, farm based business"
Rows("484:486").Hidden = False
Case "Wet grain or corn milling, farm based business"
Rows("487:488").Hidden = False
Case "Edible and inedible oilseed products, farm based business"
Rows("489:490").Hidden = False
Case "Oilseed crushing mills, farm based business"
Rows("491:492").Hidden = False
Case "Oils made from purchased oils (e.g., rapeseed (canola), cottonseed, soybean, olive, peanut, linseed, palm-kernel, sunflower), farm based business"
Rows("493:495").Hidden = False
Case "Breakfast cereal manufacturing, farm based business"
Rows("496:498").Hidden = False
Case "Sugar manufacturing, farm based business"
Rows("499:505").Hidden = False
Case "Dried beet pulp manufacturing, farm based business"
Rows("506:511").Hidden = False
Case "Non-chocolate confectionery manufacturing, farm based business"
Rows("512:517").Hidden = False
Case "Cake ornaments & edible confectionery manufacturing, farm based business"
Rows("518:522").Hidden = False
Case "Candied fruit & fruit peel products manufacturing (e.g., candied, glazed, crystallized), farm based business"
Rows("523:526").Hidden = False
Case "Chewing gum manufacturing, farm based business"
Rows("527:529").Hidden = False
Case "Corn confections manufacturing (e.g., popcorn balls, candy-coated popcorn products), farm based business"
Rows("530:534").Hidden = False
Case "Cough drops or lozenges manufacturing (except medicated), farm based business"
Rows("535:537").Hidden = False
Case "Sugared and stuffed dates manufacturing, farm based business"
Rows("538:542").Hidden = False
Case "Energy food bar manufacturing, farm based business"
Rows("543:547").Hidden = False
Case "Fudge manufacturing, farm based business"
Rows("548:552").Hidden = False
Case "Granola bars and clusters manufacturing, farm based business"
Rows("553:557").Hidden = False
Case "Halvah manufacturing, farm based business"
Rows("558:562").Hidden = False
Case "Marshmallows manufacturing, farm based business"
Rows("563:567").Hidden = False
Case "Covered nuts manufacturing, farm based business"
Rows("568:572").Hidden = False
Case "Synthetic chocolate, marzipan or toffee manufacturing, farm based business"
Rows("573:575").Hidden = False
Case "Confectionery manufacturing from purchased chocolate, farm based business"
Rows("576:580").Hidden = False
Case "Chocolate-covered granola bars made from purchased chocolate, farm based business"
Rows("581:585").Hidden = False
Case "Drinks, cocoa powder or instant chocolate made from purchased chocolate, farm based business"
Rows("586:588").Hidden = False
Case "Chocolate-covered nuts made from purchased chocolate, farm based business"
Rows("589:591").Hidden = False
Case "Frozen food manufacturing, farm based business"
Rows("592:597").Hidden = False
Case "Blast freezing on a contract basis, farm based business"
Rows("598:598").Hidden = False
Case "Frozen fruit and vegetable juice concentrates manufacturing, farm based business"
Rows("599:604").Hidden = False
Case "Dietetic, homogenized or low sodium frozen foods, farm based business"
Rows("605:610").Hidden = False
Case "Frozen whipped topping manufacturing, farm based business"
Rows("611:616").Hidden = False
Case "Fruit and vegetable canning, pickling & drying, farm based business"
Rows("617:621").Hidden = False
Case "Bouillon canning, farm based business"
Rows("622:626").Hidden = False
Case "Broth canning (except seafood), farm based business"
Rows("627:631").Hidden = False
Case "Canned pasta manufacturing, farm based business"
Rows("632:636").Hidden = False
Case "Canning soups (except seafood), farm based business"
Rows("637:641").Hidden = False
Case "Catsup & similar tomato sauces manufacturing, farm based business"
Rows("642:646").Hidden = False
Case "Chili con carne canning, farm based business"
Rows("647:651").Hidden = False
Case "Chinese foods canning, farm based business"
Rows("652:656").Hidden = False
Case "Dehydrating fruits and vegetables (except sun drying), farm based business"
Rows("657:658").Hidden = False
Case "Freeze-drying fruits & vegetables, farm based business"
Rows("659:664").Hidden = False
Case "Gravy canning, farm based business"
Rows("665:669").Hidden = False
Case "Canned hominy manufacturing, farm based business"
Rows("670:674").Hidden = False
Case "Horseradish canning (except sauce), farm based business"
Rows("675:679").Hidden = False
Case "Infant and junior food canning, farm based business"
Rows("680:684").Hidden = False
Case "Pork and beans canning, farm based business"
Rows("685:689").Hidden = False
Case "Potato products dehydrating (e.g., flakes, granules), farm based business"
Rows("690:694").Hidden = False
Case "Preserves, jams and jellies manufacturing, farm based business"
Rows("695:699").Hidden = False
Case "Relishes canning, farm based business"
Rows("700:704").Hidden = False
Case "Dry salad dressing mixes, farm based business"
Rows("705:709").Hidden = False
Case "Dry Sauce mixes, farm based business"
Rows("710:714").Hidden = False
Case "Sauerkraut manufacturing, farm based business"
Rows("715:719").Hidden = False
Case "Fluid milk manufacturing, farm based business"
Rows("720:724").Hidden = False
Case "Cottage cheese manufacturing, farm based business"
Rows("725:729").Hidden = False
Case "Cream manufacturing, farm based business"
Rows("730:734").Hidden = False
Case "Sour-cream based dips manufacturing, farm based business"
Rows("735:740").Hidden = False
Case "Fresh non-alcholic eggnog manufacturing, farm based business"
Rows("741:745").Hidden = False
Case "Fluid milk substitutes manufacturing, farm based business"
Rows("746:750").Hidden = False
Case "Milk-based drinks manufacturing (except dietary), farm based business"
Rows("751:755").Hidden = False
Case "Non-dairy liquid creamers manufacturing, farm based business"
Rows("756:761").Hidden = False
Case "Sour cream substitutes manufacturing, farm based business"
Rows("762:767").Hidden = False
Case "Sour cream manufacturing, farm based business"
Rows("768:772").Hidden = False
Case "Substitute milk products manufacturing, farm based business"
Rows("773:778").Hidden = False
Case "Whipping cream manufacturing, farm based business"
Rows("779:783").Hidden = False
Case "Yogurt manufacturing (except frozen), farm based business"
Rows("784:789").Hidden = False
Case "Butter, cheese & dry and condensed dairy product manufacturing, farm based business"
Rows("790:793").Hidden = False
Case "Anhydrous butterfat manufacturing, farm based business"
Rows("794:797").Hidden = False
Case "Animal feed dry milk products manufacturing, farm based business"
Rows("798:800").Hidden = False
Case "Baby formula fresh, processed & bottled manufacturing, farm based business"
Rows("801:806").Hidden = False
Case "Butter, creamery & whey manufacturing, farm based business"
Rows("807:810").Hidden = False
Case "Dry & wet casein manufacturing, farm based business"
Rows("811:812").Hidden = False
Case "Cheese manufacturing, farm based business"
Rows("813:817").Hidden = False
Case "Cheese spreads manufacturing, farm based business"
Rows("818:822").Hidden = False
Case "Imitation, substitute or analog cheese manufacturing, farm based business"
Rows("823:827").Hidden = False
Case "Condensed, evaporated or powdered whey manufacturing, farm based business"
Rows("828:831").Hidden = False
Case "Dried & powdered cream manufacturing, farm based business"
Rows("832:835").Hidden = False
Case "Dehydrated milk manufacturing, farm based business"
Rows("836:839").Hidden = False
Case "Dairy & non-dairy base drinks manufacturing, farm based business"
Rows("840:844").Hidden = False
Case "Ice milk mix manufacturing, farm based business"
Rows("845:849").Hidden = False
Case "Milk concentrated, condensed, dried, evaporated or powdered manufacturing, farm based business"
Rows("850:853").Hidden = False
Case "Milk UHT (ultra-high temperature) manufacturing, farm based business"
Rows("854:858").Hidden = False
Case "Non-dairy dry creamers manufacturing, farm based business"
Rows("859:863").Hidden = False
Case "Nonfat dry milk manufacturing, farm based business"
Rows("864:867").Hidden = False
Case "Soy beverages manufacturing, farm based business"
Rows("868:872").Hidden = False
Case "Substitute butter & cheese manufacturing, farm based business"
Rows("873:877").Hidden = False
Case "Liquid raw whey, farm based business"
Rows("878:881").Hidden = False
Case "Yogurt mix manufacturing, farm based business"
Rows("882:886").Hidden = False
Case "Ice cream, frozen pops & frozen dessert manufacturing, farm based business"
Rows("887:892").Hidden = False
Case "Sorbets or sherbets manufacturing, farm based business"
Rows("893:898").Hidden = False
Case "Tofu frozen desserts manufacturing, farm based business"
Rows("899:904").Hidden = False
Case "Frozen yogurt manufacturing, farm based business"
Rows("905:910").Hidden = False
Case "Custom slaughtering, farm based business"
Rows("911:911").Hidden = False
Case "Custom cut & wrap, farm based business"
Rows("912:918").Hidden = False
Case "Custom slaughtering and cut & wrap, farm based business"
Rows("919:925").Hidden = False
Case "Frozen meat pies (i.e., tourtières), made from purchased meat, farm based business"
Rows("926:931").Hidden = False
Case "Processed meat (except poultry) made from purchased meat (i.e., pastrami, salami, smoked meat, bologna, weiners, sausage), farm based business"
Rows("932:936").Hidden = False
Case "Meat curing, drying, salting, smoking or pickling, made from purchased meat, farm based business"
Rows("937:941").Hidden = False
Case "Pigs' feet, cooked and pickled, made from purchased meat, farm based business"
Rows("942:9446").Hidden = False
Case "Poultry processing (except baby or pet food), farm based business"
Rows("947:949").Hidden = False
Case "Poultry processed meat manufacturing (e.g., hot dogs, luncheon meats, sausages), farm based business"
Rows("950:954").Hidden = False
Case "Rabbits slaughtering, processing & dressing (i.e., fresh, frozen, canned or cooked), farm based business"
Rows("955:958").Hidden = False
Case "Slaughtering, dressing & packing small game, farm based business"
Rows("959:960").Hidden = False
Case "Fish & seafood, curing, drying, pickling, salting, smoking, canning, chowders and soups fresh or frozen, farm based business"
Rows("961:965").Hidden = False
Case "Seafood & seafood products fresh prepared or frozen manufacturing, farm based business"
Rows("966:969").Hidden = False
Case "Seaweed processing (e.g., dulse), farm based business"
Rows("970:973").Hidden = False
Case "Shucking & packing fresh shellfish, farm based business"
Rows("974:975").Hidden = False
Case "Retail bakeries stands or markets, farm based business"
Rows("976:979").Hidden = False
Case "Commercial bakery products fresh or frozen, farm based business"
Rows("980:984").Hidden = False
Case "Communion wafers manufacturing, farm based business"
Rows("985:989").Hidden = False
Case "Cracker meal and crumbs manufacturing, farm based business"
Rows("990:994").Hidden = False
Case "Crackers, cookies & biscuits manufacturing (e.g., graham, saltine, soda), farm based business"
Rows("995:999").Hidden = False
Case "Ice cream cones & wafers manufacturing, farm based business"
Rows("1000:1004").Hidden = False
Case "Zwieback & rusk manufacturing, farm based business"
Rows("1005:1009").Hidden = False
Case "Flour mixes, dough, pie crust shells, pasteries, prepared batters & pasta manufacturing, farm based business"
Rows("1010:1014").Hidden = False
Case "Packaging dry pasta that are manufactured with other ingredients, farm based business"
Rows("1015:1019").Hidden = False
End Select
Next Cel
If Not Application.Intersect(u, Target) Is Nothing Then
If Application.Intersect(u, Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
Rows("24:56").Hidden = True
Rows("63:1824").Hidden = True
End If
Application.EnableEvents = True
End Sub

Related

Algorithm used to prevent a player from getting their same card

I have a game I am coding in Tabletop Simulator where all players (P) is given a card (C). Once memorized all players put the card back into the deck (D), shuffled, and then all players are dealt one of the cards from the same deck (D). I am trying to code the simplest algorithm that prevents a player from getting their own card. Now when it comes to coding this should be simple I assume instead of creating simulations to run until it is successful.
Say you have the following:
deck, a randomized deck containing all the cards (including those the players have seen).
seen_card_id_by_player, a lookup table that give you the guid of the card a player has seen.
Then the solution is simply
local card_ids = {}
for i, card_data in ipairs(deck.getObjects()) do
table.insert(card_ids, card_data.guid)
end
for player, seen_card_id in pairs(seen_card_id_by_player) do
local card_id = table.remove(card_ids)
if card_id == seen_card_id then
local i = math.random(1, #card_ids)
card_ids[i], card_id = card_id, card_ids[i]
end
-- Deal the specific card.
deck.takeObject({
guid = card_ids[i],
position = player.getHandTransform().position,
flip = true,
})
end
When we pick the card the player has already seen, it is placed back at a random location among the remaining cards. This ensures that every card has an equal chance of being drawn by the next player. This is the underlying principle of the Fisher-Yates shuffle.
Full demonstration
function broadcast_error(msg)
broadcastToAll(msg, { r=1, g=0, b=0 })
end
function get_cards_seen_by_players()
local player_ids = Player.getAvailableColors()
local error = false
local seen_card_by_player = {}
for i, player_id in ipairs(player_ids) do
local player = Player[player_id]
local hand_objs = player.getHandObjects()
local player_error = false
if #hand_objs > 1 then
player_error = true
elseif #hand_objs == 1 then
local card = hand_objs[1]
if card.tag ~= "Card" then
player_error = true
else
seen_card_by_player[player] = card
end
end
if player_error then
broadcast_error(player_id .. " doesn't have a valid hand.")
error = true
end
end
if error then
return nil
end
return seen_card_by_player
end
function run()
local deck = getObjectFromGUID("...")
local seen_card_by_player = get_cards_seen_by_players()
if seen_card_by_player == nil or next(seen_card_by_player) == nil then
return
end
local seen_card_id_by_player = {}
for player, card in pairs(seen_card_by_player) do
local card_id = card.guid
seen_card_id_by_player[player] = card_id
card.putObject(deck)
end
deck.randomize()
local card_ids = {}
for i, card_data in ipairs(deck.getObjects()) do
table.insert(card_ids, card_data.guid)
end
for player, seen_card_id in pairs(seen_card_id_by_player) do
local card_id = table.remove(card_ids)
if card_id == seen_card_id then
local i = math.random(1, #card_ids)
card_ids[i], card_id = card_id, card_ids[i]
end
deck.takeObject({
guid = card_ids[i],
position = player.getHandTransform().position,
flip = true,
})
end
end
Create a game with a deck of cards. Place the above code in Global, replacing ... with the deck's GUID. To run the demonstration, deal one card to any number of players, then use /execute Global.call("run") in the chat window.

Unable to fetch the next_maintext of 2nd page

page1 and page2 URL. I want to fetch all the content from the 1st URL and only the main text from the 2nd URL and append it to the main text of 1st URL. This is only one article. function parse_indianexpress_archive_links() contains a list of news articles URLs. I m getting all the results from page1 but the next_maintext column from page2 results output <GET http://archive.indianexpress.com/news/congress-approves-2010-budget-plan/442712/2>
class spider_indianexpress(scrapy.Spider):
name = 'indianexpress'
start_urls = parse_indianexpress_archive_links()
def parse(self,response):
items = ScrapycrawlerItem()
separator = ''
#article_url = response.xpath("//link[#rel = 'canonical']/#href").extract_first()
article_url = response.request.url
date_updated = max(response.xpath("//div[#class = 'story-date']/text()").extract() , key=len)[-27:] #Call max(list, key=len) to return the longest string in list by comparing the lengths of all strings in a list
if len(date_updated) <=10:
date_updated = max(response.xpath("//div[#class = 'story-date']/p/text()").extract() , key=len)[-27:]
headline = response.xpath("(//div[#id = 'ie2013-content']/h1//text())").extract()
headline=separator.join(headline)
image_url = response.css("div.storybigpic.ssss img").xpath("#src").extract_first()
maintext = response.xpath("//div[#class = 'ie2013-contentstory']//p//text()").extract()
maintext = ' '.join(map(str, maintext))
maintext = maintext.replace('\r','')
contd = response.xpath("//div[#class = 'ie2013-contentstory']/p[#align = 'right']/text()").extract_first()
items['date_updated'] = date_updated
items['headline'] = headline
items['maintext'] = maintext
items['image_url'] = image_url
items['article_url'] = article_url
next_page_url = response.xpath("//a[#rel='canonical']/#href").extract_first()
if next_page_url :
items['next_maintext'] = scrapy.Request(next_page_url , callback = self.parse_page2)
yield items
def parse_page2(self, response):
next_maintext = response.xpath("//div[#class = 'ie2013-contentstory']//p//text()").extract()
next_maintext = ' '.join(map(str, next_maintext))
next_maintext = next_maintext.replace('\r','')
yield {next_maintext}
Output:
article_url,date_publish,date_updated,description,headline,image_url,maintext,next_maintext
http://archive.indianexpress.com/news/congress-approves-2010-budget-plan/442712/,,"Fri Apr 03 2009, 14:49 hrs ",,Congress approves 2010 budget plan,http://static.indianexpress.com/m-images/M_Id_69893_Obama.jpg,"The Democratic-controlled US Congress on Thursday approved budget blueprints embracing President Barack Obama's agenda but leaving many hard choices until later and a government deeply in the red. With no Republican support, the House of Representatives and Senate approved slightly different, less expensive versions of Obama's $3.55 trillion budget plan for fiscal 2010, which begins on October 1. The differences will be worked out over the next few weeks. Obama, who took office in January after eight years of the Republican Bush presidency, has said the Democrats' budget is critical to turning around the recession-hit US economy and paving the way for sweeping healthcare, climate change and education reforms he hopes to push through Congress this year. Obama, traveling in Europe, issued a statement praising the votes as ""an important step toward rebuilding our struggling economy."" Vice President Joe Biden, who serves as president of the Senate, presided over that chamber's vote. Democrats in both chambers voted down Republican alternatives that focused on slashing massive deficits with large cuts to domestic social spending but also offered hefty tax breaks for corporations and individuals. ""Democrats know that those policies are the wrong way to go,"" House Majority Leader Steny Hoyer told reporters. ""Our budget lays the groundwork for a sustained, shared and job-creating recovery."" But Republicans have argued the Democrats' budget would be a dangerous expansion of the federal government and could lead to unnecessary taxes that would only worsen the country's long-term fiscal situation. ""The Democrat plan to increase spending, to increase taxes, and increase the debt makes no difficult choices,"" said House Minority Leader John Boehner. ""It's a roadmap to disaster."" The budget measure is nonbinding but it sets guidelines for spending and tax bills Congress will consider later this year. BIPARTISANSHIP ABSENT AGAIN Obama has said he hoped to restore bipartisanship when he arrived in Washington but it was visibly absent on Thursday. ... contd.",<GET http://archive.indianexpress.com/news/congress-approves-2010-budget-plan/442712/2>
This is not how Scrapy works (I mean next_page request) How to fetch the Response object of a Request synchronously on Scrapy?.
But in fact you don't need synchronous requests. All you need is to check for a next page and pass current state (item) to the callback that will process your next page. I'm using cb_kwargs (it's a recommended way now). You may need to use request.meta if you have an old version.
import scrapy
class spider_indianexpress(scrapy.Spider):
name = 'indianexpress'
start_urls = ['http://archive.indianexpress.com/news/congress-approves-2010-budget-plan/442712/']
def parse(self,response):
item = {}
separator = ''
#article_url = response.xpath("//link[#rel = 'canonical']/#href").extract_first()
article_url = response.request.url
date_updated = max(response.xpath("//div[#class = 'story-date']/text()").extract() , key=len)[-27:] #Call max(list, key=len) to return the longest string in list by comparing the lengths of all strings in a list
if len(date_updated) <=10:
date_updated = max(response.xpath("//div[#class = 'story-date']/p/text()").extract() , key=len)[-27:]
headline = response.xpath("(//div[#id = 'ie2013-content']/h1//text())").extract()
headline=separator.join(headline)
image_url = response.css("div.storybigpic.ssss img").xpath("#src").extract_first()
maintext = response.xpath("//div[#class = 'ie2013-contentstory']//p//text()").extract()
maintext = ' '.join(map(str, maintext))
maintext = maintext.replace('\r','')
contd = response.xpath("//div[#class = 'ie2013-contentstory']/p[#align = 'right']/text()").extract_first()
item['date_updated'] = date_updated
item['headline'] = headline
item['maintext'] = maintext
item['image_url'] = image_url
item['article_url'] = article_url
next_page_url = response.xpath('//a[#rel="canonical"][#id="active"]/following-sibling::a[1]/#href').extract_first()
if next_page_url :
yield scrapy.Request(
url=next_page_url,
callback = self.parse_next_page,
cb_kwargs={
'item': item,
}
)
else:
yield item
def parse_next_page(self, response, item):
next_maintext = response.xpath("//div[#class = 'ie2013-contentstory']//p//text()").extract()
next_maintext = ' '.join(map(str, next_maintext))
next_maintext = next_maintext.replace('\r','')
item["maintext"] += next_maintext
next_page_url = response.xpath('//a[#rel="canonical"][#id="active"]/following-sibling::a[1]/#href').extract_first()
if next_page_url :
yield scrapy.Request(
url=next_page_url,
callback = self.parse_next_page,
cb_kwargs={
'item': item,
}
)
else:
yield item

Using MS Access 2013: If Then Statement for continuous Form Issue

I need this to effect only the current record within the continuous form.
On the Offender Type I select "offender 1" and the code correctly sets all four fields not enabled.
However when I go record 2, in the Offender Type, I select "Offender 2" the code incorrectly sets all four fields to enabled of every record of the continuous form not just the fields for record 2.
Combo box Name: Offender_Type
Selections for Offender_Type: Offender 1; Offender 2; Offender 3
Private Sub Offender_Type_AfterUpdate()
If Me.Offender_Type.Value = "offender 1 " Then
Me.Field1.Enabled = False
Me.Field2.Enabled = False
Me.Field3.Enabled = False
Me.field4.Enabled = False
ElseIf Me.Offender_Type.Value <> "offender 1" Then
Me.Field1.Enabled = True
Me.Field2.Enabled = True
Me.Field3.Enabled = True
Me.field4.Enabled = True
Else
End If
End Sub

GTK how to create 3 different filter for 1 Liststore

In GTK/Python, I'm trying to build an interface with nodes.
This is photo of my interface
I create one liststore and I want to filter different things. The user has to do two actions, first, he has to choose in the combobox the type of filter that he wants to use, if he wants to filter by node's type, node's beginning name or others.
Then in the text entry, he decides what information that he wants to see. Take the exemple of nodes type. There are like 3 different types of nodes, node type 1, node type 2 and node type 3. As an user I want to see only node type 1, so I write 1 in the node entry. Actually I have a problem, it is my filter does not work.
I first create 2 liststores:
def create_liststore(self):
if len(self.FdessinCarto.pos) != 0:
for i,node in enumerate(self.FdessinCarto.pos):
self.node_liststore.append([str(node.title),self.controller.model.string_from_numdate(int(node.start_time)),self.controller.model.string_from_numdate(int(node.end_time)),str(node.node_group),str(node.description),str(node.attachment_list)])
self.edgelist = self.controller.get_edge_list()
if len(self.edgelist) !=0:
for i in self.edgelist:
edge_prop=self.controller.edge_data(i[0],i[1])
self.edge_liststore.append([edge_prop['label'],str(i[0].title),str(i[1].title),edge_prop['description'],edge_prop['attachment_list']])
#creating the treeview for Node, making it use the filter as a model, and adding the columns
self.treeviewNode = Gtk.TreeView.new_with_model(self.node_liststore)
for i, column_title in enumerate(["Name", "Beginning date", "End date", "Type of node", "Description of node","files"]):
self.Noderenderer = Gtk.CellRendererText()
self.Noderenderer.set_property("editable", True)
column = Gtk.TreeViewColumn(column_title, self.Noderenderer, text=i)
column.set_sort_column_id(0)
self.treeviewNode.append_column(column)
#creating the treeview for edge
self.treeviewEdge = Gtk.TreeView.new_with_model(self.edge_liststore)
for i, column_title in enumerate(["Name", "Node 1", "Node 2", "Description of edge","file"]):
self.Edgerenderer = Gtk.CellRendererText()
self.Edgerenderer.set_property("editable", True)
column = Gtk.TreeViewColumn(column_title, self.Edgerenderer, text=i)
column.set_sort_column_id(0)
self.treeviewEdge.append_column(column)
self.SWViewListStore.add(self.treeviewNode)
self.SWEdgeStore.add(self.treeviewEdge)
self.SWViewListStore.show_all()
self.SWEdgeStore.show_all()
There are my 3 different filters:
#creating the filtre
self.node_beginning_date_filter = self.node_liststore.filter_new()
self.node_end_date_filter = self.node_liststore.filter_new()
self.node_type_filter = self.node_liststore.filter_new()
#setting the filter function, note that we're not using the
self.node_end_date_filter.set_visible_func(self.node_end_date_filter_func)
self.node_beginning_date_filter.set_visible_func(self.node_beginning_date_filter_func)
self.node_type_filter.set_visible_func(self.node_type_filter_func)
Once I change my combo-box, it would activate my function, it took the type of combofilter then also the text of combobox :
def on_entryComboBox_changed(self,widget):
textComboFilter = self.View.combo_filter.get_active_text()
print("textComboFilter %s" %textComboFilter)
if textComboFilter == "Filter by node's beginning date":
#print("%s language selected!" % textComboFilter)
self.View.current_filter = textComboFilter
self.View.node_beginning_date_filter.refilter()
if textComboFilter == "Filter by node's end date":
#print("%s language selected!" % textComboFilter)
self.View.current_filter = textComboFilter
self.View.node_end_date_filter.refilter()
if textComboFilter == "Filter by type of node":
#print("%s language selected!" % textComboFilter)
self.View.current_filter = textComboFilter
self.View.node_type_filter.refilter()
And it does not work.
Finally,
I manage to answer it on my own.
You should build one filter rather than three. For people who have the same problem, this is a very good example which helps me to solve my problem.
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
#list of tuples for each software, containing the software name, initial release, and main programming languages used
software_list = [("Firefox", 2002, "C++"),
("Eclipse", 2004, "Java" ),
("Pitivi", 2004, "Python"),
("Netbeans", 1996, "Java"),
("Chrome", 2008, "C++"),
("Filezilla", 2001, "C++"),
("Bazaar", 2005, "Python"),
("Git", 2005, "C"),
("Linux Kernel", 1991, "C"),
("GCC", 1987, "C"),
("Frostwire", 2004, "Java")]
class TreeViewFilterWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Treeview Filter Demo")
self.set_border_width(10)
#Setting up the self.grid in which the elements are to be positionned
self.grid = Gtk.Grid()
self.grid.set_column_homogeneous(True)
self.grid.set_row_homogeneous(True)
self.add(self.grid)
#Creating the ListStore model
self.software_liststore = Gtk.ListStore(str, int, str)
for software_ref in software_list:
self.software_liststore.append(list(software_ref))
self.current_filter_language = None
#Creating the filter, feeding it with the liststore model
self.language_filter = self.software_liststore.filter_new()
#setting the filter function, note that we're not using the
self.language_filter.set_visible_func(self.language_filter_func)
#creating the treeview, making it use the filter as a model, and adding the columns
self.treeview = Gtk.TreeView.new_with_model(self.language_filter)
for i, column_title in enumerate(["Software", "Release Year", "Programming Language"]):
renderer = Gtk.CellRendererText()
column = Gtk.TreeViewColumn(column_title, renderer, text=i)
self.treeview.append_column(column)
#creating buttons to filter by programming language, and setting up their events
self.buttons = list()
for prog_language in ["Java", "C", "C++", "Python", "None"]:
button = Gtk.Button(prog_language)
self.buttons.append(button)
button.connect("clicked", self.on_selection_button_clicked)
#setting up the layout, putting the treeview in a scrollwindow, and the buttons in a row
self.scrollable_treelist = Gtk.ScrolledWindow()
self.scrollable_treelist.set_vexpand(True)
self.grid.attach(self.scrollable_treelist, 0, 0, 8, 10)
self.grid.attach_next_to(self.buttons[0], self.scrollable_treelist, Gtk.PositionType.BOTTOM, 1, 1)
for i, button in enumerate(self.buttons[1:]):
self.grid.attach_next_to(button, self.buttons[i], Gtk.PositionType.RIGHT, 1, 1)
self.scrollable_treelist.add(self.treeview)
self.show_all()
def language_filter_func(self, model, iter, data):
"""Tests if the language in the row is the one in the filter"""
if self.current_filter_language is None or self.current_filter_language == "None":
return True
else:
return model[iter][2] == self.current_filter_language
def on_selection_button_clicked(self, widget):
"""Called on any of the button clicks"""
#we set the current language filter to the button's label
self.current_filter_language = widget.get_label()
print("%s language selected!" % self.current_filter_language)
#we update the filter, which updates in turn the view
self.language_filter.refilter()
win = TreeViewFilterWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()

Switch-Hide pictures based on cell values

I am not an expert on VBA, all I know is based on browsing internet, but some simple codes work for me well.
I am switching pictures based on P52 value, that works perfectly, but then I want to swich different pictures based on cell value P117 and that part of the code does not really work for me. What am I missing in the code?
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If Target.Address <> "$P$52" Then Exit Sub
With ActiveSheet
Select Case Target.Value
Case "Horizontal - feet"
.Pictures("B3A").Visible = True
.Pictures("V1A").Visible = False
.Pictures("V1AF").Visible = False
Case "Vertical - simple"
.Pictures("B3A").Visible = False
.Pictures("V1A").Visible = True
.Pictures("V1AF").Visible = False
Case "Vertical - lantern"
.Pictures("B3A").Visible = False
.Pictures("V1A").Visible = False
.Pictures("V1AF").Visible = True
End Select
End With
If Target.Address <> "$P$117" Then Exit Sub
With ActiveSheet
Select Case Target.Value
Case "Right"
.Pictures("3P1").Visible = True
.Pictures("3P1M").Visible = False
Case "Left"
.Pictures("3P1").Visible = False
.Pictures("3P1M").Visible = True
End Select
End With
End Sub
Thanks for your help.
Think through the logic of your if statements causing you to exit the sub.
If the cell is P117, you will hit the first if statement which causes you to exit the sub immediately. So you will never get to your second check.
Embed the logic for each of your operations in if statements like I show here and you will be able to "do something if the cell range is P52 or P117" a bit more appropriately.
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
'only do the following operation if your cell address is P52 - don't exit out
'of your entire code if it's not
If Target.Address = "$P$52" Then
With ActiveSheet
Select Case Target.Value
Case "Horizontal - feet"
.Pictures("B3A").Visible = True
.Pictures("V1A").Visible = False
.Pictures("V1AF").Visible = False
Case "Vertical - simple"
.Pictures("B3A").Visible = False
.Pictures("V1A").Visible = True
.Pictures("V1AF").Visible = False
Case "Vertical - lantern"
.Pictures("B3A").Visible = False
.Pictures("V1A").Visible = False
.Pictures("V1AF").Visible = True
End Select
End With
End If
'you skip to down here if it is NOT P52, which then lets you check again to
'see if it's P117
If Target.Address = "$P$117" Then
With ActiveSheet
Select Case Target.Value
Case "Right"
.Pictures("3P1").Visible = True
.Pictures("3P1M").Visible = False
Case "Left"
.Pictures("3P1").Visible = False
.Pictures("3P1M").Visible = True
End Select
End With
End If
End Sub
If you are going to have a lot of checks like this, you may want to create a Select case statement for Target.Address too. It's hard to say which is better for you given what you've asked here.

Resources