Discussion:
What is wrong with this syntax?
(too old to reply)
b***@gmail.com
2016-12-25 23:11:42 UTC
Permalink
Completely new to VBScript.
Doing a simple age calculation, but have some trouble getting the Else
If syntax right.

This is the block of code:

If (today_month < M) {
age--;
} else
F = parseInt(30.6001 * E);
DOM = (B - (D + F)) + (Q - Z); //day of the month
If (DOM > today_day) {
age--;
}

Any idea what is wrong here?
Note that the lines with F = and DOM = only need to run if today_month < M
is false.


RBS
Mayayana
2016-12-26 00:20:10 UTC
Permalink
<***@gmail.com> wrote

| Completely new to VBScript.
| Doing a simple age calculation, but have some trouble getting the Else
| If syntax right.
|
| This is the block of code:
|
| If (today_month < M) {
| age--;
| } else

It's nearly identical to VB6 except that it's
far more limited and doesn't have strong typing.
Everything is a variant. There are also a few
minor details, like there being no Mid statement,
only Mid function. You seem to be writing javascript.
Are you sure that's not what you meant to ask
about?
b***@gmail.com
2016-12-26 00:26:38 UTC
Permalink
All I am asking about is the If Else construction. There seems to be something wrong with the brackets or the locations of the Else and If, but can't figure it out.

RBS
Post by Mayayana
| Completely new to VBScript.
| Doing a simple age calculation, but have some trouble getting the Else
| If syntax right.
|
|
| If (today_month < M) {
| age--;
| } else
It's nearly identical to VB6 except that it's
far more limited and doesn't have strong typing.
Everything is a variant. There are also a few
minor details, like there being no Mid statement,
only Mid function. You seem to be writing javascript.
Are you sure that's not what you meant to ask
about?
b***@gmail.com
2016-12-26 00:50:07 UTC
Permalink
Yes, I meant completely new to JavaScript and this is indeed JavaScript.
Sorry I confused matters.

RBS
Post by Mayayana
| Completely new to VBScript.
| Doing a simple age calculation, but have some trouble getting the Else
| If syntax right.
|
|
| If (today_month < M) {
| age--;
| } else
It's nearly identical to VB6 except that it's
far more limited and doesn't have strong typing.
Everything is a variant. There are also a few
minor details, like there being no Mid statement,
only Mid function. You seem to be writing javascript.
Are you sure that's not what you meant to ask
about?
Mayayana
2016-12-26 03:16:45 UTC
Permalink
<***@gmail.com> wrote

| Yes, I meant completely new to JavaScript and this is indeed JavaScript.
| Sorry I confused matters.
|

And this is the VBScript group. :)
b***@gmail.com
2016-12-26 08:06:32 UTC
Permalink
Post by Mayayana
| Yes, I meant completely new to JavaScript and this is indeed JavaScript.
| Sorry I confused matters.
|
And this is the VBScript group. :)
Yes and posted to VBScript now.

RBS
R.Wieser
2016-12-26 08:28:34 UTC
Permalink
Bart,
Post by b***@gmail.com
Any idea what is wrong here?
Yes. :-)
Post by b***@gmail.com
Note that the lines with F = and DOM = only need to run if
today_month < M is false.
And lets guess, you've noticed that those lines *always* run.

The reason ? Because you made a mistake in your indentation. Or rather,
your indentation *hides* what is actually happening.

Also, why is that last closing curly baracket flush against the left side ?
If anything it should be on the same column as the "i" of the "if" where the
opening curly bracket is on.

And when you do that you will notice that your code *looks* to be
open-ended, which is a(nother) sign something is amiss with the indentation
....

What I mean ? Why is the line starting with "DOM =" indented ? And no,
its not part of the "else" (!). You did not follow the "else" by a
grouping symbol (the opening curly bracket), so it only has control over the
line directly behind/following it.

In other words: the "else" only switches the "F = parseInt(...)" line off
and on, nothing more. The lines starting with "DOM =" will *allways* be
executed. :-( :-)

Regards,
Rudy Wieser

P.s.
Your re-indented code should look like this:

If (today_month < M) {
age--;
} else
F = parseInt(30.6001 * E);
DOM = (B - (D + F)) + (Q - Z); file://day of the month
If (DOM > today_day) {
age--;
}

However, what you *wanted* is this :

If (today_month < M) {
age--;
} else {
F = parseInt(30.6001 * E);
DOM = (B - (D + F)) + (Q - Z); file://day of the month
If (DOM > today_day) {
age--;
}
}

Notice the added curly brackets !
Post by b***@gmail.com
Completely new to VBScript.
Doing a simple age calculation, but have some trouble getting the Else
If syntax right.
If (today_month < M) {
age--;
} else
F = parseInt(30.6001 * E);
DOM = (B - (D + F)) + (Q - Z); file://day of the month
If (DOM > today_day) {
age--;
}
Any idea what is wrong here?
Note that the lines with F = and DOM = only need to run if today_month < M
is false.
RBS
b***@gmail.com
2016-12-26 12:23:08 UTC
Permalink
Thanks for that. I am currently editing in a VB6 textbox and will see
if there is a free JavaScript editor to sort this out.

RBS
Post by R.Wieser
Bart,
Post by b***@gmail.com
Any idea what is wrong here?
Yes. :-)
Post by b***@gmail.com
Note that the lines with F = and DOM = only need to run if
today_month < M is false.
And lets guess, you've noticed that those lines *always* run.
The reason ? Because you made a mistake in your indentation. Or rather,
your indentation *hides* what is actually happening.
Also, why is that last closing curly baracket flush against the left side ?
If anything it should be on the same column as the "i" of the "if" where the
opening curly bracket is on.
And when you do that you will notice that your code *looks* to be
open-ended, which is a(nother) sign something is amiss with the indentation
....
What I mean ? Why is the line starting with "DOM =" indented ? And no,
its not part of the "else" (!). You did not follow the "else" by a
grouping symbol (the opening curly bracket), so it only has control over the
line directly behind/following it.
In other words: the "else" only switches the "F = parseInt(...)" line off
and on, nothing more. The lines starting with "DOM =" will *allways* be
executed. :-( :-)
Regards,
Rudy Wieser
P.s.
If (today_month < M) {
age--;
} else
F = parseInt(30.6001 * E);
DOM = (B - (D + F)) + (Q - Z); file://day of the month
If (DOM > today_day) {
age--;
}
If (today_month < M) {
age--;
} else {
F = parseInt(30.6001 * E);
DOM = (B - (D + F)) + (Q - Z); file://day of the month
If (DOM > today_day) {
age--;
}
}
Notice the added curly brackets !
Post by b***@gmail.com
Completely new to VBScript.
Doing a simple age calculation, but have some trouble getting the Else
If syntax right.
If (today_month < M) {
age--;
} else
F = parseInt(30.6001 * E);
DOM = (B - (D + F)) + (Q - Z); file://day of the month
If (DOM > today_day) {
age--;
}
Any idea what is wrong here?
Note that the lines with F = and DOM = only need to run if today_month < M
is false.
RBS
Dave "Crash" Dummy
2016-12-26 14:20:26 UTC
Permalink
Post by b***@gmail.com
Thanks for that. I am currently editing in a VB6 textbox and will see
if there is a free JavaScript editor to sort this out.
It's called "Notepad."
--
Crash

"When you get to a fork in the road, take it."
~ Yogi Berra ~
b***@gmail.com
2016-12-26 14:57:12 UTC
Permalink
Post by Dave "Crash" Dummy
Post by b***@gmail.com
Thanks for that. I am currently editing in a VB6 textbox and will see
if there is a free JavaScript editor to sort this out.
It's called "Notepad."
--
Crash
"When you get to a fork in the road, take it."
~ Yogi Berra ~
Did you mean Notepad ++ ?

RBS
R.Wieser
2016-12-26 15:21:43 UTC
Permalink
Bart,
Post by b***@gmail.com
Did you mean Notepad ++ ?
I don't think so. I get the feeling he doesn't like all that syntax
highlighting and "smart stuff" too much either. :-)

I think he ment "notepad" as the simplest flat text editor available on a
standard Windows installation.

Regards,
Rudy Wieser
Post by b***@gmail.com
Post by Dave "Crash" Dummy
Post by b***@gmail.com
Thanks for that. I am currently editing in a VB6 textbox and will see
if there is a free JavaScript editor to sort this out.
It's called "Notepad."
--
Crash
"When you get to a fork in the road, take it."
~ Yogi Berra ~
Did you mean Notepad ++ ?
RBS
Dave "Crash" Dummy
2016-12-26 19:48:05 UTC
Permalink
Post by R.Wieser
Bart,
Post by b***@gmail.com
Did you mean Notepad ++ ?
I don't think so. I get the feeling he doesn't like all that syntax
highlighting and "smart stuff" too much either. :-)
I think he ment "notepad" as the simplest flat text editor available
on a standard Windows installation.
Yup, although I actually use EditPad Lite. It is still a pure text
editor with no programming features.

Crash

"When you get to a fork in the road, take it."
~ Yogi Berra ~
Mayayana
2016-12-26 21:05:51 UTC
Permalink
"Dave "Crash" Dummy" <***@invalid.invalid> wrote

| Yup, although I actually use EditPad Lite. It is still a pure text
| editor with no programming features.

You actually prefer no color syntax highlighting
or "intellisense"? I got used to the VB6 editor and
then wrote my own for HTML, VBS, etc. It's *so*
much easier than Notepad. The colorcoding makes
it much more readable, once you're used to the
colors. Auto-correcting case and coloring of
variables prevents me from misspelling variables
because a variable name typed wrong is obvious
when I go to the next line.
Intellisense popup means I don't have to remember
object properties.

It's similar for HTML. The code becomes much
more clear when tags, comments, script blocks
and CSS are different colors.

I don't want to force you to use a shovel if you're
happy farming with a trowel. :) But if anyone here
wants a copy of my software you can have it for
free. I don't sell many copies anymore. There are
too many freebies. Just download, install and try
it. If you like it, write and ask me for the full version.
(And let me know who you are in the group. I'm
not giving it away to the public.)

http://www.jsware.net/jsware/webed.php5

There's also a javascript editor in the same program,
but it's not as polished as the VBS and HTML editors.
I find javascript ugly and tedious, so I've never learned
more than the basics. The javascript editor may sometimes
have some syntax highlighting errors with extremely
complex javascript, like the jquery stuff one sees in
webpages these days.
R.Wieser
2016-12-26 15:06:52 UTC
Permalink
Bart,
Post by b***@gmail.com
Thanks for that.
You're welcome.
Post by b***@gmail.com
I am currently editing in a VB6 textbox and will see if there is a
free JavaScript editor to sort this out.
Why ?

I mean, now you know how that "else" works and why those brackets exist (to
group a set of commands together -- nothing more, nothing less) you won't
easily make that same mistake again, and if you do you will likely be able
to recognise the mistake.

Besides, although most editors will attempt to help you with your
indentation (or at least indent to the same position as the previous line),
very few will stop you if you edit the file to what you posted.

Also, it would be very hard for an editor to help you out there: what you
posted there was *syntactically* fully correct code. That it didn't do
what you thought it would is not something an editor can help you with ...

In other words: learn the (syntax) rules of the (new?) game. If you don't
(and depend on an editor to catch you when you make a mistake) you will
stumble into problems like these more often than you think is funny.

Ofcourse, I'm prejudiced. I can't remember the last time I used one of
those syntax-aware editors. :-)

Regards,
Rudy Wieser
Post by b***@gmail.com
Thanks for that. I am currently editing in a VB6 textbox and will see
if there is a free JavaScript editor to sort this out.
RBS
Post by R.Wieser
Bart,
Post by b***@gmail.com
Any idea what is wrong here?
Yes. :-)
Post by b***@gmail.com
Note that the lines with F = and DOM = only need to run if
today_month < M is false.
And lets guess, you've noticed that those lines *always* run.
The reason ? Because you made a mistake in your indentation. Or rather,
your indentation *hides* what is actually happening.
Also, why is that last closing curly baracket flush against the left side ?
If anything it should be on the same column as the "i" of the "if" where the
opening curly bracket is on.
And when you do that you will notice that your code *looks* to be
open-ended, which is a(nother) sign something is amiss with the indentation
....
What I mean ? Why is the line starting with "DOM =" indented ? And no,
its not part of the "else" (!). You did not follow the "else" by a
grouping symbol (the opening curly bracket), so it only has control over the
line directly behind/following it.
In other words: the "else" only switches the "F = parseInt(...)" line off
and on, nothing more. The lines starting with "DOM =" will *allways* be
executed. :-( :-)
Regards,
Rudy Wieser
P.s.
If (today_month < M) {
age--;
} else
F = parseInt(30.6001 * E);
DOM = (B - (D + F)) + (Q - Z); file://day of the month
If (DOM > today_day) {
age--;
}
If (today_month < M) {
age--;
} else {
F = parseInt(30.6001 * E);
DOM = (B - (D + F)) + (Q - Z); file://day of the month
If (DOM > today_day) {
age--;
}
}
Notice the added curly brackets !
Post by b***@gmail.com
Completely new to VBScript.
Doing a simple age calculation, but have some trouble getting the Else
If syntax right.
If (today_month < M) {
age--;
} else
F = parseInt(30.6001 * E);
DOM = (B - (D + F)) + (Q - Z); file://day of the month
If (DOM > today_day) {
age--;
}
Any idea what is wrong here?
Note that the lines with F = and DOM = only need to run if today_month < M
is false.
RBS
Dr J R Stockton
2016-12-26 21:22:55 UTC
Permalink
In microsoft.public.scripting.vbscript message <10cf4ab2-f79d-4b01-a190-
Post by b***@gmail.com
Completely new to VBScript.
Doing a simple age calculation, but have some trouble getting the Else
If syntax right.
If (today_month < M) {
age--;
} else
F = parseInt(30.6001 * E);
DOM = (B - (D + F)) + (Q - Z); //day of the month
If (DOM > today_day) {
age--;
}
Any idea what is wrong here?
Note that the lines with F = and DOM = only need to run if today_month < M
is false.
Your code is incomplete and your algorithm uncertain.

It seems to me that, for any pair of Gregorian dates, the answer would
be unchanged if all months were extended to 100 days and all years were
extended to 100 months. So, for each date Y/M/D, form
(Y*100 + M)*100 + D
then subtract the two dates and div by 10000 and that should be rather
like the answer.

You must now wonder about what to do for each of the nine combinations
of Feb 29, Feb in leap year. Feb 28 in ordinary year. You may need to
consult relevant applicable law on that subject.

If your system cannot handle integers as big as, say, 21000000, then
extend less using factors of at least 31 & 12 or a bit more.
--
(c) John Stockton, Surrey, UK. ¬@merlyn.demon.co.uk Turnpike v6.05 MIME.
Merlyn Web Site < > - FAQish topics, acronyms, & links.
b***@gmail.com
2016-12-27 07:49:39 UTC
Permalink
Post by b***@gmail.com
Completely new to VBScript.
Doing a simple age calculation, but have some trouble getting the Else
If syntax right.
If (today_month < M) {
age--;
} else
F = parseInt(30.6001 * E);
DOM = (B - (D + F)) + (Q - Z); //day of the month
If (DOM > today_day) {
age--;
}
Any idea what is wrong here?
Note that the lines with F = and DOM = only need to run if today_month < M
is false.
RBS
Not using this anymore.
Now instead convert the Excel date to a Julian day like this:

var jDOB = new Date((lDOB - (25569)) * 86400000);

Then I do the logic further after getting the Year and Month with the JS functions .getFullYear() and .getMonth() and if needed getDate().
This all seems to work well.
Not dealt with dates yet before 1 Jan 1900.

RBS

Loading...