test question for the vb suck-ups out there 
Author Message
 test question for the vb suck-ups out there

Try translating this c++ into VB:

  // loop to print even integers between 1 and 20
  int n = 0;
  while(n++ < 20)
  {
    if(n % 2)
      continue;

    cout << n << endl;
  }

Be careful now . . . trick question.



Mon, 06 Oct 2003 10:52:04 GMT  
 test question for the vb suck-ups out there
#include <iostream.h>
  // loop to print even integers between 1 and 20
  int n = 0;
  int main(void)
  {
  while(n++ < 20)
  {
  if(n % 2)
  continue;

    cout << n << endl;
  }
'And in VB
Private Sub Command1_Click()
'print even integers between 1 and 20
    Dim n As Integer
    n = 1
    Do While n < 21
        If n Mod 2 = 0 Then
            Print n
        End If
        n = n + 1
    Loop

End Sub

Have I fallen for the trick?


Quote:
> Try translating this c++ into VB:

>   // loop to print even integers between 1 and 20
>   int n = 0;
>   while(n++ < 20)
>   {
>     if(n % 2)
>       continue;

>     cout << n << endl;
>   }

> Be careful now . . . trick question.



Mon, 06 Oct 2003 13:07:19 GMT  
 test question for the vb suck-ups out there
Or . . .

Dim n As Integer
  n = 1
  Do While n <= 20
    If n Mod 2 Then
      GoTo vbsucks
    End If
    Debug.Print n
vbsucks:
    n = n + 1
  Loop

Well, i dont see why yours doesnt work; so i guess i tricked meself.


Quote:
> #include <iostream.h>
>   // loop to print even integers between 1 and 20
>   int n = 0;
>   int main(void)
>   {
>   while(n++ < 20)
>   {
>   if(n % 2)
>   continue;

>     cout << n << endl;
>   }
> 'And in VB
> Private Sub Command1_Click()
> 'print even integers between 1 and 20
>     Dim n As Integer
>     n = 1
>     Do While n < 21
>         If n Mod 2 = 0 Then
>             Print n
>         End If
>         n = n + 1
>     Loop

> End Sub

> Have I fallen for the trick?



> > Try translating this c++ into VB:

> >   // loop to print even integers between 1 and 20
> >   int n = 0;
> >   while(n++ < 20)
> >   {
> >     if(n % 2)
> >       continue;

> >     cout << n << endl;
> >   }

> > Be careful now . . . trick question.



Mon, 06 Oct 2003 13:15:02 GMT  
 test question for the vb suck-ups out there
Try translating this VB into C++:

    ' loop to test theparrot's mad kung-foo skillz
    Do While True = False
        MsgBox "As if you put the brace underneath the while!!!  " & _
        "You suck!  Click OK to acknowledge this."
    Loop

Be careful now . . . only run this if you are TheDoDo.


Quote:
> Try translating this c++ into VB:

>   // loop to print even integers between 1 and 20
>   int n = 0;
>   while(n++ < 20)
>   {
>     if(n % 2)
>       continue;

>     cout << n << endl;
>   }

> Be careful now . . . trick question.



Mon, 06 Oct 2003 13:39:54 GMT  
 test question for the vb suck-ups out there

Quote:
> Try translating this c++ into VB:

>   // loop to print even integers between 1 and 20
>   int n = 0;
>   while(n++ < 20)
>   {
>     if(n % 2)
>       continue;

>     cout << n << endl;
>   }

> Be careful now . . . trick question.

The following actually compiles:

#include <iostream>

using namespace std;

// loop to print even integers between 1 and 20
int main() {

        int n = 0;

        while (n++ < 20) {

                if (n % 2) continue;

                cout << n << endl;

        }

        return 0;

Quote:
}

Jason


Mon, 06 Oct 2003 13:45:53 GMT  
 test question for the vb suck-ups out there


Quote:
>        MsgBox "As if you put the brace underneath the while!!!  " & _

Ummmmm.. that's where i would put it. :)  

Regards, Frank.



Mon, 06 Oct 2003 15:27:13 GMT  
 test question for the vb suck-ups out there
On Thu, 19 Apr 2001 05:15:02 GMT, "TheDoDo"

It's not bad.. how about this ?

while(n++ < 20)
        puts( n % 2 ? "Bad craftsmen blame tools":"");

And for those who actually understand VB.. .
   Do While (n < 21)
         Debug.Print IIf(n Mod 2, "Bad craftsmen blame tools" &
vbCrLf, "")
         n = n + 1
   Loop

Quote:
>Or . . .

>Dim n As Integer
>  n = 1
>  Do While n <= 20
>    If n Mod 2 Then
>      GoTo vbsucks
>    End If
>    Debug.Print n
>vbsucks:
>    n = n + 1
>  Loop

>Well, i dont see why yours doesnt work; so i guess i tricked meself.



>> #include <iostream.h>
>>   // loop to print even integers between 1 and 20
>>   int n = 0;
>>   int main(void)
>>   {
>>   while(n++ < 20)
>>   {
>>   if(n % 2)
>>   continue;

>>     cout << n << endl;
>>   }
>> 'And in VB
>> Private Sub Command1_Click()
>> 'print even integers between 1 and 20
>>     Dim n As Integer
>>     n = 1
>>     Do While n < 21
>>         If n Mod 2 = 0 Then
>>             Print n
>>         End If
>>         n = n + 1
>>     Loop

>> End Sub

>> Have I fallen for the trick?



>> > Try translating this c++ into VB:

>> >   // loop to print even integers between 1 and 20
>> >   int n = 0;
>> >   while(n++ < 20)
>> >   {
>> >     if(n % 2)
>> >       continue;

>> >     cout << n << endl;
>> >   }

>> > Be careful now . . . trick question.

Regards, Frank.


Mon, 06 Oct 2003 15:56:08 GMT  
 test question for the vb suck-ups out there

| The following actually compiles:
|
| #include <iostream>
|
| using namespace std;
|
| // loop to print even integers between 1 and 20
| int main() {
|
| int n = 0;
|
| while (n++ < 20) {
|
| if (n % 2) continue;
|
| cout << n << endl;
|
| }
|
| return 0;
| }
|
| Jason

LOL, Here's an alternative...

# include <iostream>
using namespace::std;

int main( )
 {
  for(int i = 2; i <= 20; i += 2)
      cout<< i << endl;
  return 0;
 }

Chris Val



Mon, 06 Oct 2003 20:10:26 GMT  
 test question for the vb suck-ups out there

Quote:

>Have I fallen for the trick?

You seem to have worked your way around it.

I think the pitfall intended is that C++ *immediately* increments the
variable, before doing anything in the loop body, while in the VB code,
it's (commonly) done at the end:

Quote:
>  while(n++ < 20)
>  {
...
>  }
>'And in VB
>    Dim n As Integer
>    n = 1
>    Do While n < 21
...
>        n = n + 1
>    Loop

This is not the same. This is:

    Dim n As Integer
    n = 0
    Do While n < 20
        n = n + 1
        ...
    Loop

--
        Bart.



Mon, 06 Oct 2003 21:17:57 GMT  
 test question for the vb suck-ups out there
What about if we construct an equivalent to the ++ operator. Consider this
function

Function PP(Arg1 As Variant, Arg2 As Variant, _
            Optional Increment As Long = 1) As Variant
  Dim ErrorCondition As Long
  If Increment < 0 Then
    ErrorCondition = 380 'Invalid property value -- must be positive
  ElseIf Arg1 = "++" Then 'Prefix
    If VarType(Arg2) > 3 Then
      ErrorCondition = 13 'Type mismatch - not Integer or Long
    Else
      Arg2 = Arg2 + Increment
      PP = Arg2
    End If
  ElseIf Arg2 = "++" Then 'Postfix
    If VarType(Arg1) > 3 Then
      ErrorCondition = 13 'Type mismatch - not Integer or Long
    Else
      PP = Arg1
      Arg1 = Arg1 + Increment
    End If
  Else
    ErrorCondition = 93 'Invalid Pattern String -- no "++" specified
  End If
  If ErrorCondition Then Err.Raise ErrorCondition
End Function

where PP is meant to stand for the ++ (plus plus) operator. The
prefix/postfix operation is controlled by placing the string "++" either in
the first or second argument (and your Integer or Long variable in the other
of those two arguments). If the first argument is set as "++", then a prefix
operation is performed. If the second argument is set as "++", then a
postfix operation is performed.

So, the loop

     while(n++ < 20)
       {
          .....
       }

would become

     Do While PP(n, "++") < 20
       ...
     Loop

To duplicate this loop instead

     while(++n < 20)
      {
         .....
      }

you would use

     Do While PP("++", n) < 20
        ...
     Loop

Of course this is not as compact as the C/C++ notation, but it is fully
equivalent in function. You may use it in any calcution, not just in loop
control tests.

Oh, and one final note. The optional third argument allows you to set an
increment value other than 1. So if you wanted to use a number in a
calculation and then increment it by say 5 afterwards. Then after executing
this postfix operation

     SomeValue = 3
     NewValue = PP(SomeValue, "++", 5)

NewValue is assigned 3 and SomeValue becomes 8 after the last statement.
This is equivalent to

     SomeValue = 3
     NewValue = SomeValue
     SomeValue = SomeValue + 5

Rick


Quote:

> >Have I fallen for the trick?

> You seem to have worked your way around it.

> I think the pitfall intended is that C++ *immediately* increments the
> variable, before doing anything in the loop body, while in the VB code,
> it's (commonly) done at the end:

> >  while(n++ < 20)
> >  {
> ...
> >  }

> >'And in VB
> >    Dim n As Integer
> >    n = 1
> >    Do While n < 21
> ...
> >        n = n + 1
> >    Loop

> This is not the same. This is:

>     Dim n As Integer
>     n = 0
>     Do While n < 20
> n = n + 1
>         ...
>     Loop

> --
> Bart.



Mon, 06 Oct 2003 23:09:43 GMT  
 test question for the vb suck-ups out there
Actually, that last example in the "one final note" section might have been
more instructive if I used the result from PP, something like this:

     SomeValue = 3
     NewValue = 10 * PP(SomeValue, "++", 5)

NewValue is assigned 30 and SomeValue becomes 8 after the last statement.
This is equivalent to

     SomeValue = 3
     NewValue = 10 * SomeValue
     SomeValue = SomeValue + 5

And, of course, this

     SomeValue = 3
     NewValue = 10 * PP("++", SomeValue, 5)

sets NewValue to 80 (the SomeValue variable is incremented *before* it is
used) and SomeValue to 8. This is  equivalent to

     SomeValue = 3
     SomeValue = SomeValue + 5
     NewValue = 10 * SomeValue

Rick


Quote:
> What about if we construct an equivalent to the ++ operator. Consider this
> function

> Function PP(Arg1 As Variant, Arg2 As Variant, _
>             Optional Increment As Long = 1) As Variant
>   Dim ErrorCondition As Long
>   If Increment < 0 Then
>     ErrorCondition = 380 'Invalid property value -- must be positive
>   ElseIf Arg1 = "++" Then 'Prefix
>     If VarType(Arg2) > 3 Then
>       ErrorCondition = 13 'Type mismatch - not Integer or Long
>     Else
>       Arg2 = Arg2 + Increment
>       PP = Arg2
>     End If
>   ElseIf Arg2 = "++" Then 'Postfix
>     If VarType(Arg1) > 3 Then
>       ErrorCondition = 13 'Type mismatch - not Integer or Long
>     Else
>       PP = Arg1
>       Arg1 = Arg1 + Increment
>     End If
>   Else
>     ErrorCondition = 93 'Invalid Pattern String -- no "++" specified
>   End If
>   If ErrorCondition Then Err.Raise ErrorCondition
> End Function

> where PP is meant to stand for the ++ (plus plus) operator. The
> prefix/postfix operation is controlled by placing the string "++" either
in
> the first or second argument (and your Integer or Long variable in the
other
> of those two arguments). If the first argument is set as "++", then a
prefix
> operation is performed. If the second argument is set as "++", then a
> postfix operation is performed.

> So, the loop

>      while(n++ < 20)
>        {
>           .....
>        }

> would become

>      Do While PP(n, "++") < 20
>        ...
>      Loop

> To duplicate this loop instead

>      while(++n < 20)
>       {
>          .....
>       }

> you would use

>      Do While PP("++", n) < 20
>         ...
>      Loop

> Of course this is not as compact as the C/C++ notation, but it is fully
> equivalent in function. You may use it in any calcution, not just in loop
> control tests.

> Oh, and one final note. The optional third argument allows you to set an
> increment value other than 1. So if you wanted to use a number in a
> calculation and then increment it by say 5 afterwards. Then after
executing
> this postfix operation

>      SomeValue = 3
>      NewValue = PP(SomeValue, "++", 5)

> NewValue is assigned 3 and SomeValue becomes 8 after the last statement.
> This is equivalent to

>      SomeValue = 3
>      NewValue = SomeValue
>      SomeValue = SomeValue + 5

> Rick




> > >Have I fallen for the trick?

> > You seem to have worked your way around it.

> > I think the pitfall intended is that C++ *immediately* increments the
> > variable, before doing anything in the loop body, while in the VB code,
> > it's (commonly) done at the end:

> > >  while(n++ < 20)
> > >  {
> > ...
> > >  }

> > >'And in VB
> > >    Dim n As Integer
> > >    n = 1
> > >    Do While n < 21
> > ...
> > >        n = n + 1
> > >    Loop

> > This is not the same. This is:

> >     Dim n As Integer
> >     n = 0
> >     Do While n < 20
> > n = n + 1
> >         ...
> >     Loop

> > --
> > Bart.



Mon, 06 Oct 2003 23:24:03 GMT  
 test question for the vb suck-ups out there


| What about if we construct an equivalent to the ++ operator. Consider this
| function
|
| Function PP(Arg1 As Variant, Arg2 As Variant, _
|             Optional Increment As Long = 1) As Variant
|   Dim ErrorCondition As Long
|   If Increment < 0 Then
|     ErrorCondition = 380 'Invalid property value -- must be positive
|   ElseIf Arg1 = "++" Then 'Prefix
|     If VarType(Arg2) > 3 Then
|       ErrorCondition = 13 'Type mismatch - not Integer or Long
|     Else
|       Arg2 = Arg2 + Increment
|       PP = Arg2
|     End If
|   ElseIf Arg2 = "++" Then 'Postfix
|     If VarType(Arg1) > 3 Then
|       ErrorCondition = 13 'Type mismatch - not Integer or Long
|     Else
|       PP = Arg1
|       Arg1 = Arg1 + Increment
|     End If
|   Else
|     ErrorCondition = 93 'Invalid Pattern String -- no "++" specified
|   End If
|   If ErrorCondition Then Err.Raise ErrorCondition
| End Function
|
| where PP is meant to stand for the ++ (plus plus) operator. The
| prefix/postfix operation is controlled by placing the string "++" either in
| the first or second argument (and your Integer or Long variable in the other
| of those two arguments). If the first argument is set as "++", then a prefix
| operation is performed. If the second argument is set as "++", then a
| postfix operation is performed.
|
| So, the loop
|
|      while(n++ < 20)
|        {
|           .....
|        }
|
| would become
|
|      Do While PP(n, "++") < 20
|        ...
|      Loop
|
| To duplicate this loop instead
|
|      while(++n < 20)
|       {
|          .....
|       }
|
| you would use
|
|      Do While PP("++", n) < 20
|         ...
|      Loop
|
| Of course this is not as compact as the C/C++ notation, but it is fully
| equivalent in function. You may use it in any calcution, not just in loop
| control tests.
|
| Oh, and one final note. The optional third argument allows you to set an
| increment value other than 1. So if you wanted to use a number in a
| calculation and then increment it by say 5 afterwards. Then after executing
| this postfix operation
|
|      SomeValue = 3
|      NewValue = PP(SomeValue, "++", 5)
|
| NewValue is assigned 3 and SomeValue becomes 8 after the last statement.
| This is equivalent to
|
|      SomeValue = 3
|      NewValue = SomeValue
|      SomeValue = SomeValue + 5
|
| Rick

Hey Rick, thats pretty good.
I just want to say, dont you hate the amount of code that
VB requires as oposed to C++. I wish they could some
day reduce this, its just to word'y...

Chris Val



Mon, 06 Oct 2003 23:25:05 GMT  
 test question for the vb suck-ups out there
Actually, most of the routine dealt with error detection. If you could trust
yourself to always input the correct parameters <g>, everything boils down
to this:

    Function PP(Arg1 As Variant, Arg2 As Variant, _
                  Optional Increment As Long = 1) As Variant
        If Arg1 = "++" Then 'Prefix
           Arg2 = Arg2 + Increment
           PP = Arg2
        ElseIf Arg2 = "++" Then 'Postfix
           PP = Arg1
           Arg1 = Arg1 + Increment
        End If
    End Function

This code is really not that bad; you should find it easier to read.

Rick



Quote:



> | What about if we construct an equivalent to the ++ operator. Consider
this
> | function
> |
> | Function PP(Arg1 As Variant, Arg2 As Variant, _
> |             Optional Increment As Long = 1) As Variant
> |   Dim ErrorCondition As Long
> |   If Increment < 0 Then
> |     ErrorCondition = 380 'Invalid property value -- must be positive
> |   ElseIf Arg1 = "++" Then 'Prefix
> |     If VarType(Arg2) > 3 Then
> |       ErrorCondition = 13 'Type mismatch - not Integer or Long
> |     Else
> |       Arg2 = Arg2 + Increment
> |       PP = Arg2
> |     End If
> |   ElseIf Arg2 = "++" Then 'Postfix
> |     If VarType(Arg1) > 3 Then
> |       ErrorCondition = 13 'Type mismatch - not Integer or Long
> |     Else
> |       PP = Arg1
> |       Arg1 = Arg1 + Increment
> |     End If
> |   Else
> |     ErrorCondition = 93 'Invalid Pattern String -- no "++" specified
> |   End If
> |   If ErrorCondition Then Err.Raise ErrorCondition
> | End Function
> |
> | where PP is meant to stand for the ++ (plus plus) operator. The
> | prefix/postfix operation is controlled by placing the string "++" either
in
> | the first or second argument (and your Integer or Long variable in the
other
> | of those two arguments). If the first argument is set as "++", then a
prefix
> | operation is performed. If the second argument is set as "++", then a
> | postfix operation is performed.
> |
> | So, the loop
> |
> |      while(n++ < 20)
> |        {
> |           .....
> |        }
> |
> | would become
> |
> |      Do While PP(n, "++") < 20
> |        ...
> |      Loop
> |
> | To duplicate this loop instead
> |
> |      while(++n < 20)
> |       {
> |          .....
> |       }
> |
> | you would use
> |
> |      Do While PP("++", n) < 20
> |         ...
> |      Loop
> |
> | Of course this is not as compact as the C/C++ notation, but it is fully
> | equivalent in function. You may use it in any calcution, not just in
loop
> | control tests.
> |
> | Oh, and one final note. The optional third argument allows you to set an
> | increment value other than 1. So if you wanted to use a number in a
> | calculation and then increment it by say 5 afterwards. Then after
executing
> | this postfix operation
> |
> |      SomeValue = 3
> |      NewValue = PP(SomeValue, "++", 5)
> |
> | NewValue is assigned 3 and SomeValue becomes 8 after the last statement.
> | This is equivalent to
> |
> |      SomeValue = 3
> |      NewValue = SomeValue
> |      SomeValue = SomeValue + 5
> |
> | Rick

> Hey Rick, thats pretty good.
> I just want to say, dont you hate the amount of code that
> VB requires as oposed to C++. I wish they could some
> day reduce this, its just to word'y...

> Chris Val



Mon, 06 Oct 2003 23:51:53 GMT  
 test question for the vb suck-ups out there


| Actually, most of the routine dealt with error detection. If you could trust
| yourself to always input the correct parameters <g>, everything boils down
| to this:
|
|     Function PP(Arg1 As Variant, Arg2 As Variant, _
|                   Optional Increment As Long = 1) As Variant
|         If Arg1 = "++" Then 'Prefix
|            Arg2 = Arg2 + Increment
|            PP = Arg2
|         ElseIf Arg2 = "++" Then 'Postfix
|            PP = Arg1
|            Arg1 = Arg1 + Increment
|         End If
|     End Function
|
| This code is really not that bad; you should find it easier to read.
|
| Rick

Fair enough, I didn't take that into consideration really...

Chris Val



| >


| > | What about if we construct an equivalent to the ++ operator. Consider
| this
| > | function
| > |
| > | Function PP(Arg1 As Variant, Arg2 As Variant, _
| > |             Optional Increment As Long = 1) As Variant
| > |   Dim ErrorCondition As Long
| > |   If Increment < 0 Then
| > |     ErrorCondition = 380 'Invalid property value -- must be positive
| > |   ElseIf Arg1 = "++" Then 'Prefix
| > |     If VarType(Arg2) > 3 Then
| > |       ErrorCondition = 13 'Type mismatch - not Integer or Long
| > |     Else
| > |       Arg2 = Arg2 + Increment
| > |       PP = Arg2
| > |     End If
| > |   ElseIf Arg2 = "++" Then 'Postfix
| > |     If VarType(Arg1) > 3 Then
| > |       ErrorCondition = 13 'Type mismatch - not Integer or Long
| > |     Else
| > |       PP = Arg1
| > |       Arg1 = Arg1 + Increment
| > |     End If
| > |   Else
| > |     ErrorCondition = 93 'Invalid Pattern String -- no "++" specified
| > |   End If
| > |   If ErrorCondition Then Err.Raise ErrorCondition
| > | End Function
| > |
| > | where PP is meant to stand for the ++ (plus plus) operator. The
| > | prefix/postfix operation is controlled by placing the string "++" either
| in
| > | the first or second argument (and your Integer or Long variable in the
| other
| > | of those two arguments). If the first argument is set as "++", then a
| prefix
| > | operation is performed. If the second argument is set as "++", then a
| > | postfix operation is performed.
| > |
| > | So, the loop
| > |
| > |      while(n++ < 20)
| > |        {
| > |           .....
| > |        }
| > |
| > | would become
| > |
| > |      Do While PP(n, "++") < 20
| > |        ...
| > |      Loop
| > |
| > | To duplicate this loop instead
| > |
| > |      while(++n < 20)
| > |       {
| > |          .....
| > |       }
| > |
| > | you would use
| > |
| > |      Do While PP("++", n) < 20
| > |         ...
| > |      Loop
| > |
| > | Of course this is not as compact as the C/C++ notation, but it is fully
| > | equivalent in function. You may use it in any calcution, not just in
| loop
| > | control tests.
| > |
| > | Oh, and one final note. The optional third argument allows you to set an
| > | increment value other than 1. So if you wanted to use a number in a
| > | calculation and then increment it by say 5 afterwards. Then after
| executing
| > | this postfix operation
| > |
| > |      SomeValue = 3
| > |      NewValue = PP(SomeValue, "++", 5)
| > |
| > | NewValue is assigned 3 and SomeValue becomes 8 after the last statement.
| > | This is equivalent to
| > |
| > |      SomeValue = 3
| > |      NewValue = SomeValue
| > |      SomeValue = SomeValue + 5
| > |
| > | Rick
| >
| > Hey Rick, thats pretty good.
| > I just want to say, dont you hate the amount of code that
| > VB requires as oposed to C++. I wish they could some
| > day reduce this, its just to word'y...
| >
| > Chris Val
| >
| >
| >
| >
|
|



Mon, 06 Oct 2003 23:56:52 GMT  
 test question for the vb suck-ups out there
Poor pinion-plucked pathetic picked-on parrot can't even write this simple
stuff in VB? On the other hand, hmm, code seems awfully familiar -- could it
have been recycled from a previous article or website where some C wonk was
complaining that VB wasn't C? Oh, well, at least he didn't offer to pay for
someone to do it. <G>


Quote:
> Try translating this c++ into VB:

>   // loop to print even integers between 1 and 20
>   int n = 0;
>   while(n++ < 20)
>   {
>     if(n % 2)
>       continue;

>     cout << n << endl;
>   }

> Be careful now . . . trick question.



Tue, 07 Oct 2003 00:50:53 GMT  
 
 [ 21 post ]  Go to page: [1] [2]

 Relevant Pages 

1. TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST

2. How to handle print outs in VB?

3. TEST TEST TEST TEST

4. alt.test,comp.test,misc.test,news.test

5. UPS Online Tools Using VB

6. UPS and VB

7. MCSD test on VB - questions.

8. university EMR send outs

9. on the outs

10. Learning the ins and outs of Peek and Poke

 

 
Powered by phpBB® Forum Software