Related
Everything has been going smooth until the new roblox update and now my barrage effect clones make the game insanely laggy.
Any help on optimizing it would be greatly appreciated.
I know this might sound lazy but it would be great if you could optimize it for me. I have 0 idea how to optimize and this is my last hope.
local EffectModule = require(game.ServerStorage:WaitForChild("HitEffectModule"))
local event = game:GetService("ReplicatedStorage"):WaitForChild("TheWorld").Barrage -- this is the event which fires from client to server
local TweenService = game:GetService("TweenService") -- this is a very useful function for extra effects
local Debris = game:GetService("Debris")
local Damage = 1.8
local Punched = game.Workspace.Sounds.Punched
--u can get ur own one im just using a free one as an example
local function Detect(Character)
local Hitbox = script.Hitbox:Clone()
Hitbox.Parent = workspace
Hitbox.CFrame = Character.PrimaryPart.CFrame * CFrame.new(0,0,Hitbox.Size.Z/2 * -1)
Debris:AddItem(Hitbox,.3)
local Connection
Connection = Hitbox.Touched:Connect(function(hitted)
if hitted.Parent:FindFirstChild("Humanoid") and not hitted:IsDescendantOf(Character) then
local Enemy = hitted.Parent
Enemy.Humanoid:TakeDamage(Damage)
Connection:Disconnect()
Hitbox:Destroy()
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(1e6,1e6,1e6)
bv.Velocity = Character.PrimaryPart.CFrame.LookVector * 10
Debris:AddItem(bv,.2)
bv.Parent = Enemy.PrimaryPart
EffectModule.Gore2(Enemy.UpperTorso)
Enemy.Humanoid:LoadAnimation(script.HitAnim):Play()
Punched:Play()
Enemy.Humanoid.WalkSpeed = 3
wait(1)
Enemy.Humanoid.WalkSpeed = 16
end
end)
end
local function CreateArm(Character)
local Stand = game:GetService("ServerStorage").StandModel.TheWorld
local StartXR = math.random(150,350)/100
Detect(Character)
local StartXL = math.random(150,350)/100 * -1
local StartYR = math.random(-150,250)/100
local StartYL = math.random(-150,250)/100
local LeftArmModel = Instance.new("Model")
LeftArmModel.Name = "LeftArm"
LeftArmModel.Parent = game.Workspace
Debris:AddItem(LeftArmModel,.3)
local LLA = Stand:FindFirstChild("LeftLowerArm"):Clone()
LLA.Parent = LeftArmModel
local LUA = Stand:FindFirstChild("LeftUpperArm"):Clone()
LUA.Parent = LeftArmModel
local LH = Stand:FindFirstChild("LeftHand"):Clone()
LH.Parent = LeftArmModel
local weld1 = Instance.new("WeldConstraint")
weld1.Part0 = LH
weld1.Part1 = LLA
weld1.Parent = LH
local weld2 = Instance.new("WeldConstraint")
weld2.Part0 = LUA
weld2.Part1 = LLA
weld2.Parent = LUA
for i , v in pairs(LeftArmModel:GetDescendants()) do
if v:IsA("Texture") or v:IsA("BasePart") or v:IsA("Decal") then
v.Transparency = .2
TweenService:Create(v,TweenInfo.new(.3),{Transparency = .75}):Play()
end
if v:IsA("Motor6D") then
v:Destroy()
end
end
LeftArmModel.PrimaryPart = LLA
LeftArmModel.PrimaryPart.Anchored = true
LeftArmModel.PrimaryPart.CFrame = CFrame.new(Character.PrimaryPart.CFrame * CFrame.new(StartXL,StartYL,-1.5).p,Character.PrimaryPart.CFrame * CFrame.new(StartXL * .4,StartYL * .4,-8).p) * CFrame.Angles(math.rad(90),0,0)
TweenService:Create(LeftArmModel.PrimaryPart,TweenInfo.new(.3),{CFrame = LeftArmModel.PrimaryPart.CFrame * CFrame.new(0,-5,0)}):Play()
local RightArmModel = Instance.new("Model")
RightArmModel.Name = "LeftArm"
RightArmModel.Parent = game.Workspace
Debris:AddItem(RightArmModel,.3)
local RLA = Stand:FindFirstChild("RightLowerArm"):Clone()
RLA.Parent = RightArmModel
local RUA = Stand:FindFirstChild("RightUpperArm"):Clone()
RUA.Parent = RightArmModel
local RH = Stand:FindFirstChild("RightHand"):Clone()
RH.Parent = RightArmModel
local weld1 = Instance.new("WeldConstraint")
weld1.Part0 = RH
weld1.Part1 = RLA
weld1.Parent = RH
local weld2 = Instance.new("WeldConstraint")
weld2.Part0 = RUA
weld2.Part1 = RLA
weld2.Parent = RUA
for i , v in pairs(RightArmModel:GetDescendants()) do
if v:IsA("Texture") or v:IsA("BasePart") or v:IsA("Decal") then
v.Transparency = .2
TweenService:Create(v,TweenInfo.new(.3),{Transparency = .75}):Play()
end
if v:IsA("Motor6D") then
v:Destroy()
end
end
RightArmModel.PrimaryPart = RLA
RightArmModel.PrimaryPart.Anchored = true
RightArmModel.PrimaryPart.CFrame = CFrame.new(Character.PrimaryPart.CFrame * CFrame.new(StartXR,StartYR,-1.5).p,Character.PrimaryPart.CFrame * CFrame.new(StartXR * .4,StartYR * .4,-8).p) * CFrame.Angles(math.rad(90),0,0)
TweenService:Create(RightArmModel.PrimaryPart,TweenInfo.new(.3),{CFrame = RightArmModel.PrimaryPart.CFrame * CFrame.new(0,-5,0)}):Play()
end
event.OnServerEvent:Connect(function(Player,hold)
local Character = Player.Character
local Stand = Character:FindFirstChild(Character.Name)
if Stand then
if not Character:FindFirstChild("Barraging") then
if hold == true and Character.UsingMove.Value == false then
local barraging = Instance.new("BoolValue")
barraging.Name = "Barraging"
barraging.Parent = Character
Character.UsingMove.Value = true
Character.PrimaryPart.StandPosition.Position = Vector3.new(0,-1,-2)
local Anim = Stand.AnimationController:LoadAnimation(script.Anim)
Anim:Play()
local Sound = script.BarrageSound:Clone()
Sound.Parent = Character.PrimaryPart
Sound:Play()
local Starttime = tick()
repeat
wait(.30)
CreateArm(Character)
until tick() - Starttime >= 5 or not Character:FindFirstChild("Barraging")
Character.PrimaryPart.StandPosition.Position = Vector3.new(-2,0.7,3)
Anim:Stop()
Sound:Destroy()
Character.UsingMove.Value = false
end
else
Character:FindFirstChild("Barraging"):Destroy()
end
end
end)
Instead of cloning it from a storage, at the start just clone a bunch of them and keep them very high up in sky so that it wont be rendered, and as you need them position them accordingly while switching them.
maybe is a simple issue but I'm pretty new to EF so:
I have this query:
Dim InvoicesQuery = (From i As Invoice In dbContext.Invoices.AsNoTracking() Where i.InvoiceNumber = -1
Select New InvoicesWithDetails With {
.InvoiceDetails = i.InvoicesDetails,
.InvoiceDetailsUnmerged = i.InvoicesDetailsUnmergeds,
.Examination = Nothing,
.Applicant = Nothing,
.InvoiceNumber = i.InvoiceNumber,
.InvoiceYear = i.InvoiceYear,
.DocCode = i.DocCode,
.CompanyId = i.CompanyId,
.InvoiceDate = i.InvoiceDate,
.NetAmount = i.NetAmount,
.AmountPaid = i.AmountPaid,
.AmountToPay = i.AmountToPay,
.VAT = i.VAT,
.AdditionalTax = i.AdditionalTax,
.Status = i.Status,
.Amount = i.Amount,
.ExaminationId = i.ExaminationId,
.ReceiverName = If(i.OtherReceiverName Is Nothing, i.ReceiverName, i.OtherReceiverName),
.ReceiverAddress = If(i.OtherReceiverAddress Is Nothing, i.ReceiverAddress, i.OtherReceiverAddress),
.ReceiverCity = If(i.OtherReceiverCity Is Nothing, i.ReceiverCity, i.OtherReceiverCity),
.ReceiverTaxCode = If(i.OtherReceiverTaxCode Is Nothing, i.ReceiverTaxCode, i.OtherReceiverTaxCode),
.ReceiverCompanyTaxCode = i.ReceiverCompanyTaxCode,
.ReceiverZipCode = If(i.OtherReceiverZipCode Is Nothing, i.ReceiverZipCode, i.OtherReceiverZipCode),
.IsCreditNote = i.IsCreditNote,
.HasCreditNote = i.HasCreditNote,
.FixedAdditionalAmountOnInvoice = i.FixedAdditionalAmountOnInvoice,
.CashFlowPaymentModeId = If(i.CashFlowPaymentModeId IsNot Nothing, i.CashFlowPaymentModeId.Trim, Nothing),
.AgreementDeductible = i.AgreementDeductible,
.IsPatientInvoiceRecipient = i.IsPatientInvoiceRecipient,
.IsApplicantInvoiceRecipient = i.IsApplicantInvoiceRecipient,
.IsDoctorInvoiceRecipient = i.IsDoctorInvoiceRecipient,
.DoctorId = If(i.DoctorId IsNot Nothing, i.DoctorId, Nothing),
.Doctor = Nothing,
.CreditNoteParentInvoice = i.CreditNoteParentInvoice,
.CreditNoteParentInvoiceYear = i.CreditNoteParentInvoiceYear,
.IsDeferredInvoice = i.IsDeferredInvoice,
.IsExtracted = If(i.IsExtracted IsNot Nothing, i.IsExtracted, False),
.IsExportedToHOST = If(i.IsExportedToHOST IsNot Nothing, i.IsExportedToHOST, False),
.ApplicantId = i.ApplicantId,
.InvoiceHasVAT = i.InvoiceHasVAT,
.VAT_Percentage = i.VAT_Percentage,
.IssuedBy = i.IssuedBy,
.MaskedCounter = i.MaskedCounter,
.DocTypeId = i.DocTypeId,
.OtherReceiverName = i.OtherReceiverName,
.OtherReceiverAddress = i.OtherReceiverAddress,
.OtherReceiverCity = i.OtherReceiverCity,
.OtherReceiverTaxCode = i.OtherReceiverTaxCode,
.OtherReceiverZipCode = i.OtherReceiverZipCode,
.CashFlows = i.CashFlows}).ToList
InvoicesWithDetails is a class that hinerits Invoice; Invoice is a db entity
After this call I loop through the results like this:
For Each i As InvoicesWithDetails In InvoicesQuery.Where(Function(iwd) iwd.CompanyDescription Is Nothing And iwd.CompanyId IsNot Nothing)
i.CompanyDescription = ReturnCompanyDescription(i.CompanyId)
Next
For each cycle in the loop the database is called.
I thought that after the .ToList in the first call I could iterate the results without invoke the database.
What is wrong?
Thanks in advance
Ok, I worked more on that and I tried a different approach:
This is the new query, targeting the Invoice entity:
Dim InvoicesQuery As List(Of Invoice)
InvoicesQuery = (From i As Invoice In dbContext.Invoices.AsNoTracking Where
i.InvoiceDate >= FromDate And i.InvoiceDate <= ToDate).ToList
After that I create a new istance of InvoiceWithDetails and set all the properties like this:
For Each i As Invoice In InvoicesQuery
Dim newInvoiceWithDetails As New InvoicesWithDetails
With newInvoiceWithDetails
.InvoiceDetails = i.InvoicesDetails
.InvoiceDetailsUnmerged = i.InvoicesDetailsUnmergeds
.Examination = Nothing
.Applicant = Nothing
.InvoiceNumber = i.InvoiceNumber
.InvoiceYear = i.InvoiceYear
.DocCode = i.DocCode
.CompanyId = i.CompanyId
.InvoiceDate = i.InvoiceDate
.NetAmount = i.NetAmount
.AmountPaid = i.AmountPaid
.AmountToPay = i.AmountToPay
.VAT = i.VAT
.AdditionalTax = i.AdditionalTax
.Status = i.Status
.Amount = i.Amount
.ExaminationId = i.ExaminationId
.ReceiverName = If(i.OtherReceiverName Is Nothing, i.ReceiverName, i.OtherReceiverName)
.ReceiverAddress = If(i.OtherReceiverAddress Is Nothing, i.ReceiverAddress, i.OtherReceiverAddress)
.ReceiverCity = If(i.OtherReceiverCity Is Nothing, i.ReceiverCity, i.OtherReceiverCity)
.ReceiverTaxCode = If(i.OtherReceiverTaxCode Is Nothing, i.ReceiverTaxCode, i.OtherReceiverTaxCode)
.ReceiverCompanyTaxCode = i.ReceiverCompanyTaxCode
.ReceiverZipCode = If(i.OtherReceiverZipCode Is Nothing, i.ReceiverZipCode, i.OtherReceiverZipCode)
.IsCreditNote = i.IsCreditNote
.HasCreditNote = i.HasCreditNote
.FixedAdditionalAmountOnInvoice = i.FixedAdditionalAmountOnInvoice
.CashFlowPaymentModeId = If(i.CashFlowPaymentModeId IsNot Nothing, i.CashFlowPaymentModeId.Trim, Nothing)
.AgreementDeductible = i.AgreementDeductible
.IsPatientInvoiceRecipient = i.IsPatientInvoiceRecipient
.IsApplicantInvoiceRecipient = i.IsApplicantInvoiceRecipient
.IsDoctorInvoiceRecipient = i.IsDoctorInvoiceRecipient
.DoctorId = If(i.DoctorId IsNot Nothing, i.DoctorId, Nothing)
.Doctor = Nothing
.CreditNoteParentInvoice = i.CreditNoteParentInvoice
.CreditNoteParentInvoiceYear = i.CreditNoteParentInvoiceYear
.IsDeferredInvoice = i.IsDeferredInvoice
.IsExtracted = If(i.IsExtracted IsNot Nothing, i.IsExtracted, False)
.IsExportedToHOST = If(i.IsExportedToHOST IsNot Nothing, i.IsExportedToHOST, False)
.ApplicantId = i.ApplicantId
.InvoiceHasVAT = i.InvoiceHasVAT
.VAT_Percentage = i.VAT_Percentage
.IssuedBy = i.IssuedBy
.MaskedCounter = i.MaskedCounter
.DocTypeId = i.DocTypeId
.OtherReceiverName = i.OtherReceiverName
.OtherReceiverAddress = i.OtherReceiverAddress
.OtherReceiverCity = i.OtherReceiverCity
.OtherReceiverTaxCode = i.OtherReceiverTaxCode
.OtherReceiverZipCode = i.OtherReceiverZipCode
.CashFlows = i.CashFlows
End With
FinalList.Add(newInvoiceWithDetails)
For each cycle and each property value, the database is invoked
Again, what is wrong?
Keep getting an automation error when my userform uses the below code when it initializes. I dont get an error when i take it out. The userform is being called from a shape using a module. the text from the userform is stored under a sheet called "Compliance". My userform is also called compliance. Here is my code below, any help would be much appreciated:
Private Sub UserForm_Initialize()
Dim ws As Worksheet
Set ws = Sheets("compliance")
On Error Resume Next
With page1
employee1.Value = ws.Range("B2")
employee2.Value = ws.Range("B3")
employee3.Value = ws.Range("B4")
employee4.Value = ws.Range("B5")
employee5.Value = ws.Range("B5")
employee6.Value = ws.Range("B6")
'//// setting ops grade
grade1.Value = ws.Range("D2")
grade2.Value = ws.Range("D3")
grade3.Value = ws.Range("D4")
grade4.Value = ws.Range("D5")
grade5.Value = ws.Range("D6")
grade6.Value = ws.Range("D7")
'//// setting employee compliance recap
recap1.Value = ws.Range("F2")
recap2.Value = ws.Range("F3")
recap3.Value = ws.Range("F4")
recap4.Value = ws.Range("F5")
recap5.Value = ws.Range("F6")
recap6.Value = ws.Range("F7")
'////////////////////////////////////////// febraury
'//// setting employees interviewed
With page2
febemp1.Value = ws.Range("B14")
febemp2.Value = ws.Range("B15")
febemp3.Value = ws.Range("B16")
febemp4.Value = ws.Range("B17")
febemp5.Value = ws.Range("B18")
febemp6.Value = ws.Range("B19")
febgrd1.Value = ws.Range("D14")
febgrd2.Value = ws.Range("D15")
febgrd3.Value = ws.Range("D16")
febgrd4.Value = ws.Range("D17")
febgrd5.Value = ws.Range("D18")
febgrd6.Value = ws.Range("D19")
febrecap1.Value = ws.Range("F14")
febrecap2.Value = ws.Range("F15")
febrecap3.Value = ws.Range("F16")
febrecap4.Value = ws.Range("F17")
febrecap5.Value = ws.Range("F18")
febrecap6.Value = ws.Range("F19")
With page3
marchemp1.Value = ws.Range("B26")
marchemp2.Value = ws.Range("B27")
marchemp3.Value = ws.Range("B28")
marchemp4.Value = ws.Range("B29")
marchemp5.Value = ws.Range("B30")
marchemp6.Value = ws.Range("B31")
marchgrd1.Value = ws.Range("D26")
marchgrd2.Value = ws.Range("D27")
marchgrd3.Value = ws.Range("D28")
marchgrd4.Value = ws.Range("D29")
marchgrd5.Value = ws.Range("D30")
marchgrd6.Value = ws.Range("D31")
marchrecap1.Value = ws.Range("F26")
marchrecap2.Value = ws.Range("F27")
marchrecap3.Value = ws.Range("F28")
marchrecap4.Value = ws.Range("F29")
marchrecap5.Value = ws.Range("F30")
marchrecap6.Value = ws.Range("F31")
With page4
apremp1.Value = ws.Range("B38")
apremp2.Value = ws.Range("B39")
apremp3.Value = ws.Range("B40")
apremp4.Value = ws.Range("B41")
apremp5.Value = ws.Range("B42")
apremp6.Value = ws.Range("B43")
aprgrd1.Value = ws.Range("D38")
aprgrd2.Value = ws.Range("D39")
aprgrd3.Value = ws.Range("D40")
aprgrd4.Value = ws.Range("D41")
aprgrd5.Value = ws.Range("D42")
aprgrd6.Value = ws.Range("D43")
aprrecap1.Value = ws.Range("F38")
aprrecap2.Value = ws.Range("F39")
aprrecap3.Value = ws.Range("F40")
aprrecap4.Value = ws.Range("F41")
aprrecap5.Value = ws.Range("F42")
aprrecap6.Value = ws.Range("F43")
With page5
mayemp1.Value = ws.Range("B50")
mayemp2.Value = ws.Range("B51")
mayemp3.Value = ws.Range("B52")
mayemp4.Value = ws.Range("B53")
mayemp5.Value = ws.Range("B54")
mayemp6.Value = ws.Range("B55")
maygrd1.Value = ws.Range("D50")
maygrd2.Value = ws.Range("D51")
maygrd3.Value = ws.Range("D52")
maygrd4.Value = ws.Range("D53")
maygrd5.Value = ws.Range("D54")
maygrd6.Value = ws.Range("D55")
mayrecap1.Value = ws.Range("F50")
mayrecap2.Value = ws.Range("F51")
mayrecap3.Value = ws.Range("F52")
mayrecap4.Value = ws.Range("F53")
mayrecap5.Value = ws.Range("F54")
mayrecap6.Value = ws.Range("F55")
With page6
junemp1.Value = ws.Range("B62")
junemp2.Value = ws.Range("B63")
junemp3.Value = ws.Range("B64")
junemp4.Value = ws.Range("B65")
junemp5.Value = ws.Range("B66")
junemp6.Value = ws.Range("B67")
jungrd1.Value = ws.Range("D62")
jungrd2.Value = ws.Range("D63")
jungrd3.Value = ws.Range("D64")
jungrd4.Value = ws.Range("D65")
jungrd5.Value = ws.Range("D66")
jungrd6.Value = ws.Range("D67")
junrecap1.Value = ws.Range("F62")
junrecap2.Value = ws.Range("F63")
junrecap3.Value = ws.Range("F64")
junrecap4.Value = ws.Range("F65")
junrecap5.Value = ws.Range("F66")
junrecap6.Value = ws.Range("F67")
With page7
julemp1.Value = ws.Range("B74")
julemp2.Value = ws.Range("B75")
julemp3.Value = ws.Range("B76")
julemp4.Value = ws.Range("B77")
julemp5.Value = ws.Range("B78")
julemp6.Value = ws.Range("B79")
julgrd1.Value = ws.Range("D74")
julgrd2.Value = ws.Range("D75")
julgrd3.Value = ws.Range("D76")
julgrd4.Value = ws.Range("D77")
julgrd5.Value = ws.Range("D78")
julgrd6.Value = ws.Range("D79")
julrecap1.Value = ws.Range("F74")
julrecap2.Value = ws.Range("F75")
julrecap3.Value = ws.Range("F76")
julrecap4.Value = ws.Range("F77")
julrecap5.Value = ws.Range("F78")
julrecap6.Value = ws.Range("F79")
With page8
augemp1.Value = ws.Range("B86")
augemp2.Value = ws.Range("B87")
augemp3.Value = ws.Range("B88")
augemp4.Value = ws.Range("B89")
augemp5.Value = ws.Range("B90")
augemp6.Value = ws.Range("B91")
auggrd1.Value = ws.Range("D86")
auggrd2.Value = ws.Range("D87")
auggrd3.Value = ws.Range("D88")
auggrd4.Value = ws.Range("D89")
auggrd5.Value = ws.Range("D90")
auggrd6.Value = ws.Range("D91")
augrecap1.Value = ws.Range("F86")
augrecap2.Value = ws.Range("F87")
augrecap3.Value = ws.Range("F88")
augrecap4.Value = ws.Range("F89")
augrecap5.Value = ws.Range("F90")
augrecap6.Value = ws.Range("F91")
With page9
sepemp1.Value = ws.Range("B98")
sepemp2.Value = ws.Range("B99")
sepemp3.Value = ws.Range("B100")
sepemp4.Value = ws.Range("B101")
sepemp5.Value = ws.Range("B102")
sepemp6.Value = ws.Range("B103")
sepgrd1.Value = ws.Range("D98")
sepgrd2.Value = ws.Range("D99")
sepgrd3.Value = ws.Range("D100")
sepgrd4.Value = ws.Range("D101")
sepgrd5.Value = ws.Range("D102")
sepgrd6.Value = ws.Range("D103")
seprecap1.Value = ws.Range("F98")
seprecap2.Value = ws.Range("F99")
seprecap3.Value = ws.Range("F100")
seprecap4.Value = ws.Range("F101")
seprecap5.Value = ws.Range("F102")
seprecap6.Value = ws.Range("F103")
With page10
octemp1.Value = ws.Range("B110")
octemp2.Value = ws.Range("B111")
octemp3.Value = ws.Range("B112")
octemp4.Value = ws.Range("B113")
octemp5.Value = ws.Range("B114")
octemp6.Value = ws.Range("B115")
octgrd1.Value = ws.Range("D110")
octgrd2.Value = ws.Range("D111")
octgrd3.Value = ws.Range("D112")
octgrd4.Value = ws.Range("D113")
octgrd5.Value = ws.Range("D114")
octgrd6.Value = ws.Range("D115")
octrecap1.Value = ws.Range("F110")
octrecap2.Value = ws.Range("F111")
octrecap3.Value = ws.Range("F112")
octrecap4.Value = ws.Range("F113")
octrecap5.Value = ws.Range("F114")
octrecap6.Value = ws.Range("F115")
With page11
novemp1.Value = ws.Range("B122")
novemp2.Value = ws.Range("B123")
novemp3.Value = ws.Range("B124")
novemp4.Value = ws.Range("B125")
novemp5.Value = ws.Range("B126")
novemp6.Value = ws.Range("B127")
novgrd1.Value = ws.Range("D122")
novgrd2.Value = ws.Range("D123")
novgrd3.Value = ws.Range("D124")
novgrd4.Value = ws.Range("D125")
novgrd5.Value = ws.Range("D126")
novgrd6.Value = ws.Range("D127")
novrecap1.Value = ws.Range("F122")
novrecap2.Value = ws.Range("F123")
novrecap3.Value = ws.Range("F124")
novrecap4.Value = ws.Range("F125")
novrecap5.Value = ws.Range("F126")
novrecap6.Value = ws.Range("F127")
With page12
decemp1.Value = ws.Range("B134")
decemp2.Value = ws.Range("B135")
decemp3.Value = ws.Range("B136")
decemp4.Value = ws.Range("B137")
decemp5.Value = ws.Range("B138")
decemp6.Value = ws.Range("B139")
decgrd1.Value = ws.Range("D134")
decgrd2.Value = ws.Range("D135")
decgrd3.Value = ws.Range("D136")
decgrd4.Value = ws.Range("D137")
decgrd5.Value = ws.Range("D138")
decgrd6.Value = ws.Range("D139")
decrecap1.Value = ws.Range("F134")
decrecap2.Value = ws.Range("F135")
decrecap3.Value = ws.Range("F136")
decrecap4.Value = ws.Range("F137")
decrecap5.Value = ws.Range("F138")
decrecap6.Value = ws.Range("F139")
End With
End With
End With
End With
End With
End With
End With
End With
End With
End With
End With
End With
End Sub
Untested - too many controls to make...
You'd need to harmonize your control naming a bit, but something like this should work:
Private Sub UserForm_Initialize()
Dim ws As Worksheet, mNum As Long, months, i As Long, m
Dim c As Range
Set ws = Sheets("compliance")
Set c = ws.Range("B1")
months = Array("jan", "feb", "mar", "apr", "may", "jun", _
"jul", "aug", "sep", "oct", "nov", "dec")
For mNum = 1 To 12
m = months(m - 1)
With Me.MultiPage1.Pages("page" & mNum)
For i = 1 To 6
.Controls(m & "emp" & i).Value = c.Offset(i, 0).Value
.Controls(m & "grd" & i).Value = c.Offset(i, 2).Value
.Controls(m & "recap" & i).Value = c.Offset(i, 4).Value
Next i
End With
Set c = c.Offset(12, 0)
Next mNum
End Sub
I'm working on an access project using vba and one of the programs has several queries like UPDATE A INNER JOIN B ON condition SET field = value .Both table A and Table B have hundreds of thousands records.
The annoying thing is these queries will take more than ten hours to execute and I was trying to use index to improve the performance but failed. Any suggestions to help me out?
Here is one of the queries:
strSQL = "UPDATE [csd_dis_" & i_year & "_all] as d INNER JOIN [adm_" & a_yyyy & "] as aa ON d.d_cino = aa.a_cino and cstr(d.d_sentdte) = cstr(aa.a_sentdte) and right('00' + trim(str(d.m_d_nature)),2) = left(trim(cstr(aa.m_a_nature)),2) "
strSQL = strSQL & "SET d.match_adm = " & kk & ",d.a_local_p = aa.a_local_p,d.inst = aa.c_inst, d.dosy = aa.dosy,d.dosm = aa.dosm,d.dosd = aa.dosd, " _
& "d.a_sentdte = aa.a_sentdte,d.tid = aa.tid,d.crb = aa.crb,d.crbchk = aa.crbchk, d.court = aa.court,d.ccn = aa.ccn,d.cyr = aa.cyr,d.a_nature = aa.nature,d.nature_o = aa.nature_o, " _
& "d.m_a_nature = aa.m_a_nature,d.class = aa.class,d.cat = aa.cat,d.ilossp = aa.ilossp,d.chap = aa.chap,d.sect = aa.sect,d.newoff = aa.newoff,d.hkid = aa.hkid,d.sex = aa.sex,d.doby = aa.doby,d.dobm = aa.dobm, " _
& "d.dobd = aa.dobd,d.a_dob = aa.a_dob,d.a_dob_imp = aa.a_dob_imp,d.age = aa.age,d.accom = aa.accom,d.disres = aa.disres,d.yrres = aa.yrres,d.edu = aa.edu,d.marst = aa.marst,d.bplbir = aa.bplbir,d.plbir = aa.plbir,d.yrhk = aa.yrhk, " _
& "d.[on] = aa.[on],d.sently = aa.sently,d.sentlm = aa.sentlm,d.sentld = aa.sentld,d.tr = aa.tr,d.dr = aa.dr,d.mr = aa.mr,d.inr = aa.inr,d.pvdg = aa.pvdg, d.pvndg = aa.pvndg,d.pvcn = aa.pvcn,d.pvcn2 = aa.pvcn2,d.bghome = aa.bghome, " _
& "d.pvdc = aa.pvdc,d.pvtc = aa.pvtc,d.pvdatc = aa.pvdatc,d.pvrc = aa.pvrc,d.pvpri = aa.pvpri,d.pvinst = aa.pvinst,d.foffen = aa.foffen,d.dfcy = aa.dfcy,d.dfcm = aa.dfcm,d.dfcd = aa.dfcd,d.a_dfcdte = aa.a_dfcdte, " _
& "d.agefcn = aa.agefcn,d.trisoc = aa.trisoc,d.ddpur = aa.ddpur,d.dcost = aa.dcost,d.cumd = aa.cumd,d.needle = aa.needle,d.yrdg = aa.yrdg,d.causa = aa.causa,d.fdg = aa.fdg,d.fmd = aa.fmd,d.agefdg = aa.agefdg, " _
& "d.yradd = aa.yradd,d.asso = aa.asso,d.la = aa.la,d.origin = aa.origin,d.mode = aa.mode,d.arrest = aa.arrest,d.stayy = aa.stayy,d.staym = aa.staym,d.stayd = aa.stayd,d.occ = aa.occ,d.name = aa.name,d.cname = aa.cname," _
& "d.othdocno = aa.othdocno,d.cudg1 = aa.cudg1,d.cudg2 = aa.cudg2,d.cudg3 = aa.cudg3,d.cudg4 = aa.cudg4,d.psydrug1 = aa.psydrug1,d.psydrug2 = aa.psydrug2,d.psydrug3 = aa.psydrug3, " _
& "d.psydrug4 = aa.psydrug4,d.agefpsy = aa.agefpsy,d.psydgfreq = aa.psydgfreq,d.psycausa = aa.psycausa WHERE '" & matchkey & "' and d.match_adm=' '"
I am new to VB.net and facing a strange situation. I have a structure that contains another structure. The inner structure is nullable. Now wht I do is something like the following. I create a new instance of the inner structure, set the member variables and assign the whole structure to the inner structure of the parent. But it is giving an error. The assignment is not successful. If I try to peek into the structure in the watch window, it says "property evaluation failed" for the HasValue and Value properties.
Dim testData As List(Of TestData) = Nothing
Dim testData_List1 As New TestData
With testData_List1.commonTestParam
.AccuchekActiveEnergy = 2.56
.AccuchekActiveEnergyUnit = ActiveEnergyUnit.KiloWattHour
.AccuchekApparentEnergy = 34.56
.AccuchekApparentEnergyUnit = ApparentEnergyUnit.VoltAmpereHour
.AccuchekFrequency = 1
.AccuchekRange = "20474 ewr 34324"
.AccuchekType = AccuchekType.AccuchekOne
.ActiveLoadRPhase = 145
.AvgActiveLoad = 2.56
.AvgActiveLoadUnit = ActiveLoadUnit.Watt
.AvgPowerFactor = 0
.AvgPowerFactorType = PowerFactorType.PFLag
.ConditionalFlag1 = 0
.ConsumerNo = "343122050242"
.CurrentRPhase = 1
.GeneralFlag1 = 0
.InstantaneousPFRPhase = 2
.ManufacturingYear = 2009
.MeterActiveEnergy = 258.89
.MeterActiveEnergyUnit = ActiveEnergyUnit.KiloWattHour
.MeterActiveError = 20
.MeterApparentError = 14
.MeterConstant = 3200
.MeterConstantUnit = MeterConstantUnit.RevsPerkVAh
.MeterMake = "DS"
.MeterSNo = "6563402"
.MeterTypeAndClass = MeterTypeAndClass.MTCElectorMechWith20
.MTFID = "123456789"
.NoofTestRevolutions = 100
.PulseCriteria = 0
.RatedBasic = 25
.RatedMax = 30
.RatedVoltage = 15
.ReactiveCurrentRPhase = 145
.RemarkID = 0
.TestDateAndTime = "100320101545"
.TestDuration = 2145
.TesterCode = 0
.TestID = "147852"
.TestMode = TestMode.TMOpticalScanner
.TestNumber = 0
.VoltageRPhase = 145
End With
Dim accuchek3TestParameters1 As New Accuchek3PhaseTestParameters
With accuchek3TestParameters1
.AccuchekReactiveLagEnergy = 2.46
.AccuchekReactiveLagEnergyUnit = ReactiveEnergyUnit.KiloVoltAmpereReactiveHour
.AccuchekReactiveLeadEnergy = 2.56
.AccuchekReactiveLeadEnergyUnit = ReactiveEnergyUnit.KiloVoltAmpereReactiveHour
.ActiveLoadBPhase = 14
.ActiveLoadYPhase = 15
.AvgApparentLoad = 10
.AvgApparentLoadUnit = ApparentLoadUnit.KiloVoltAmpere
.AvgReactiveLagLoad = 14
.AvgReactiveLagLoadUnit = ReactiveLoadUnit.KiloVoltAmpereReactive
.AvgReactiveLeadLoad = 15
.AvgReactiveLeadLoadUnit = ReactiveLoadUnit.KiloVoltAmpereReactive
.ConditionalFlag2 = 0
.ConditionalFlag3 = 0
.CTRatio = 1.23
.CurrentBPhase = 10
.CurrentYPhase = 11
.InstantaneousPFBPhase = 0
.InstantaneousPFYPhase = 1
.MeterApparentEnergy = 1.01
.MeterApparentUnit = ApparentEnergyUnit.KiloVoltAmpereHour
.MeterReactiveLagEnergy = 1.25
.MeterReactiveLagError = 1.25
.MeterReactiveLagUnit = ReactiveEnergyUnit.KiloVoltAmpereReactiveHour
.MeterReactiveLeadEnergy = 1.45
.MeterReactiveLeadError = 1.56
.MeterReactiveLeadUnit = ReactiveEnergyUnit.KiloVoltAmpereReactiveHour
.PercentageLoad = 1
.PTRatio = 1
.ReactiveCurrentBPhase = 10
.ReactiveCurrentYPhase = 11
.VoltageBPhase = 10
.VoltageYPhase = 10
End With
testData_List1.accuchek3TestParameters = accuchek3TestParameters1
testData.Add(testData_List1)
Can somebody please guide me?
Your first line is:
Dim testData As List(Of TestData) = Nothing
Then at the bottom you do
testData.Add(testData_List1)
I can't see anywhere in between where you do something like:
testData = New List(Of TestData)()
Though it's slightly hard to read since you've got both a variables and types with TestData as their name (or part of their name) so I might just be missing that.