inexplicable crash fixed by superfluous assignment
I was testing a tiny snippet I'd written to format a timespan (e.g., last change 5m23s ago
) and kept getting an error I couldn't understand. Every time I try to use the loop variable i
directly in a call to ts()
, ASP informed me An error occurred...
'the function
function ts(s)
dim m: m = CLng(s 60): s = s mod 60
dim h: h = CLng(m 60): m = m mod 60
ts = right("00" & h, 2) & "h" & _
right("00" & m, 2) & "m" & _
right("00" & s, 2) & "s"
end function
'the test
for i = 0 to 90000 step 15
' response.write i & ": " & ts(i) & "<br />" 'an error has occurred
dim j: j = i : response.write i & ": " & ts(j) & "<br />" 'works fine
next
What in the world is going on here?
Why does ts(i)
create an error every time?
Given that, why does j=i : ts(j)
work fine?
It can't be a problem with the variable i
, since it works fine with the write call. Here's some other things I tried:
response.write i & ": " 'no problem
'response.write ts(i) 'crashes
'dim x: x = ts(i) 'crashes
dim j: j = i 'no problem
dim x: x = ts(j) 'works
response.write x & "<br />" 'works
'response.write ts(j) & "<br />" 'also works
'response.write i & ": " & ts(j) & "<br />" 'also works
(Finally, I know there's allegedly a way to make IIS display real errors. I'd love to hear how to do that without RDP access to the webserver.)
vbscript asp-classic
add a comment |
I was testing a tiny snippet I'd written to format a timespan (e.g., last change 5m23s ago
) and kept getting an error I couldn't understand. Every time I try to use the loop variable i
directly in a call to ts()
, ASP informed me An error occurred...
'the function
function ts(s)
dim m: m = CLng(s 60): s = s mod 60
dim h: h = CLng(m 60): m = m mod 60
ts = right("00" & h, 2) & "h" & _
right("00" & m, 2) & "m" & _
right("00" & s, 2) & "s"
end function
'the test
for i = 0 to 90000 step 15
' response.write i & ": " & ts(i) & "<br />" 'an error has occurred
dim j: j = i : response.write i & ": " & ts(j) & "<br />" 'works fine
next
What in the world is going on here?
Why does ts(i)
create an error every time?
Given that, why does j=i : ts(j)
work fine?
It can't be a problem with the variable i
, since it works fine with the write call. Here's some other things I tried:
response.write i & ": " 'no problem
'response.write ts(i) 'crashes
'dim x: x = ts(i) 'crashes
dim j: j = i 'no problem
dim x: x = ts(j) 'works
response.write x & "<br />" 'works
'response.write ts(j) & "<br />" 'also works
'response.write i & ": " & ts(j) & "<br />" 'also works
(Finally, I know there's allegedly a way to make IIS display real errors. I'd love to hear how to do that without RDP access to the webserver.)
vbscript asp-classic
3
Try to changefunction ts(s)
tofunction ts(ByVal s)
– omegastripes
Jan 3 at 18:48
That worked. SO ANGRY.function ts(sec) : dim s: s = sec
also works.
– Einstein X. Mystery
Jan 3 at 19:15
add a comment |
I was testing a tiny snippet I'd written to format a timespan (e.g., last change 5m23s ago
) and kept getting an error I couldn't understand. Every time I try to use the loop variable i
directly in a call to ts()
, ASP informed me An error occurred...
'the function
function ts(s)
dim m: m = CLng(s 60): s = s mod 60
dim h: h = CLng(m 60): m = m mod 60
ts = right("00" & h, 2) & "h" & _
right("00" & m, 2) & "m" & _
right("00" & s, 2) & "s"
end function
'the test
for i = 0 to 90000 step 15
' response.write i & ": " & ts(i) & "<br />" 'an error has occurred
dim j: j = i : response.write i & ": " & ts(j) & "<br />" 'works fine
next
What in the world is going on here?
Why does ts(i)
create an error every time?
Given that, why does j=i : ts(j)
work fine?
It can't be a problem with the variable i
, since it works fine with the write call. Here's some other things I tried:
response.write i & ": " 'no problem
'response.write ts(i) 'crashes
'dim x: x = ts(i) 'crashes
dim j: j = i 'no problem
dim x: x = ts(j) 'works
response.write x & "<br />" 'works
'response.write ts(j) & "<br />" 'also works
'response.write i & ": " & ts(j) & "<br />" 'also works
(Finally, I know there's allegedly a way to make IIS display real errors. I'd love to hear how to do that without RDP access to the webserver.)
vbscript asp-classic
I was testing a tiny snippet I'd written to format a timespan (e.g., last change 5m23s ago
) and kept getting an error I couldn't understand. Every time I try to use the loop variable i
directly in a call to ts()
, ASP informed me An error occurred...
'the function
function ts(s)
dim m: m = CLng(s 60): s = s mod 60
dim h: h = CLng(m 60): m = m mod 60
ts = right("00" & h, 2) & "h" & _
right("00" & m, 2) & "m" & _
right("00" & s, 2) & "s"
end function
'the test
for i = 0 to 90000 step 15
' response.write i & ": " & ts(i) & "<br />" 'an error has occurred
dim j: j = i : response.write i & ": " & ts(j) & "<br />" 'works fine
next
What in the world is going on here?
Why does ts(i)
create an error every time?
Given that, why does j=i : ts(j)
work fine?
It can't be a problem with the variable i
, since it works fine with the write call. Here's some other things I tried:
response.write i & ": " 'no problem
'response.write ts(i) 'crashes
'dim x: x = ts(i) 'crashes
dim j: j = i 'no problem
dim x: x = ts(j) 'works
response.write x & "<br />" 'works
'response.write ts(j) & "<br />" 'also works
'response.write i & ": " & ts(j) & "<br />" 'also works
(Finally, I know there's allegedly a way to make IIS display real errors. I'd love to hear how to do that without RDP access to the webserver.)
vbscript asp-classic
vbscript asp-classic
asked Jan 3 at 18:22
Einstein X. MysteryEinstein X. Mystery
322313
322313
3
Try to changefunction ts(s)
tofunction ts(ByVal s)
– omegastripes
Jan 3 at 18:48
That worked. SO ANGRY.function ts(sec) : dim s: s = sec
also works.
– Einstein X. Mystery
Jan 3 at 19:15
add a comment |
3
Try to changefunction ts(s)
tofunction ts(ByVal s)
– omegastripes
Jan 3 at 18:48
That worked. SO ANGRY.function ts(sec) : dim s: s = sec
also works.
– Einstein X. Mystery
Jan 3 at 19:15
3
3
Try to change
function ts(s)
to function ts(ByVal s)
– omegastripes
Jan 3 at 18:48
Try to change
function ts(s)
to function ts(ByVal s)
– omegastripes
Jan 3 at 18:48
That worked. SO ANGRY.
function ts(sec) : dim s: s = sec
also works.– Einstein X. Mystery
Jan 3 at 19:15
That worked. SO ANGRY.
function ts(sec) : dim s: s = sec
also works.– Einstein X. Mystery
Jan 3 at 19:15
add a comment |
1 Answer
1
active
oldest
votes
omegastripes clued me in.
Apparently in VBScript, the default is for parameters to be passed ByRef
erence.
(Literally every other programming language I've ever used passes primitives ByVal
ue)
This caused a problem when I changed the value of s
inside the function.
Any of these snippets work just fine:
function ts(ByVal s)
...
...
ts(i)
function ts(sec)
dim s: s = sec
...
...
ts(i)
(or, as mentioned in the OP, passing the value in a non-loop-iterator variable)
function ts(s)
...
dim j: j = i: ts(j)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54027768%2finexplicable-crash-fixed-by-superfluous-assignment%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
omegastripes clued me in.
Apparently in VBScript, the default is for parameters to be passed ByRef
erence.
(Literally every other programming language I've ever used passes primitives ByVal
ue)
This caused a problem when I changed the value of s
inside the function.
Any of these snippets work just fine:
function ts(ByVal s)
...
...
ts(i)
function ts(sec)
dim s: s = sec
...
...
ts(i)
(or, as mentioned in the OP, passing the value in a non-loop-iterator variable)
function ts(s)
...
dim j: j = i: ts(j)
add a comment |
omegastripes clued me in.
Apparently in VBScript, the default is for parameters to be passed ByRef
erence.
(Literally every other programming language I've ever used passes primitives ByVal
ue)
This caused a problem when I changed the value of s
inside the function.
Any of these snippets work just fine:
function ts(ByVal s)
...
...
ts(i)
function ts(sec)
dim s: s = sec
...
...
ts(i)
(or, as mentioned in the OP, passing the value in a non-loop-iterator variable)
function ts(s)
...
dim j: j = i: ts(j)
add a comment |
omegastripes clued me in.
Apparently in VBScript, the default is for parameters to be passed ByRef
erence.
(Literally every other programming language I've ever used passes primitives ByVal
ue)
This caused a problem when I changed the value of s
inside the function.
Any of these snippets work just fine:
function ts(ByVal s)
...
...
ts(i)
function ts(sec)
dim s: s = sec
...
...
ts(i)
(or, as mentioned in the OP, passing the value in a non-loop-iterator variable)
function ts(s)
...
dim j: j = i: ts(j)
omegastripes clued me in.
Apparently in VBScript, the default is for parameters to be passed ByRef
erence.
(Literally every other programming language I've ever used passes primitives ByVal
ue)
This caused a problem when I changed the value of s
inside the function.
Any of these snippets work just fine:
function ts(ByVal s)
...
...
ts(i)
function ts(sec)
dim s: s = sec
...
...
ts(i)
(or, as mentioned in the OP, passing the value in a non-loop-iterator variable)
function ts(s)
...
dim j: j = i: ts(j)
answered Jan 3 at 20:08
Einstein X. MysteryEinstein X. Mystery
322313
322313
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54027768%2finexplicable-crash-fixed-by-superfluous-assignment%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
Try to change
function ts(s)
tofunction ts(ByVal s)
– omegastripes
Jan 3 at 18:48
That worked. SO ANGRY.
function ts(sec) : dim s: s = sec
also works.– Einstein X. Mystery
Jan 3 at 19:15