Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Cetin Basoz
  Where is Cetin Basoz?
 Izmir
 Turkey
 Cetin Basoz
 To: anand kulkarni
  Where is anand kulkarni?
 sholapur
 India
 anand kulkarni
 Tags
Subject: RE: if endif,do while,scan endscan with C#
Thread ID: 394070 Message ID: 394111 # Views: 88 # Ratings: 8
Version: Visual FoxPro 9 SP2 Category: .NET
Date: Monday, December 30, 2013 6:49:50 PM         
   


> Hello Experts ,
> Thanks for C Sharp Support . Now I have just completed Insert / Update / Delete with C sharp . Now days I am playing with this :) . Once again thanks . It Could not be possible without your help and thanks to Eric for Foxite :) .
>
> Now Next Step I want to take . I think you came to know with the Subject of this thread .
> Now I want comparative help for if/endif, do while , scan/endscan with C sharp.
> Thanks In Advance .
>
> regards
> Anand S. Kulkarni
>
> When it rains ... all Birds occupy shelter , but Eagle is the only bird with its capacity to fly over the sky to avoid rains !!!
> https://www.facebook.com/pages/Ask-Software-Consultant-Solapur/163446803786335?ref=stream

With a comparison to VFP? C# counterparts are more versatile:

if ... endif and if ...else... endif

typically:

if (conditionalExpr )
{
  //...
}

// and
if ( conditionalExpr )
{
  //...
} 
else
{
  //...
}



do case ... endcase

simply done with if ... else ... endif style using the fact that syntactically you can write it like:

if c1
...
else
  if c2
    ...
  else
    if c3
       ...
    else
       ...
    endif
  endif
endif


And in C# it is much easier and readable:

if ( c1 )
{
//...
}
else if ( c2 )
{
//...
}
else if ( c3 )
{
//...
}
else
{
//...
}


(There is a switch () in C# that at first looks like do case...endcase but is different).

Also inline if -iif()- is a little more cleaner:

var result = ( conditionalExpr )
              ? trueCase
              : falseCase;


( remember you can write this on a single line if you will )

do while ... enddo

has one counterpart:

while ( conditionalExpr )
{
  // ...
}


and another one that VFP doesn't have:

do
{
  // ... guaranteed to execute once
  // even if conditionalExpr is false
} while (conditionalExpr )


In VFP you have to do that like:

* ... the code to execute
do while conditionalExpr
  * ... the code to execute
enddo


Note the unnecessary duplication in code (VFP coders need to be creative to prevent this duplication but that makes it harder).

scan ... endscan

Well, this one has many counterparts. Scan ... endscan is kind of an "Enumerator" over a set of records. In C# you don't have "table and records" but you have a "collection of objects" which you can think of as "a table of records" as well (it is more than that). Then you have for and foreach iterators over that collection, as well as since Linq operates on any collections you are granted with its iterator methods. And some classes like Enumerable provide you out of the box collections that you can iterate (scan ... endscan) - you *can* write inline delegate codes that act as the body of a scan .. endscan on virtually any collection, or you could use a delegate function as a parameter to an enumeration -flying over the top of your head like bullets I guess at the moment-. I don't say do it but you can do it. Here is a sample:

Assume you have a table created and populated this way:

create table tickdata (timed datetime, price money, quantity int)
insert into tickData values ('06:01',100,20)
insert into tickData values ('06:02',90,30)
insert into tickData values ('06:03',129,10)
insert into tickData values ('06:11',112,8)
insert into tickData values ('06:12',150,60)
insert into tickData values ('06:20',110,10)
insert into tickData values ('06:23',120,5)
insert into tickData values ('06:24:59',130,15)
insert into tickData values ('06:25',140,35)


It is a typical stock realtime data for a given stock (say MSFT) and we want to convert this into an "period, open, low, high, close, volume" cursor, where "period" is 5 minute intervals starting from 06:00 -nearest multiple of five minutes of the min time really-. There are multiple ways to do that, including using for() {...} or foreach() {...} to do it like scan...endscan. But we can also do it with the Linq (the Great:) natural syntax:

var myStock = from myData in db.Tickdata.OrderBy( t => t.Timed ).AsEnumerable()
  group myData by ((int)myData.Timed.Value.TimeOfDay.TotalMinutes) / 5 into barData
  let bStart = TimeSpan.FromMinutes( barData.Key * 5 ).ToString()
  let bEnd   = TimeSpan.FromMinutes( (barData.Key+1) * 5 ).ToString()
  select new 
  { period = bStart.Substring(0,5) + " - " + bEnd.Substring(0,5),
	open   = barData.FirstOrDefault().Price,   
	low    = barData.Min( bd => bd.Price ),
	high   = barData.Max( bd => bd.Price ),
	close  = barData.LastOrDefault().Price,
	volume = barData.Sum( bd => bd.Quantity ) };



This would give us something like:

period	        open	low	high	close	volume
06:00 - 06:05	100	90	129	129	60
06:10 - 06:15	112	112	150	150	68
06:20 - 06:25	110	110	130	130	30
06:25 - 06:30	140	140	140	140	35


It is up to you, to consider this as a scan ... endscan or an SQL or a mixture with some UDF in between :)

PS: This example is a little heavy for beginners.



Cetin Basoz

Give some sample data in code for your question - here is the tool you need to generate the code

My Blog


MongoDb Certified Developer
MongoDb Certified DBA


Support Wikipedia

ENTIRE THREAD

if endif,do while,scan endscan with C# Posted by anand kulkarni @ 12/30/2013 1:30:32 PM
RE: if endif,do while,scan endscan with C# Posted by Stefan Wuebbe @ 12/30/2013 2:15:20 PM
RE: if endif,do while,scan endscan with C# Posted by anand kulkarni @ 12/31/2013 4:20:30 AM
RE: if endif,do while,scan endscan with C# Posted by Cetin Basoz @ 12/30/2013 6:49:50 PM
RE: if endif,do while,scan endscan with C# Posted by Gene Wirchenko @ 12/30/2013 8:11:48 PM
RE: if endif,do while,scan endscan with C# Posted by Stefan Wuebbe @ 12/30/2013 10:52:46 PM
RE: if endif,do while,scan endscan with C# Posted by Gene Wirchenko @ 12/31/2013 7:34:32 PM
RE: if endif,do while,scan endscan with C# Posted by Tony Vignone @ 12/31/2013 9:26:15 PM
RE: if endif,do while,scan endscan with C# Posted by David Mustakim @ 12/31/2013 9:39:31 PM
RE: if endif,do while,scan endscan with C# Posted by Tony Vignone @ 12/31/2013 10:33:36 PM
RE: if endif,do while,scan endscan with C# Posted by David Mustakim @ 1/2/2014 10:05:03 PM
RE: if endif,do while,scan endscan with C# Posted by Tony Vignone @ 1/2/2014 11:37:33 PM
RE: if endif,do while,scan endscan with C# Posted by Gene Wirchenko @ 12/31/2013 11:06:05 PM
RE: if endif,do while,scan endscan with C# Posted by Cetin Basoz @ 1/2/2014 1:42:16 PM
RE: if endif,do while,scan endscan with C# Posted by Gene Wirchenko @ 1/2/2014 6:49:34 PM
RE: if endif,do while,scan endscan with C# Posted by Stefan Wuebbe @ 1/1/2014 11:49:33 AM
RE: if endif,do while,scan endscan with C# Posted by Gene Wirchenko @ 1/2/2014 3:31:21 AM
RE: if endif,do while,scan endscan with C# Posted by Cetin Basoz @ 1/2/2014 1:38:05 PM
RE: if endif,do while,scan endscan with C# Posted by Gene Wirchenko @ 1/2/2014 7:04:59 PM
RE: if endif,do while,scan endscan with C# Posted by Cetin Basoz @ 1/2/2014 7:31:59 PM
RE: if endif,do while,scan endscan with C# Posted by Gene Wirchenko @ 1/3/2014 7:45:08 PM
RE: if endif,do while,scan endscan with C# Posted by Cetin Basoz @ 1/3/2014 9:38:13 PM
RE: if endif,do while,scan endscan with C# Posted by Gene Wirchenko @ 1/6/2014 8:26:53 PM
RE: if endif,do while,scan endscan with C# Posted by Glen Villar @ 12/31/2013 4:19:58 AM
RE: if endif,do while,scan endscan with C# Posted by Cetin Basoz @ 12/31/2013 10:10:22 AM
RE: if endif,do while,scan endscan with C# Posted by Glen Villar @ 12/31/2013 12:02:34 PM
RE: if endif,do while,scan endscan with C# Posted by Binod Binani @ 1/3/2014 2:34:45 PM