I am trying to write a triple nested for loop and I get the error message "For Control Variable already in use". I have dimmed and set all the my variables, but it is my first time using a triple nested loop and I can't understand why there is an error. Below my code:
Dim LastrowProv As Integer
Dim LastRowAdv As Integer
LastrowProv = Worksheets("Provisions").Cells(1, 1).End(xlDown).Row
LastRowAdv = Worksheets("Advances").Cells(1, 1).End(xlDown).Row
LastRowCPMatch = Worksheets("Exclusions").Cells(1, CPMatch).End(xlDown).Row
For z = LastRowCPMatch To 1 Step -1
For x = LastrowProv To 2 Step -1
For i = LastRowAdv To 2 Step -1
If Worksheets("Advances").Cells(i, CPNameAdv) = Worksheets("Exclusions").Cells(z, CPMatch) _
And Worksheets("Provisions").Cells(x, CPNameProv) = Worksheets("Exclusions").Cells(z, CPMatch) _
And Worksheets("Advances").Cells(i, IntEntAdv) = Worksheets("Provisions").Cells(x, IntEntProv) _
And Worksheets("Advances").Cells(i, TExpAdv) > -Worksheets("Provisions").Cells(x, TExpProv) Then
Worksheets("Advances").Cells(i, TExpAdv) = Worksheets("Advances").Cells(i, TExpAdv) + Worksheets("Provisions").Cells(x, TExpProv)
Worksheets("Advances").Cells(i, UnsExpAdv) = Worksheets("Advances").Cells(i, UnsExpAdv).Value + Worksheets("Provisions").Cells(x, UnsExpProv).Value
Worksheets("Provisions").Rows(x).EntireRow.Delete
Exit For
End If
Next i
Next x
Next z
Thank you for the help!
Related
I wanted to report some debug information for a parser I am writing in lua. I am using the debug hook facility for tracking but it seems like there is some form of race condition happening.
Here is my test code:
enters = 0
enters2 = 0
calls = 0
tailcalls = 0
returns = 0
lines = 0
other = 0
exits = 0
local function analyze(arg)
enters = enters + 1
enters2 = enters2 + 1
if arg == "call" then
calls = calls + 1
elseif arg == "tail call" then
tailcalls = tailcalls + 1
elseif arg == "return" then
returns = returns + 1
elseif arg == "line" then
lines = lines + 1
else
other = other + 1
end
exits = exits + 1
end
debug.sethook(analyze, "crl")
-- main code
print("enters = ", enters)
print("enters2 = ", enters2)
print("calls = ", calls)
print("tailcalls = ", tailcalls)
print("returns = ", returns)
print("lines = ", lines)
print("other = ", other)
print("exits = ", exits)
print("sum = ", calls + tailcalls + returns + lines + other)
and here is the result:
enters = 429988
enters2 = 429991
calls = 97433
tailcalls = 7199
returns = 97436
lines = 227931
other = 0
exits = 430009
sum = 430012
Why does none of this add up? I am running lua 5.4.2 on Ubuntu 20.04, no custom c libraries, no further messing with the debug library.
I found the problem...
The calls to the print function when printing the result also trigger the hook, which only affects the results that have not been printed yet.
I have no clue what is wrong with this code, it is literally saying that a for loop that is perfectly fine, is attempting to get a vector3 value.
local locations = {}
local Players = game:GetService("Players")
local function SplitString(String)
local CurrentString = ""
local x = 1
for i = 1, #String do
local FullString = string.sub(String,1,i)
local Character = string.sub(String,i,i)
local CurrentString = string.sub(String, x, i)
print(locations[1])
if Character == "," then
CurrentString = string.sub(String,x,i-1)
table.insert(locations,CurrentString)
x = i + 1
CurrentString = string.sub(String, x , i)
print(locations)
end
--Add the character to the string.
if Character == " " then
x = i + 1
CurrentString = string.sub(String, x, i + 1)
end
if #FullString + 1 == #String then
table.insert(locations, CurrentString)
end
end
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local humanoidrootpart = char:WaitForChild("HumanoidRootPart")
wait(5)
while humanoidrootpart do
local location = humanoidrootpart.position
print(location)
SplitString(location)
print(locations[1])
local RoundLocatX = math.floor(locations[1]*50)/50
local RoundLocatZ = math.floor(locations[3]*50)/50
local RoundLocatXLength = RoundLocatX.length
local RoundLocatZLength = RoundLocatZ.length
if RoundLocatX > 50 then
print('hi')
end
wait(1)
end
end)
end)
This is the error:
ServerScriptService.Terrain Generation:9: attempt to get length of a Vector3 value
I would post this on the roblox forum but they are stupid and require some dumb amount of reading time to be able to post on it.
Your error is pointing at this line :
for i = 1, #String do
and saying that you are trying to get the length of a Vector3 object. That means that #String is not working as expected. So looking at the object you passed into the SplitString function...
local location = humanoidrootpart.position
print(location)
SplitString(location)
Your location variable is a Vector3, not a string, and it doesn't support the length operator, #.
But you don't have to parse it as a string to get the values out of it. Since it is a Vector3, you can simply index the different values in it.
local location = humanoidrootpart.Position
local RoundLocatX = math.floor(location.X * 50) / 50
local RoundLocatZ = math.floor(location.Z * 50) / 50
I have started reverse engineering and using visual basic decompiler, I got this, although it's basic, only thing I don't understand ( is this piece of code ) :
loc_00405255: On Error Resume Next
loc_00405262: -1 = Time$
loc_0040526D: var_30 = On Error Resume Next
loc_00405273: edi = Date$
loc_0040527E: var_34 = var_30
Is what would var_30 contain ?
EDIT 2 :
Cause I from the docs here, I don't see On Error Resume Next doesn't return anything .
Below is the part of the whole section of code :
Dim var_140 As Variant
loc_00405255: On Error Resume Next
loc_00405262: -1 = Time$
loc_0040526D: var_30 = On Error Resume Next
loc_00405273: edi = Date$
loc_0040527E: var_34 = var_30
loc_004052B7: var_24 = Text2.Text
loc_004052BF: var_144 = var_24
loc_00405301: var_168 = var_24
loc_00405314: var_C4 = var_168
loc_00405357: var_28 = Text1.Text
loc_0040535F: var_14C = var_28
loc_004053A8: Asc(var_28) = Asc(var_28) + 0001h
loc_004053C3: var_16C = var_30
loc_004053D6: var_54 = var_16C
loc_0040540B: var_2C = var_34
loc_00405418: var_84 = Right$(var_2C, 2)
loc_00405428: var_E4 = "Grand-Theft-Auto-Vice-City"
loc_0040543C: var_F4 = "bbidhan-ThE-Great"
loc_004054AF: var_150 = (var_168 = Chr(Asc(var_28)) & Right(var_16C, 2) & Right$(var_2C, 2) & "Grand-Theft-Auto-Vice-City" & "bbidhan-ThE-Great")
loc_0040552B: If var_150 = 0 Then GoTo loc_004057C2
loc_00405588: var_38 = Global.App
loc_0040558D: var_144 = var_38
loc_004055E5: var_24 = Global.Path
loc_004055EA: var_14C = var_24
EDIT 1 :
Q2. Right(var_16C, 2) & Right$(var_2C, 2)
Difference between the above two, with the $ sign ?
On Error is a statement, not an expression. Saying some_variable = On Error is a syntax error.
It appears that your decompiler is attempting to use that syntax to communicate something, but whatever it's trying to communicate isn't something expressible in VB6, and certainly not something I intuitively understand from looking at it either. It may be trying to tell you about some internal bookkeeping used to keep track of error information, or it may just be a bug in the decompiler you're using. It's not a meaningful expression.
Upon trying to run my code I get the error "compile error: variable not defined" and it highlights my Sub line. Here is the code for reference.
Sub RI_Processing()
Dim i As Single
Dim Output() As Single 'Define this dynamic array for the solver output
Process the DMSO data
For i = 1 To 45 Step 1
Workbooks("Calibration Range 1 Normalized Profiles.xlsx").Activate
RawData.Range("C10:C649") = Sheet1.Columns("i").Values
SolverOk SetCell:="$E$7", MaxMinVal:=2, ValueOf:=0, ByChange:="$B$2:$B$4", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve
Workbooks("Simulated Fresnel Function.xlsx").Activate
Output(i, 1) = Sheet1.Range("B4").Values
Next i
i = 0
' Process the NaCl Data
For i = 1 To 102 Step 1
Workbooks("Calibration Range 1 Normalized Profiles.xlsx").Activate
RawData.Range("C10:C649") = Sheet2.Columns("i").Values
SolverOk SetCell:="$E$7", MaxMinVal:=2, ValueOf:=0, ByChange:="$B$2:$B$4", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve
Workbooks("Simulated Fresnel Function.xlsx").Activate
Output(i, 2) = Sheet1.Range("B4").Values
Next i
i = 0
' Process the Sucrose data
For i = 1 To 72 Step 1
Workbooks("Calibration Range 1 Normalized Profiles.xlsx").Activate
RawData.Range("C10:C649") = Sheet3.Columns("i").Values 'Copies the data of all 'i' columns to raw data for solver
SolverOk SetCell:="$E$7", MaxMinVal:=2, ValueOf:=0, ByChange:="$B$2:$B$4", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve 'Run solver
Workbooks("Simulated Fresnel Function.xlsx").Activate
Output(i, 3) = Sheet1.Range("B4").Values 'Put solver output to the matrix 'output' in the appropriate columns
Next i
End Sub
Why does the following work in VBScript (classic ASP)
Dim y: y = rs("file_description")
Dim x: x = (instr(y, "Internal Server Error") <> 0 or instr(y, "Server Unavailable") <> 0) AND instr(y, "RetryCount=9") = 0
But this does not work. It halts execution (without an error number or description!)
dim x: x = (instr(rs("file_description"), "Internal Server Error") <> 0 or instr(rs("file_description"), "Server Unavailable") <> 0) AND instr(rs("file_description"), "RetryCount=9") = 0
Seems strange that simply extracting the rs("file_description") expression into a variable causes the code to work.
I don't understand why.
rs("file_description") can mean the field object or its default property .Value. VBScript picks one or another depending on the context. Because
y = rs("file_description")
does not use Set, y will contain the .Value. To make things clear for the second aproach, use
x = (instr(rs("file_description").Value, ...