Home All Groups Group Topic Archive Search About

VB equivalent of this C# code

Author
16 Oct 2006 11:07 PM
Jon Paal
what is vb equiv. of

++

shown in C# ?

Author
17 Oct 2006 12:01 AM
David Anton
i ++ in VB is i += 1 or i = i + 1
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter


Show quoteHide quote
"Jon   Paal" wrote:

> what is vb equiv. of
>
> ++
>
>  shown in C# ?
>
>
>
Author
17 Oct 2006 2:19 AM
pvdg42
"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot com> wrote in message
news:efMxQfX8GHA.1252@TK2MSFTNGP04.phx.gbl...
> what is vb equiv. of
>
> ++
>
> shown in C# ?
David's answer is correct, but with the ++ (increment) and -- (decrement)
operators, you also need to be aware that the ++ and -- operators each come
in two versions, prefix and postfix,  that affect operation in complex
expressions.

int i = 5;
i++;  and
++i;  do exactly the same thing, add 1 to the current value in the variable
i.

i--; and
--i; also do exactly the same thing, subtract 1 from the current value in i.

So, prefix vs. postfix notation makes no difference in simple expressions.

In an expression like this, however,

Assume i == 5
if (i++ > 5) vs. if(++1 > 5).

there is a difference:
if(i++ > 5) evaluates the Boolean expression based on the *current* value in
i, then adds 1 to i.
The Boolean expression is false.

if(++1 > 5) *first* adds 1 to i, then evaluates the Boolean expression using
the new value in i.
The Boolean expression is true.

As you didn't show the context in which you encountered the ++ in C# code, I
though you should be aware of the difference between prefix and postfix
notation.
Author
17 Oct 2006 4:19 AM
David Anton
So when you take it all into consideration, there is no single statement
equivalent to statements containing ++ or --, since VB doesn't allow
assignments within expressions (there is a complex multi-statement equivalent
however).   There is only a single statement equivalent for simple "i++" or
"i--" statements.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter


Show quoteHide quote
"pvdg42" wrote:

>
> "Jon Paal" <Jon[ nospam ]Paal @ everywhere dot com> wrote in message
> news:efMxQfX8GHA.1252@TK2MSFTNGP04.phx.gbl...
> > what is vb equiv. of
> >
> > ++
> >
> > shown in C# ?
> David's answer is correct, but with the ++ (increment) and -- (decrement)
> operators, you also need to be aware that the ++ and -- operators each come
> in two versions, prefix and postfix,  that affect operation in complex
> expressions.
>
> int i = 5;
> i++;  and
> ++i;  do exactly the same thing, add 1 to the current value in the variable
> i.
>
> i--; and
> --i; also do exactly the same thing, subtract 1 from the current value in i.
>
> So, prefix vs. postfix notation makes no difference in simple expressions.
>
> In an expression like this, however,
>
> Assume i == 5
> if (i++ > 5) vs. if(++1 > 5).
>
> there is a difference:
> if(i++ > 5) evaluates the Boolean expression based on the *current* value in
> i, then adds 1 to i.
> The Boolean expression is false.
>
> if(++1 > 5) *first* adds 1 to i, then evaluates the Boolean expression using
> the new value in i.
> The Boolean expression is true.
>
> As you didn't show the context in which you encountered the ++ in C# code, I
> though you should be aware of the difference between prefix and postfix
> notation.
>
>
>
Author
19 Oct 2006 9:02 PM
Branco Medeiros
David Anton wrote:
> So when you take it all into consideration, there is no single statement
> equivalent to statements containing ++ or --, since VB doesn't allow
> assignments within expressions (there is a complex multi-statement equivalent
> however).   There is only a single statement equivalent for simple "i++" or
> "i--" statements.

Well, if you *really*, *really* want it, nothing but common sense
forbids you from having:

<air-code>
  Function PreInc(ByRef Value As Integer) As Integer
    Value +=1
    Return Value
  End Function

  Function PostInc(ByRef Value As Integer) As Integer
    Dim Result As Integer = Value
    Value +=1
    Return Result
  End Function

  Function PreDec(ByRef Value As Integer) As Integer
    Value -=1
    Return Value
  End Function

  Function PostDec(ByRef Value As Integer) As Integer
    Dim Result As Integer = Value
    Value -=1
    Return Result
  End Function
</air-code>

Regards,

Branco.
Author
19 Oct 2006 8:20 PM
Jon Paal
c#code :

if (failureCount++ >= MaxInvalidPasswordAttempts)  {...

source of c# is example here:

http://www.eggheadcafe.com/articles/20051119.asp
Author
17 Oct 2006 5:06 AM
Cor Ligthert [MVP]
Jon,

I know it only on one place and that is in a "for index".

step 1

Cor

Show quoteHide quote
"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot com> schreef in bericht
news:efMxQfX8GHA.1252@TK2MSFTNGP04.phx.gbl...
> what is vb equiv. of
>
> ++
>
> shown in C# ?
>