Excel bracket using VBA not working? - arrays

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!

Related

AttributeError: module 'interactions' has no attribute 'Client'

Full disclosure I haven't written this code myself and I'm still a little new to discord intents. I'm worried that some older discord libraries on my computer may be causing this but i'm not sure why I'm getting this error. Every time I run my program "AttributeError: module 'interactions' has no attribute 'Client' ".
Here is the code I was using
#imports
import interactions
import random
import cloudscraper
#settings
SafeMines = ':white_check_mark:'
TileMines = ':x:'
SafeTowers = ':white_check_mark:'
TileTowers = ':x:'
BotToken = ''
ServerId = 0
BuyerRoleId = 0
#StartUp
bot = interactions.Client(
token=BotToken
)
#defines
def GenGrid(SafeTiles:int):
Generating = True
BoardNums = []
Board = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
Grid = f''
line = 0
endrownums = [6,11,16,21]
while Generating:
if len(BoardNums) < SafeTiles:
Selection = random.randint(1, 25)
if Selection in BoardNums:
pass
else:
BoardNums.append(Selection)
else:
Generating = False
for Number in BoardNums:
Board[Number-1] = 1
for Position in Board:
line += 1
if line in endrownums:
Grid += f'\n'
if Position == 1:
Grid += f'{SafeMines}'
else:
Grid += f'{TileMines}'
else:
if Position == 1:
Grid += f'{SafeMines}'
else:
Grid += f'{TileMines}'
return Grid
def gentower(rows:int):
if rows >= 9:
return "Max Rows 8!"
else:
def pr():
rowtp1 = f"{SafeTowers}{TileTowers}{TileTowers}"
rowtp2 = f"{TileTowers}{SafeTowers}{TileTowers}"
rowtp3 = f"{TileTowers}{TileTowers}{SafeTowers}"
joe = random.randint(1,3)
if joe == 1:
return rowtp1
elif joe == 2:
return rowtp2
else:
return rowtp3
leg = True
counter = 0
finaltower = f""
while leg:
if counter == rows:
leg = False
else:
counter +=1
finaltower += f"{pr()}\n"
return finaltower
#Commands
#bot.command(
name='mines',
description="Generates A Mine Grid",
scope=ServerId,
options= [
interactions.Option(
name="game_id",
description="Put your game id here",
type=interactions.OptionType.STRING,
required=True,
),
interactions.Option(
name="clicks",
description="How many safe spots to generate",
type=interactions.OptionType.INTEGER,
required=True,
)
]
)
async def Mines(ctx, game_id: str, clicks:int):
if BuyerRoleId in ctx.author.roles or ctx.author.id == 756534114143961088:
if int(clicks) > 23:
mines = interactions.Embed(title=f"Mines", description=f"Too Many SafeClicks! Max is 23\nYou Chose {clicks}/23", color=0xFC4431)
await ctx.send(embeds=mines, ephemeral=True)
else:
count = 0
includes_dash = False
includes_number1 = ""
includes_number2 = ""
l = [14,15,16]
l2 = [18,19,20,21,22]
lsu = False
for v in game_id:
count += 1
if count == 9:
if v == "-":
includes_dash = True
if count in l:
if v == "4":
includes_number1 += v
if count in l:
try:
int(v)
if lsu == True:
continue
else:
includes_number2 +=v
lsu = True
except ValueError:
continue
if includes_dash == True:
if includes_number1 == "4":
try:
int(includes_number2)
mines = interactions.Embed(title=f"Mines", description=f"Generated Tiles!", color=0xFC4431)
mines.add_field(name=f"Field {clicks} Clicks", value=GenGrid(clicks),inline=True)
await ctx.send(embeds=mines, ephemeral=True)
print(f"\n\n{ctx.author} Used Towers command\nID = {ctx.author.id}\n")
except ValueError:
mines = interactions.Embed(title=f"Mines", description=f"Invalid ID!", color=0xFC4431)
await ctx.send(embeds=mines, ephemeral=True)
else:
mines = interactions.Embed(title=f"Mines", description=f"Invalid ID!", color=0xFC4431)
await ctx.send(embeds=mines, ephemeral=True)
else:
mines = interactions.Embed(title=f"Mines", description=f"Invalid ID!", color=0xFC4431)
await ctx.send(embeds=mines, ephemeral=True)
else:
await ctx.send(f"Not Eligable! {ctx.author.mention}")
#Bot
bot.start()
Im not sure why its giving me any error, any suggestions on this?

How to create multi infinity loops with coroutine in Kotlin

I have a method in viewmodel that I want to execute infinity till client stop that.
This loop should work for each button separately and stop that too.
But when I execute the loop for fourth time, application hangs.
How can I manage the loop and run it for four separate objects
This is my method in viewmodel:
fun getLocationInfinity(context: Context, tripId: Long, passengerId: Int) =
viewModelScope.launch {
val gpsTracker = LocationGpsTracker(context, 0, 0)
val netGpsTracker = LocationGpsTrackerNetwork(context)
var way = Way()
way.latitude1 = gpsTracker.getLatitude()
way.longitude1 = gpsTracker.getLongitude()
way.accuracy1 = gpsTracker.getAccuracy()
way.latitudeNet1 = netGpsTracker.getLatitude()
way.longitudeNet1 = netGpsTracker.getLongitude()
way.accuracyNet1 = netGpsTracker.getAccuracy()
while (isActive) {
if (_passengerSwitch.value?.get(passengerId - 1) == true) {
way.latitude2 = way.latitude1
way.longitude2 = way.longitude1
way.accuracy2 = way.accuracy1
way.latitudeNet2 = way.latitudeNet1
way.longitudeNet2 = way.longitudeNet1
way.accuracyNet2 = way.accuracyNet1
way.latitude1 = gpsTracker.getLatitude()
way.longitude1 = gpsTracker.getLongitude()
way.accuracy1 = gpsTracker.getAccuracy()
way.latitudeNet1 = netGpsTracker.getLatitude()
way.longitudeNet1 = netGpsTracker.getLongitude()
way.accuracyNet1 = netGpsTracker.getAccuracy()
_way.postValue(way)
val tripDetails = TripDetails(
latitude1 = way.latitude1,
latitude2 = way.latitude2,
longitude1 = way.longitude1,
longitude2 = way.longitude2,
accuracy1 = way.accuracy1,
accuracy2 = way.accuracy2,
latitudeNet1 = way.latitudeNet1,
latitudeNet2 = way.latitudeNet2,
longitudeNet1 = way.longitudeNet1,
longitudeNet2 = way.longitudeNet2,
accuracy1Net = way.accuracyNet1,
accuracy2Net = way.accuracyNet2,
distance = null,
isCalculated = false,
tripId = tripId.toInt(),
isEnded = false
)
localRepository.insertLocation(tripDetails)
delay(2000)
}
}
}
The delay() call needs to be outside your if-block. Otherwise, if the condition is false, this loop will never suspend so it never relinquishes the thread.

Cycle Through Array to Change Players PowerPoint VBA

I'm trying to create a macro to cycle between three players on a game that I am making on PowerPoint. However, when I run the code, it changes once and and gets stuck. It won't cycle through the array. In the code I plan to change the color of the shape containing the player's name as well as show transparent gray buttons over the other players' boxes so that they can't adjust their scores. Here is my code. Thanks in advance.
Sub SwitchPlayers()
Dim oSl As Slide
Dim RGB As String
Dim i As Long
Dim myTurn() As Integer
ReDim myTurn(2) '0, 1, 2... 3 compartments
Set oSl = ActivePresentation.Slides(5)
For i = 0 To 2
myTurn(i) = i + 1
If myTurn(i) = 0 Then
oSl.Shapes("T1NB").Fill.ForeColor.RGB = vbYellow
oSl.Shapes.Range(Array("T2NB", "T3NB")).Fill.ForeColor.RGB = vbWhite
oSl.Shapes.Range(Array("T2+1G", "T2-1G", "T3+1G", "T3-1G")).Visible = True
oSl.Shapes.Range(Array("T1+1G", "T1-1G")).Visible = False
ElseIf myTurn(i) = 1 Then
oSl.Shapes("T2NB").Fill.ForeColor.RGB = vbYellow
oSl.Shapes.Range(Array("T1NB", "T3NB")).Fill.ForeColor.RGB = vbWhite
oSl.Shapes.Range(Array("T1+1G", "T1-1G", "T3+1G", "T3-1G")).Visible = True
oSl.Shapes.Range(Array("T2+1G", "T2-1G")).Visible = False
ElseIf myTurn(i) = 2 Then
oSl.Shapes("T3NB").Fill.ForeColor.RGB = vbYellow
oSl.Shapes.Range(Array("T1NB", "T2NB")).Fill.ForeColor.RGB = vbWhite
oSl.Shapes.Range(Array("T1+1G", "T1-1G", "T2+1G", "T2-1G")).Visible = True
oSl.Shapes.Range(Array("T3+1G", "T3-1G")).Visible = False
End If
Next i
End Sub
Thanks again to #SteveRindsberg. I figured it out and added Select Case to my toolbox. This is the code that I came up with. Works great.
Sub SwitchPlayers2()
Dim oSl As Slide
Dim RGB As String
Set oSl = ActivePresentation.Slides(5)
Select Case iLastRan
Case Is = 0
oSl.Shapes("T1NB").Fill.ForeColor.RGB = vbYellow
oSl.Shapes.Range(Array("T2NB", "T3NB")).Fill.ForeColor.RGB = vbWhite
oSl.Shapes.Range(Array("T2+1G", "T2-1G", "T3+1G", "T3-1G")).Visible = True
oSl.Shapes.Range(Array("T1+1G", "T1-1G")).Visible = False
iLastRan = iLastRan + 1
Case Is = 1
oSl.Shapes("T2NB").Fill.ForeColor.RGB = vbYellow
oSl.Shapes.Range(Array("T1NB", "T3NB")).Fill.ForeColor.RGB = vbWhite
oSl.Shapes.Range(Array("T1+1G", "T1-1G", "T3+1G", "T3-1G")).Visible = True
oSl.Shapes.Range(Array("T2+1G", "T2-1G")).Visible = False
iLastRan = iLastRan + 1
Case Is = 2
oSl.Shapes("T3NB").Fill.ForeColor.RGB = vbYellow
oSl.Shapes.Range(Array("T1NB", "T2NB")).Fill.ForeColor.RGB = vbWhite
oSl.Shapes.Range(Array("T1+1G", "T1-1G", "T2+1G", "T2-1G")).Visible = True
oSl.Shapes.Range(Array("T3+1G", "T3-1G")).Visible = False
iLastRan = iLastRan + 1
If iLastRan > 2 Then
iLastRan = 0
End If
End Select
End Sub

2 object of same type returns true when != checked

I am using model.GetType().GetProperties() with foreach to compare properties of 2 object of same class.
like this
foreach (var item in kayit.GetType().GetProperties())
{
var g = item.GetValue(plu);
var b = item.GetValue(kayit);
if (g is string && b is string&& g!=b)
{
a += item.Name + "*";
}
else if (g is DateTime&& b is DateTime&& g!=b)
{
a += item.Name + "*";
}
}
But the problem is even if they have the same value g!=b returns a true all the time. I have used a break point to prove this and they are literally same thing. Actually I am taking the value putting it in textbox then creating another class after button click and comaring to see the changed properties. So even if I don't change anything it doesn't read the mas equals. Can someone help me about this please?
more info:
I get the plu from database and populate my control with it:
txtorder.Text = plu.OrderNo;
dtporder.Value = nulldate(plu.OrderDate);
dtp1fit.Value = nulldate(plu.FirstFitDate);
dtp1yorum.Value = nulldate(plu.FirstCritDate);
dtp2fit.Value = nulldate(plu.SecondFitDate);
dtp2yorum.Value = nulldate(plu.SecondCritDate);
dtpsizeset.Value = nulldate(plu.SizeSetDate);
dtpsizesetok.Value = nulldate(plu.SizeSetOkDate);
dtpkumasplan.Value = nulldate(plu.FabricOrderByPlan);
txtTedarikci.Text = plu.Fabric_Supplier;
dtpkumasFP.Value = nulldate(plu.FabricOrderByFD);
dtpfabarrive.Value = nulldate(plu.FabricArrive);
dtpbulk.Value = nulldate(plu.BulkFabricDate);
dtpbulkok.Value = nulldate(plu.BulkConfirmDate);
dtpaccessory.Value = nulldate(plu.AccessoriesDate);
dtpaccessoryarrive.Value = nulldate(plu.AccessoriesArriveDate);
dtpcutok.Value = nulldate(plu.ProductionStartConfirmation);
dtpcutstart.Value = nulldate(plu.ProductionStart);
dtpshipmentdate.Value = nulldate(plu.ShipmentDate);
dtpshipmentsample.Value = nulldate(plu.ShipmentSampleDate);
dtpshippedon.Value = nulldate(plu.Shippedon);
nulldate is just a method where I change null values to my default value.
And this is what I do after button click:
var kayit = new uretim();
kayit.OrderNo = txtorder.Text.ToUpper();
kayit.OrderDate = vdat(dtporder.Value);
kayit.FirstFitDate = vdat(dtp1fit.Value);
kayit.FirstCritDate = vdat(dtp1yorum.Value);
kayit.SecondFitDate = vdat(dtp2fit.Value);
kayit.SecondCritDate = vdat(dtp2yorum.Value);
kayit.SizeSetDate = vdat(dtpsizeset.Value);
kayit.SizeSetOkDate = vdat(dtpsizesetok.Value);
kayit.FabricOrderByPlan = vdat(dtpkumasplan.Value);
kayit.Fabric_Supplier = txtTedarikci.Text;
kayit.FabricOrderByFD = vdat(dtpkumasFP.Value);
kayit.FabricArrive = vdat(dtpfabarrive.Value);
kayit.BulkFabricDate = vdat(dtpbulk.Value);
kayit.BulkConfirmDate = vdat(dtpbulkok.Value);
kayit.AccessoriesDate = vdat(dtpaccessory.Value);
kayit.AccessoriesArriveDate = vdat(dtpaccessoryarrive.Value);
kayit.ProductionStartConfirmation = vdat(dtpcutok.Value);
kayit.ProductionStart = vdat(dtpcutstart.Value);
kayit.ShipmentDate = vdat(dtpshipmentdate.Value);
kayit.ShipmentSampleDate = vdat(dtpshipmentsample.Value);
kayit.Shippedon = vdat(dtpshippedon.Value);
kayit.Status = true;
kayit.WrittenDate = DateTime.Now;
kayit.GuidKey = plu.GuidKey != null ? plu.GuidKey : Guid.NewGuid().ToString("N");
I have proven by breakpoint that values are actually same. But the != check retruns a true.
When you are doing
g != b
compiler doesn't know that these objects are strings to compare so it compares their references. You can do:
g.Equals(b) //be carefull if one of them is null
or
g.ToString() != b.ToString()
EDIT
You can compare them after you check the type:
if (g is string && b is string)
{
if( g.ToString() != b.ToString() ){
}
}

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