Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ CLI
/*
Simple 256 x 3 array with data of type string containing reps of numerical
Trying to write to console converted value but filter only one of the inner loop's cycles. 
Why can't the use of "if(rs = 0)" do the filtering?
*/
using namespace System;
using namespace System::IO;
using namespace System::Text;
/* array of 256 x 3 */
void PrintValues(Array^ myArr);
int main()
{
  array<String^, 2>^testArray = gcnew array<String^,2>(256,3);
  /* zero (as string) array ... */
  for (int aa=testArray->GetLowerBound(0);aa<=testArray->GetUpperBound(0);aa++)
    for (int ab=testArray->GetLowerBound(1);ab<=testArray->GetUpperBound(1);ab++)
    {
      testArray->SetValue("0",aa,ab);
    }
 
 /* comment this next three lines to avoid the print out of the array content */
  PrintValues(testArray);
  Console::WriteLine(" ");
  Console::WriteLine(" ");
  /* add some string content to the zeroed table */
  testArray->SetValue("555",23,1);
  testArray->SetValue("129",128,2);
  testArray->SetValue("141",45,0);
  /* output the tabular data in an admittedly odd fashion (wait ... there's a point here) */
  for (int aa=testArray->GetLowerBound(0);aa<=testArray->GetUpperBound(0);aa++)
    for (int ab=testArray->GetLowerBound(1);ab<=testArray->GetUpperBound(1);ab++)
    {
      if (Convert::ToInt32(testArray[aa,0])>0)
      /* this will return three runs at that value located @ testArray[45,0] all of which are 141 */
        Console::WriteLine("using GetValue: {0}", testArray->GetValue(aa,0));
    }
 
    //PrintValues(testArray);
    /* Now, here's the "filter" I'd like to add to this for loop; the reason for this question -> seems like a no brainer in an "if-then-else sense". But no! */
    //for (int aa=testArray->GetLowerBound(0);aa<=testArray->GetUpperBound(0);aa++)
    //	for (int ab=testArray->GetLowerBound(1);ab<=testArray->GetUpperBound(1);ab++)
    //	{
    //    if (Convert::ToInt32(testArray[aa,0])>0)
    //    /* this will never return ...  */
    //      if(ab=0)
    //      {
    //       Console::WriteLine("using GetValue: {0}", testArray->GetValue(aa,0));
    //      }
    //  }
}
 
void PrintValues( Array^ myArr )
{
  System::Collections::IEnumerator^ myEnumerator = myArr->GetEnumerator();
  int i = 0;
  int cols = myArr->GetLength( myArr->Rank - 1 );
  while ( myEnumerator->MoveNext() )
  {
    if ( i < cols )
    {
      i++;
    }
    else
    {
      Console::WriteLine();
      i = 1;
    }
    Console::Write(  "\t{0}", myEnumerator->Current );
  }
}
Posted 14-Mar-12 10:44am
RedDk10.3K
Edited 14-Mar-12 11:44am
Nelek63.2K
v3
Comments
OriginalGriff at 14-Mar-12 15:59pm
   
The code block markers are visible, rather than acting to format the code - I have reported it in Sugs&Bugs.
It's not something you have done wrong - it's a bug by the looks of things!
Nelek at 14-Mar-12 16:30pm
   
Edition: Pre Tags added (it did work for me, choosing a language not the basic pre's) and changed tabulations a bit to avoid many instructions being "multilined"

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

RedDK wrote:
if(ab=0)

Ahem...[^].
  Permalink  
Comments
Randor at 14-Mar-12 17:56pm
   
Beware of the darkside. Stopped they must be; on this all depends. Yoda conditions I recommend.
CPallini at 14-Mar-12 18:51pm
   
There is no dark side [...], really. As a matter of fact it's all dark.
SAKryukov at 14-Mar-12 19:35pm
   
So funny you guys are. And I like the text of the anchor: "Ahem..." -- just right thing to say. 5 for the answer.
--SA
CPallini at 15-Mar-12 4:14am
   
Thank you. :-)
RedDK at 14-Mar-12 20:42pm
   
Thanks C,
 
if(ab==0) it is ...
pwasser at 15-Mar-12 6:39am
   
I usually put the constant first and let the compiler do it's job.
 
Thus:
if(0=ab)
SAKryukov at 15-Mar-12 21:45pm
   
! :-)
Unfortunately, the trick does not work with two variables -- the bug won't be detected...
--SA
Randor at 15-Mar-12 21:56pm
   
Left operand must be l-value.
SAKryukov at 15-Mar-12 22:44pm
   
Yes, yes, I understand how your technique works. Of course. I just say, if the two are variables, and '=' is written by mistake instead of "==", this technique won't help, exactly because you introduce l-value anyway, and the bug get passes, agree?
--SA
Randor at 15-Mar-12 23:06pm
   
Yes, if both variables are l-value then there is no trick for avoiding an erroneous assignment.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 400
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 14 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100