io.read() isn't working and makes my file immediately exit - error-handling

This works fine, but when I tried to make another one, it makes the lua file immediately exits
print("hai")
io.read()
local var = math.random()
print(math.sqrt(var))
if var >= 0 then
print(math.sqrt(3)
elseif var <= 0 then
print(var)
end
end
end
io.read()
I added second io.read() but the problem is still here. I changed from io.read() to os.execute "pause" but I still can't solve this problem

Related

while loop with try/catch error in Julia logic problem

I'm trying to write a while loop that tests whether an input is valid or not and it keeps asking if the user insists on the wrong input. If it is a valid one, the program just goes on. This is where i'm at.
while true
try
selected_row = readline()
selected_row = parse(Int8, selected_row)
break
catch e
if isa(e, LoadError)
#warn "type a valid number between [1,8]"
elseif isa(e, ArgumentError)
#warn "type a valid number between [1,8]"
end
end
end
println("you chose (C|R) ($selected_row)")
The problem is that when the input is correct I get an error.
LoadError: UndefVarError: selected_row not defined
The while loop creates a new scope. Now the way to fix the issue depends on where you put your code.
If it is inside e.g. a function then use:
local selected_row
before the loop (inside the function body) and things will work.
If your code is in top-level scope write:
global selected_row = parse(Int8, readline())
in your code which will guarantee that a global variable selected_row will be created.
Having said that I would recommend to write your code as follows:
function get_int8()
while true
selected_row = tryparse(Int8, readline())
isnothing(selected_row) || return selected_row
end
end
selected_row = get_int8()

roblox lua script not activating

so i have this code
local player = game.Players.LocalPlayer
local unitFrame = script.Parent
local buttona = unitFrame.buttonA
local sprinting = true
unitFrame.Title.Text = "Perks"
local function onButtonAClick()
unitFrame.Title.Text = "perks"
end
local function sprintButton()
if sprinting == false then
sprinting = true
player.Character.Humanoid.WalkSpeed = 20
unitFrame.buttonA.Text = "strinting"
end
if sprinting == true then
sprinting = false
player.Character.Humanoid.WalkSpeed = 16
unitFrame.buttonA.Text = "walking"
end
end
buttona.MouseButton1Click:connect(sprintButton)
what i am trying to do is make a sprinting toggle program. The only problem is that it will work once then not work at all. i can click it and it changes the text then when i click it again it does nothing. i want it to be able to work every time you press it.
In the function you test 2 if statements. If sprinting is false, and if it it is true.
The key to understanding your problem is that your if statements counteract eachother.
Let's walk through this, first it detects if it's false. No, sprinting is not false. Then if checks if it's true. It is! So it sets it to false.
Great so far, right? Well here's your problem. When you try it again, sprinting is false. So the first if statement is run, and it sets it to true. But then, ANOTHER if statement is run immediately after. Since it's now true, this runs, setting it to false. It appears nothing happened.
Your solution? Take out the end to the first if statement, and replace the second if to an elseif. This way once one statement evaluated to true, it won't evaluate the next.
Your logic is not correct. As warspyking said, you have an issue with your conditionals. Fix this by adding an elseif statement instead.
local function sprintButton()
if not sprinting then
sprinting = true
player.Character.Humanoid.WalkSpeed = 20
unitFrame.buttonA.Text = "sprinting"
elseif sprinting then
sprinting = false
player.Character.Humanoid.WalkSpeed = 16
unitFrame.buttonA.Text = "walking"
end
end

Why won't my code Loop?

Sorry for the messy code :S
If CheckBox2.Checked = True Then
For i As Integer = 0 To 1 Step 0
If CheckBox1.Checked = True Then
If TextBox1.Text = lblCLickLImit.Text Then
Timer1.Stop()
TextBox1.Text = "0"
System.Windows.Forms.SendKeys.Send("{F5}")
System.Threading.Thread.Sleep(delaydelaytime)
System.Windows.Forms.SendKeys.Send("{ENTER}")
Else
If CheckBox1.Checked = False Then
If TextBox1.Text = lblCLickLImit.Text Then
Timer1.Stop()
TextBox1.Text = "0"
End If
End If
End If
Else
If CheckBox2.Checked = False Then
If CheckBox1.Checked Then
If TextBox1.Text = lblCLickLImit.Text Then
Timer1.Stop()
TextBox1.Text = "0"
System.Windows.Forms.SendKeys.Send("{F5}")
System.Threading.Thread.Sleep(delaydelaytime)
System.Windows.Forms.SendKeys.Send("{ENTER}")
End If
Else
If CheckBox1.Checked = False Then
If TextBox1.Text = lblCLickLImit.Text Then
Timer1.Stop()
TextBox1.Text = "0"
End If
End If
End If
End If
End If
Next
Basically this code is for an Auto Clicker program,(Hopefully this will help you understand, http://prntscr.com/7tuc3o interface) Ok so when the "Continuous" checkbox is selected the code is in theory supposed to loop for infinity. However when I run the program with everything selected as shown all that happens is the program clicks once and then crashes (not responding). Any help I have tried this loop in other programs and it works, just not with this code.
Your loop is tying up the UI thread. You'll need to look into using either a background worker:
BackgroundWorker handles long-running tasks. It does not freeze the entire program as this task executes.
(dotnetperls.com)
Here is the msdn walkthrough of how to set-up a backgroundworker:
https://msdn.microsoft.com/en-us/library/ywkkz4s1.aspx
Or
If this is a personal project and no one you love will need to maintain this code, you can use Application.DoEvents() to continue to pump messages while the program is looping. Here is the msdn documentation for that https://msdn.microsoft.com/en-us/library/system.windows.forms.application.doevents(v=vs.110).aspx
First of all, a Step of 0 doesn't really make any sense in a for loop. It may /work/ but it is going to drive anyone reading it later insane. If you want an infinite loop don't use a for loop, use:
While True
'code here
End While
For loops are used when you know exactly how many iterations of your loop you need. A while loop is designed to iterate as long as some condition is true. In this example the condition is always true so it loops indefinitely.
Your code is also just going to spin the UI thread constantly. It never pauses for input (even your sleep calls do not release the thread for input). As far as the OS knows, your app has locked up because it never processes any of the window messages that get posted to it. It is still happily spinning away though, until windows finally gets tired of it and prompts you to kill it.
Not sure what other "programs" you're working with but I can tell you you don't want to use a For loop for this. You want a do/while loop, like either:
While True
...
End While
or
Do
...
Loop While True

Running Line of code twice causes activeX error 0x8000ffff

Following code causes an ActiveX error 0x8000ffff if executed twice.
It all boils down to this two lines, as the rest of the code runs smoothly.
In particular, if I run the line of code only once, it works great. If I run the line of code twice I get the error. Note that the line is only reading the variable, so I do not understand why it would not be readable the second time. If s_Var changes, then it works, essentially i can read every column once.
This works:
obj_Dlr = GetDataLoggerRecipe(s_Dlr)
If Not s_Var = "" Then
Debug.Print obj_Dlr.GetColumn(s_Var).Name
End If
This not:
obj_Dlr = GetDataLoggerRecipe(s_Dlr)
If Not s_Var = "" Then
Debug.Print obj_Dlr.GetColumn(s_Var).Name
Debug.Print obj_Dlr.GetColumn(s_Var).Name
End If
Also reassigning the variable does not work..
obj_Dlr = GetDataLoggerRecipe(s_Dlr)
If Not s_Var = "" Then
Debug.Print obj_Dlr.GetColumn(s_Var).Name
End If
obj_Dlr = GetDataLoggerRecipe(s_Dlr)
If Not s_Var = "" Then
Debug.Print obj_Dlr.GetColumn(s_Var).Name
End If
I'm interested in understanding what is going on, as it helps me to solve anotehr problem.
Thanks

How do I get a variable to work within double quotes in ASP-classic?

The following code is part of a function that is being called for each file the program finds during it's search through a directory.
set searchname = objFSO.OpenTextFile(server.mappath(filename),1, true)
do until searchname.AtEndOfStream
lineData = lcase(searchname.ReadLine())
if instr(lineData,s)>0 then
instances = instances + 1
end if
Loop
This the part of my code I'm confused with. This code worked perfectly yesterday. I made a few edits but mostly with HTML and CSS. When I pulled this code out today to optimize it better, I just keep getting a permission denied error with this line.
set searchname = objFSO.OpenTextFile(server.mappath(filename),1, true)
The problem is that the folder the code scans through contains some files that have more than one word. So it's essential that I get the "filename" variable within double quotes. I've been looking everywhere for a solution and none of them have been helpful yet. Is this even possible or is there a workaround?
Any help would be much appreciated here.
EDIT: As requested here's the code that gets the filename. Although no idea how it pertains to my question.
Function filesearch(name)
ext = instr(name,".txt")
vdirectoryvalue = instr(name,"Files\")+6
idname = mid(name,vdirectoryvalue,ext)
vdirectory = len(idname) - 4
filename = left(idname,vdirectory)
instances = 0
set searchname = objFSO.OpenTextFile(server.mappath(idname), 1, true)
do until searchname.AtEndOfStream
lineData = lcase(searchname.ReadLine())
if instr(lineData,s)>0 then
instances = instances + 1
end if
Loop
End Function