Connecting Dropdown to Excel Slicer - excel-2010

Event routine not changing slicer tables
Used some base example code but not working.
Option Explicit
' The Event routine
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(False, False) = "A7" Then
SelectSlicerItem ThisWorkbook.SlicerCaches(1), Target.Value
End If
End Sub
Sub SelectSlicerItem(sc As SlicerCache, itemText As String, Optional defaultItem As String = "")
Dim si As SlicerItem, found As Boolean
found = False
sc.ClearManualFilter
For Each si In sc.SlicerItems
' Debug.Print si.Caption, si.value
If si.Caption <> itemText Then
si.Selected = False
found = True
End If
Next si
If si.Caption <> Jan Then
ActiveSheet.Shapes.Range(Array("Period")).Select
With ActiveWorkbook.SlicerCaches("Slicer_Period")
.SlicerItems("1").Selected = True
.SlicerItems("2").Selected = False
.SlicerItems("3").Selected = False
.SlicerItems("4").Selected = False
.SlicerItems("5").Selected = False
.SlicerItems("6").Selected = False
End With
End If
Next si
If si.Caption = FebYTD Then
ActiveSheet.Shapes.Range(Array("Period")).Select
With ActiveWorkbook.SlicerCaches("Slicer_Period")
.SlicerItems("1").Selected = True
.SlicerItems("2").Selected = True
.SlicerItems("3").Selected = False
.SlicerItems("4").Selected = False
.SlicerItems("5").Selected = False
.SlicerItems("6").Selected = False
Next si
If si.Caption = MarYTD Then
ActiveSheet.Shapes.Range(Array("Period")).Select
With ActiveWorkbook.SlicerCaches("Slicer_Period")
.SlicerItems("1").Selected = True
.SlicerItems("2").Selected = True
.SlicerItems("3").Selected = True
.SlicerItems("4").Selected = False
.SlicerItems("5").Selected = False
.SlicerItems("6").Selected = False
End With
End If
Next si
If si.Caption = AprYTD Then
ActiveSheet.Shapes.Range(Array("Period")).Select
With ActiveWorkbook.SlicerCaches("Slicer_Period")
.SlicerItems("1").Selected = True
.SlicerItems("2").Selected = True
.SlicerItems("3").Selected = True
.SlicerItems("4").Selected = True
.SlicerItems("5").Selected = False
.SlicerItems("6").Selected = False
End With
End If
Next si
If si.Caption = MayYTD Then
ActiveSheet.Shapes.Range(Array("Period")).Select
With ActiveWorkbook.SlicerCaches("Slicer_Period")
.SlicerItems("1").Selected = True
.SlicerItems("2").Selected = True
.SlicerItems("3").Selected = True
.SlicerItems("4").Selected = True
.SlicerItems("5").Selected = False
.SlicerItems("6").Selected = False
End With
End If
Next si
If si.Caption = JunYTD Then
ActiveSheet.Shapes.Range(Array("Period")).Select
With ActiveWorkbook.SlicerCaches("Slicer_Period")
.SlicerItems("1").Selected = True
.SlicerItems("2").Selected = True
.SlicerItems("3").Selected = True
.SlicerItems("4").Selected = True
.SlicerItems("5").Selected = False
.SlicerItems("6").Selected = False
End With
If Not found And defaultItem <> "" Then SelectSlicerItem sc, defaultItem
End Sub
The expected result is once I selected my desired drop down options, my slicers will change to reflect the results that I laid out for each selection.
Could you please advise me?

Related

attempt to perform arithmetic (add) on string and number Error

when I touch the object, I want it to be deleted and come back after 2 seconds and add 1 coin. how can I do this?
local WheatAmount = script.Parent
local oyuncuParasi = "Coins"
duvar = false
function onTouch(vurus)
if duvar == false then
oyuncuParasi = oyuncuParasi +1;
duvar = true
vurus.Parent:Destroy()
WheatAmount.CanCollide = false
wait(2)
WheatAmount.CanCollide = true
duvar = false
end
end
script.Parent.Touched:connect(onTouch)
You are trying to add 1 to local oyuncuParasi = "Coins" which is currently a string...
Try this:
local WheatAmount = script.Parent
local oyuncuParasi = 0
duvar = false
function onTouch(vurus)
if duvar == false then
oyuncuParasi += 1; -- Adds a coin
duvar = true
WheatAmount.Transparent = 1 -- Set the object Transparent
WheatAmount.CanCollide = false
WheatAmount.CanTouch = false
wait(2)
WheatAmount.Transparent = 0 -- Set the object Not Transparent
WheatAmount.CanCollide = true
WheatAmount.CanTouch = true
duvar = false
end
end
script.Parent.Touched:connect(onTouch)
Note: Make sure you put this in a server sided script instead of local script in the Object.
Let me know if it worked and the results!!

Why does my debounce not work, yet produce no errors?

Why does my debounce not work, yet produce no errors?
Here's my script so far, but it isn't working.
local UIS = game:GetService("UserInputService")
local toggle = false
script.Parent.BackpackFrame.Visible = false
script.Parent.BackpackText.Visible = false
UIS.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
if toggle == false then
script.Parent.BackpackFrame.Visible = true
script.Parent.BackpackText.Visible = true
toggle = true
end
if toggle == true then
script.Parent.BackpackFrame.Visible = false
script.Parent.BackpackText.Visible = false
toggle = false
end
end
end)
If toggle is false you set it to true
if toggle == false then
script.Parent.BackpackFrame.Visible = true
script.Parent.BackpackText.Visible = true
toggle = true
end
And then immediately set it to false as you run into your second conditional statement.
if toggle == true then
script.Parent.BackpackFrame.Visible = false
script.Parent.BackpackText.Visible = false
toggle = false
end
So your change is revoked immediately befor anything had a chance to update.
If you have two exclusive states use if / else.
if toggle == false then
script.Parent.BackpackFrame.Visible = true
script.Parent.BackpackText.Visible = true
toggle = true
else
script.Parent.BackpackFrame.Visible = false
script.Parent.BackpackText.Visible = false
toggle = false
end
As all you're doing is to assign boolean values you can simply get rid of your conditions and do this:
toggle = not toggle -- toggle your state
-- assign the state to the visible property
script.Parent.BackpackFrame.Visible = toggle
script.Parent.BackpackText.Visibile = toggle
The code is setting toggle to false immediately after setting it to true.
if toggle == false then
-- false part
toggle = true
end
if toggle == true then
-- true part
toggle = false
end
Just use an else instead of checking toggle twice
if toggle then
-- true part
toggle = false
else
-- false part
toggle = true
end

Access Form Events - What control to use to execute code dynamically

I have created a form to enter training events.
I have an unbound calculated control at the top of my form which reflects the status of the training. Calculated control source:
=IIf(IsNull([Txt_TrainComm]),"NEW",IIf(IsNull([Txt_TrainComp]),"COMMENCED",IIf(IsNull([txtAssNom]),"ASSESSMENT REQUIRED",IIf(IsNull([txtAssComp]),"ASSESSMENT - NOMINATED","ASSESSED"))))
My form has a few key dates (Text Box Names: txt_TrainComm, txt_TrainComp, txtAssNom & txtAssComp) to be entered in that order. What I want to happen is as the dates are entered other form controls are enabled, the footer is made visible etc. I have written a code that when placed in the Form Current Event works fine when switching from one record to the next. Please see my code so far below:
Private Sub Form_Current()
If Me.StatusName = "NEW" Then
Me.StatusName.Width = 1418
Me.Txt_TrainComp.Enabled = False
Me.Txt_TrainComm.Enabled = True
Me.Page_Assessment.Enabled = False
If Me.FormFooter.Visible = True Then
Me.FormFooter.Visible = False
Me.cmdShowdetails__.Caption = "Show Assessment <<"
Dim WindowHeightNEW As Long
WindowHeightNEW = Me.WindowHeight - Me.FormFooter.Height
Me.Move Left:=Me.WindowLeft, Top:=Me.WindowTop, Height:=WindowHeightNEW
End If
End If
If Me.StatusName = "COMMENCED" Then
Me.StatusName.Width = 2552
Me.Txt_TrainComp.Enabled = True
Me.Txt_TrainComm.Enabled = True
Me.Page_Assessment.Enabled = False
If Me.FormFooter.Visible = True Then
Me.FormFooter.Visible = False
Me.cmdShowdetails__.Caption = "Show Assessment <<"
Dim WindowHeightCOMM As Long
WindowHeightCOMM = Me.WindowHeight - Me.FormFooter.Height
Me.Move Left:=Me.WindowLeft, Top:=Me.WindowTop, Height:=WindowHeightCOMM
End If
End If
If Me.StatusName = "ASSESSMENT REQUIRED" Then
Me.StatusName.Width = 4253
Me.Txt_TrainComp.Enabled = True
Me.Txt_TrainComm.Enabled = True
Me.Page_Assessment.Enabled = True
If Me.FormFooter.Visible = False Then
Me.FormFooter.Visible = True
Me.cmdShowdetails__.Caption = "Hide Assessment <<"
Dim WindowHeightASSREQ As Long
WindowHeightASSREQ = Me.WindowHeight + Me.FormFooter.Height
Me.Move Left:=Me.WindowLeft, Top:=Me.WindowTop, Height:=WindowHeightASSREQ
End If
End If'
If Me.StatusName = "ASSESSMENT - NOMINATED" Then
Me.StatusName.Width = 4925
Me.Txt_TrainComp.Enabled = False
Me.Txt_TrainComm.Enabled = False
Me.Page_Assessment.Enabled = True
If Me.FormFooter.Visible = False Then
Me.FormFooter.Visible = True
Me.cmdShowdetails__.Caption = "Hide Assessment <<"
Dim WindowHeightASSNOM As Long
WindowHeightASSNOM = Me.WindowHeight + Me.FormFooter.Height
Me.Move Left:=Me.WindowLeft, Top:=Me.WindowTop, Height:=WindowHeightASSNOM
End If
End If
If Me.StatusName = "ASSESSED" Then
Me.StatusName.Width = 1985
Me.Txt_TrainComp.Enabled = False
Me.Txt_TrainComm.Enabled = False
Me.Page_Assessment.Enabled = True
If Me.FormFooter.Visible = False Then
Me.FormFooter.Visible = True
Me.cmdShowdetails__.Caption = "Hide Assessment <<"
Dim WindowHeightASSD As Long
WindowHeightASSD = Me.WindowHeight + Me.FormFooter.Height
Me.Move Left:=Me.WindowLeft, Top:=Me.WindowTop, Height:=WindowHeightASSD
End If
End If
End Sub
What I cant get to work, is placing the code in the correct control event so that for example, when a date is entered into txt_TrainComp, the code is run dynamically. I have to switch to a different record and then back for the changes to take effect which isn't the desired result. I have tried BeforeUpdate, AfterUpdate, OnDirty, OnChange and they dont seem to work.
Is someone able to please have a look and make a suggestion to what event or code changes I need to make? Hopefully I have provided enough information.
Thank you in advance.
Thanks to RetiredGeek, FormObject_LostFocus() was the correct event to run the code after focus is changed.
Private Sub Txt_TrainComm_LostFocus()
Call FormUpdate
Me.TrainingStatus.Value = Me.StatusName
End Sub
Private Sub Txt_TrainComp_LostFocus()
Call FormUpdate
Me.TrainingStatus.Value = Me.StatusName
End Sub
Private Sub txtAssComp_LostFocus()
Call FormUpdate
Me.TrainingStatus.Value = Me.StatusName
End Sub
Private Sub txtAssNom_LostFocus()
Call FormUpdate
Me.TrainingStatus.Value = Me.StatusName
End Sub

Roblox Studio My script only works one time

I made a gun shop website. When I try to buy a gun the first time it works but, when I delete the gun from my inventory and try again it wont work.
Please Help.
local ServerStorage = game:GetService("ServerStorage")
local Vendedor = script.Parent
local ClickDetector = game.Workspace.Lojadearmas.Vendedor.ClickDetector
local Glock = ServerStorage:WaitForChild("G17"):Clone()
ClickDetector.MouseClick:Connect(function(player)
print(player.name)
local Player = player
local Gui = player.PlayerGui.LojaArmas
Gui.Frame.Visible = true
Gui.Frame2.Visible = true
Gui.Glock.Visible = true
Gui.Fechar.Visible = true
Gui.Loja.Visible = true
Gui.Fechar.MouseButton1Click:Connect(function()
Gui.Frame.Visible = false
Gui.Frame2.Visible = false
Gui.Glock.Visible = false
Gui.Fechar.Visible = false
Gui.Loja.Visible = false
print(Player)
end)
Gui.Glock.MouseButton1Click:Connect(function()
if Player.leaderstats.Reais.Value >= 1000 then
Glock.Parent = Player.Backpack
print(Player.leaderstats.Reais.Value)
Player.leaderstats.Reais.Value = Player.leaderstats.Reais.Value - 1000
end
end)
end)
Its because you are cloning it once when you referenced the variable Glock. Try this:
local ServerStorage = game:GetService("ServerStorage")
local Vendedor = script.Parent
local ClickDetector = game.Workspace.Lojadearmas.Vendedor.ClickDetector
local Glock = ServerStorage:WaitForChild("G17")
ClickDetector.MouseClick:Connect(function(player)
print(player.name)
local Player = player
local Gui = player.PlayerGui.LojaArmas
Gui.Frame.Visible = true
Gui.Frame2.Visible = true
Gui.Glock.Visible = true
Gui.Fechar.Visible = true
Gui.Loja.Visible = true
Gui.Fechar.MouseButton1Click:Connect(function()
Gui.Frame.Visible = false
Gui.Frame2.Visible = false
Gui.Glock.Visible = false
Gui.Fechar.Visible = false
Gui.Loja.Visible = false
print(Player)
end)
Gui.Glock.MouseButton1Click:Connect(function()
if Player.leaderstats.Reais.Value >= 1000 then
Glock:Clone().Parent = Player.Backpack
print(Player.leaderstats.Reais.Value)
Player.leaderstats.Reais.Value = Player.leaderstats.Reais.Value - 1000
end
end)
end)
Let me know if you require any further assistance.

Why is it that when I set a new variable to the player entity FindMetaTable("Player") on the server side, but is 'nil' on the client side?

To clarify, because it was hard to explain in the title.
-- file that contains this code is > "player.lua"
local ply = FindMetaTable("Player")
ply.LastDamageType = "N/A"
this code sets a new variable to all player entities. The variable is just a string of the last entity that did damage to the player. That is made possible by the following code:
-- file that contains this code is > "init.lua"
AddCSLuaFile("shared.lua")
AddCSLuaFile("cl_init.lua")
include("shared.lua")
include("player.lua")
-->
--> OTHER METHODS THAT I DIDN'T INCLUDE
-->
function GM:PlayerShouldTakeDamage(ply, attacker)
ply.LastDamageType=tostring(attacker)
return true
end
My point of doing all this is because I want to have a hud element that will display this string so the client can see what was the last thing that dealt damage to him.
The problem is that, the variable is coming up as nil on the client side file "cl_init", yet if I printed the table that contained all the data that was in the player through the client AND through the server side. both tables were the same excluding the variable I made "LastDamageType"
-- file that contains this code is > "cl_init.lua"
include("shared.lua")
surface.CreateFont("dayz_font",{font="Arial",size=24,weight=400})
function GM:HUDPaint()
local ply = LocalPlayer()
draw.SimpleText("you are "..ply:Nick(),"dayz_font", 150,10,Color(255,120,50),TEXT_ALIGN_CENTER)//TargetID
surface.SetFont("TargetID")
surface.SetTextColor(Color(30,70,130))
surface.SetTextPos(surface.ScreenWidth()-200 ,20)
surface.DrawText("You have ")
surface.SetTextColor(Color(200,90,30))
surface.DrawText(ply:Health())
surface.SetTextColor(Color(30,70,130))
surface.DrawText(" health")
surface.SetTextPos(surface.ScreenWidth()-200 ,35)
surface.DrawText(""..tostring(Entity(1):GetTable().LastDamageType))
-- FOR DEBUGGING PURPOSES, I'M USING "Entity(1)" TO GET MY PLAYER
-- I KNOW THAT "LocalPlayer()" PROBABLY ALSO EQUATES TO THE SAME THING
-- AS WHAT "Entity(1)" IS AT THIS MOMENT BECAUSE I'M TESTING THIS IN SINGLEPLAYER.
end
So it seems that the player data on the client side and the server side are not the SAME thing and that they have to be synchronized or something like that... Or did I miss something important that kept them synchronized?
//////////////////////////////////////////////////
ADDITIONAL INFORMATION
//////////////////////////////////////////////////
These are printed lists of all the variables of my player entity when I did
PrintTable(Entity(1):GetTable())
on both the client side and server side. The first list is on the server and the second is on the client. I will separate them with ==========================
I know you don't probably want to look through the list to just to Ctrl+F and type in "LastDamageType" to highlight it.
/////////////////////////////////////////
SERVER SIDE
CWAttachments:
am_flechetterounds = true
am_magnum = true
am_matchgrade = true
am_slugrounds = true
bg_ak74_rpkbarrel = true
bg_ak74_ubarrel = true
bg_ak74foldablestock = true
bg_ak74heavystock = true
bg_ak74rpkmag = true
bg_ar1560rndmag = true
bg_ar15heavystock = true
bg_ar15sturdystock = true
bg_bipod = true
bg_deagle_compensator = true
bg_deagle_extendedbarrel = true
bg_foldsight = true
bg_longbarrel = true
bg_longbarrelmr96 = true
bg_longris = true
bg_magpulhandguard = true
bg_mp530rndmag = true
bg_mp5_kbarrel = true
bg_mp5_sdbarrel = true
bg_nostock = true
bg_regularbarrel = true
bg_retractablestock = true
bg_ris = true
bg_sg1scope = true
md_acog = true
md_aimpoint = true
md_anpeq15 = true
md_cobram2 = true
md_eotech = true
md_foregrip = true
md_kobra = true
md_m203 = true
md_microt1 = true
md_pbs1 = true
md_pso1 = true
md_saker = true
md_tundra9mm = true
CalcIdeal = 990
CalcSeqOverride = -1
DTVar = function: 0x1ca93680
EditValue = function: 0x2ac6c878
GetEditingData = function: 0x18501238
GetNetworkKeyValue = function: 0x1caf7ec0
GetNetworkVars = function: 0x1caf9640
LastDamageType = Entity [0][worldspawn]
LastPlayerTrace = 859.94995117188
LastSpawnpoint = Entity [61][info_player_start]
NetworkVar = function: 0x2375b100
NetworkVarElement = function: 0x23785a08
NetworkVarNotify = function: 0x1844e3c8
PlayerTrace:
Entity = Entity [0][worldspawn]
Fraction = 0.49089023470879
FractionLeftSolid = 0
Hit = true
HitBox = 0
HitGroup = 0
HitNoDraw = false
HitNonWorld = false
HitNormal = -1.000000 0.000000 0.000000
HitPos = 15359.968750 950.995850 -12563.697266
HitSky = true
HitTexture = TOOLS/TOOLSSKYBOX
HitWorld = true
MatType = 88
Normal = 0.998662 0.047185 -0.021163
PhysicsBone = 0
StartPos = -704.000000 192.000000 -12223.280273
StartSolid = false
SurfaceProps = 77
RestoreNetworkVars = function: 0x184b21a8
SCarMouseMoveX = 0
SCarMouseMoveY = 0
SetNetworkKeyValue = function: 0x1838a3f8
SetupEditing = function: 0x0f107ab8
SetupKeyValue = function: 0x1844da70
WT_RagdollRoper_Roping = false
canChat = 864.94995117188
dt:
m_CurrentPlayerClass:
ClassID = 125
Func = function: 0x1ca70b58
Player = Player [1][UbErZ Andrew900460]
m_bFlashlight = true
m_bInSwim = false
m_bWasNoclipping = false
m_bWasOnGround = true
////////////////////////////////////////////////////////////////
CLIENT SIDE
CWAttachments:
am_flechetterounds = true
am_magnum = true
am_matchgrade = true
am_slugrounds = true
bg_ak74_rpkbarrel = true
bg_ak74_ubarrel = true
bg_ak74foldablestock = true
bg_ak74heavystock = true
bg_ak74rpkmag = true
bg_ar1560rndmag = true
bg_ar15heavystock = true
bg_ar15sturdystock = true
bg_bipod = true
bg_deagle_compensator = true
bg_deagle_extendedbarrel = true
bg_foldsight = true
bg_longbarrel = true
bg_longbarrelmr96 = true
bg_longris = true
bg_magpulhandguard = true
bg_mp530rndmag = true
bg_mp5_kbarrel = true
bg_mp5_sdbarrel = true
bg_nostock = true
bg_regularbarrel = true
bg_retractablestock = true
bg_ris = true
bg_sg1scope = true
md_acog = true
md_aimpoint = true
md_anpeq15 = true
md_cobram2 = true
md_eotech = true
md_foregrip = true
md_kobra = true
md_m203 = true
md_microt1 = true
md_pbs1 = true
md_pso1 = true
md_saker = true
md_tundra9mm = true
CalcIdeal = 990
CalcSeqOverride = -1
ChatGestureWeight = 0
DTVar = function: 0x2be3b410
EditValue = function: 0x3053c750
GetEditingData = function: 0x2bb01b30
GetNetworkKeyValue = function: 0x2bb01d18
GetNetworkVars = function: 0x2bb01d38
LastPlayerTrace = 859.96203613281
NetworkVar = function: 0x2bb01c98
NetworkVarElement = function: 0x2bab5340
NetworkVarNotify = function: 0x2bb01cd8
PlayerTrace:
Entity = Entity [0][worldspawn]
Fraction = 0.49089023470879
FractionLeftSolid = 0
Hit = true
HitBox = 0
HitGroup = 0
HitNoDraw = false
HitNonWorld = false
HitNormal = -1.000000 0.000000 0.000000
HitPos = 15359.968750 950.995850 -12563.697266
HitSky = true
HitTexture = TOOLS/TOOLSSKYBOX
HitWorld = true
MatType = 88
Normal = 0.998662 0.047185 -0.021163
PhysicsBone = 0
StartPos = -704.000000 192.000000 -12223.280273
StartSolid = false
SurfaceProps = 77
RestoreNetworkVars = function: 0x2bb01d58
SetNetworkKeyValue = function: 0x2bb01cf8
SetupEditing = function: 0x2bb01c38
SetupKeyValue = function: 0x2bb01c58
dt:
m_CurrentPlayerClass:
ClassID = 125
Func = function: 0x30283ff8
Player = Player [1][UbErZ Andrew900460]
m_bInSwim = false
m_bWasNoclipping = false
m_bWasOnGround = true
If you wish to have a network shared variable that you can assign to an entity (e.g. a player) you want to use NWVariables. In your situation, since you are saving an entity you want to look at SetNWEntity and GetNWEntity.
Here is how you would implement it in the PlayerShouldTakeDamage hook:
function GM:PlayerShouldTakeDamage(ply, attacker)
ply:SetNWEntity("LastDamageType", attacker)
return true
end

Resources