Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > microsoft.public.scripting.vbscript > #11205

Re: Weird bug

From "R. Roesler" <worm.composter@nospam.arcornews.de>
Newsgroups microsoft.public.scripting.vbscript
Subject Re: Weird bug
Date 2015-11-19 13:12 +0100
Organization No Such Agency
Message-ID <db6nhuFktk4U1@mid.individual.net> (permalink)
References <n2d78f$639$1@dont-email.me>

Show all headers | View raw


Mayayana <mayayana@invalid.nospam> typed:

>I just wasted hours before discovering this:
>
> x = -18
>
> x = x + 9: If x > 10 Then x = 10: If x < 0 Then x = 0
>
> MsgBox x
>
> '  Returns -9, but, this works:
>
> x = -18
>
> x = x + 9: If x < 0 Then x = 0
>
> MsgBox x
>
> Why? Is only one colon allowed? I've never noticed that
>
> problem before. It works fine in VB6.

That's really easy. The first expression does not work, because there is
no /End If/ or /ElseIf/. And I am very sceptical that this code works in
VB6. Try this one:
x = x + 9: If x > 10 Then x = 10: ElseIf x < 0 Then x = 0
                                  ^^^^
A blocked *If* statement must be the _first_ statement on a _line_. The
block *If* _must_ _end_ with an *End* *If* statement. How else the
interpreter should recognize on which position the *If* statement is
over? Scripting only works for Dummys 8-O and for frustrated ones.

And that is your given statement in blocked code:

x = -18
x = x + 9
If x > 10 Then
    x = 10
    If x < 0 Then
        x = 0
    End If
End If

That makes no sense. Do you see the benefit of structered code? It makes
the code easier to read and to understand and detecting of errors is
more simple.

-- 
ЯR

Back to microsoft.public.scripting.vbscript | Previous | NextPrevious in thread | Find similar


Thread

Weird bug "Mayayana" <mayayana@invalid.nospam> - 2015-11-16 13:28 -0500
  Re: Weird bug "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-11-16 19:50 +0100
  Re: Weird bug "Dave \"Crash\" Dummy" <invalid@invalid.invalid> - 2015-11-16 15:28 -0500
  Re: Weird bug "Mayayana" <mayayana@invalid.nospam> - 2015-11-16 16:13 -0500
    Re: Weird bug "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-11-16 22:57 +0100
      Re: Weird bug "Mayayana" <mayayana@invalid.nospam> - 2015-11-16 18:10 -0500
        Re: Weird bug "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-11-17 01:20 +0100
          Re: Weird bug "Mayayana" <mayayana@invalid.nospam> - 2015-11-16 21:11 -0500
  Re: Weird bug "R.Wieser" <address@not.available> - 2015-11-17 10:44 +0100
    Re: Weird bug "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-11-17 11:19 +0100
      Re: Weird bug "R.Wieser" <address@not.available> - 2015-11-17 11:31 +0100
    Re: Weird bug "Mayayana" <mayayana@invalid.nospam> - 2015-11-17 09:06 -0500
      Re: Weird bug "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-11-17 15:24 +0100
        Re: Weird bug "Mayayana" <mayayana@invalid.nospam> - 2015-11-17 10:35 -0500
          Re: Weird bug "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-11-17 16:45 +0100
      Re: Weird bug "R.Wieser" <address@not.available> - 2015-11-17 17:13 +0100
        inline "End If" bug, was Re: Weird bug "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-11-17 17:41 +0100
          Re: inline "End If" bug, was Re: Weird bug "R.Wieser" <address@not.available> - 2015-11-17 18:27 +0100
            Re: inline "End If" bug, was Re: Weird bug "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-11-17 19:37 +0100
              Edsger Wybe Dijkstra was: Re: inline "End If" bug, was Re: Weird bug "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-11-17 19:44 +0100
              Re: inline "End If" bug, was Re: Weird bug "R.Wieser" <address@not.available> - 2015-11-17 20:47 +0100
        Re: Weird bug "Mayayana" <mayayana@invalid.nospam> - 2015-11-17 12:01 -0500
          Re: Weird bug "R.Wieser" <address@not.available> - 2015-11-17 18:47 +0100
  Re: Weird bug "R. Roesler" <worm.composter@nospam.arcornews.de> - 2015-11-19 13:12 +0100

csiph-web