Popular Posts

Sep 25, 2011

Available Preprocessor Directives

#define: Used to define the compilation identifier, such as the INTEGRATE_
TESTS identifier used in this chapter’s example. You would define this
at the top of a source code file to activate conditional preprocessor
statements used throughout the source code file. Using a #define
directive does not span multiple source code files.

#undef: Used to undefine an identifier. You would use #undef if you wanted
to change a global setting. Let’s say that an identifier is set globally,
but for a particular source code file, you want the behavior as if the
identifier were not set. In that case, you use #undef. Another way to
achieve this behavior is to use the ! character in front of the identifier.

#if and #endif: Used to conditionally include or not include a piece of source code.You would use a conditional directive whenever you wanted to define
source code configurations, such as for debug or production builds.

#elif: Instead of a single #if block, you could have multiple tests for code
inclusion. You would use #elif when you have more than a single
preprocessor directive, such as for debug, production, and performance

#else: A default code block that is included if the other #if statements did
not trigger.

#region and #endregion: These have absolutely nothing to do with the compilation of the source code. They are used by Visual Studio to create regions of source code that can be “folded.” Folding means to collapse a block of code
out of sight temporarily. Source code files can become long, and constantly
paging up and down becomes tedious. By folding the code,
you are reducing the amount of times that you need to page up and
down, even though the code still exists.

Sep 22, 2011

Exception Description

We can easily handle exception in c#. Here are some name and their description.

Exception :
Plain vanilla exception; a general container for all exceptions.
When you get one of these exceptions, look at the Message
property for the exact details. If you throw this type of
exception, it is important to supply an easy-to-understand
string to the exception constructor.
ArgumentException :
Thrown if you call a method and one of the arguments is not
valid. Typically, in the Message property you can find the
problem with the arguments. If this exception is thrown, it is
because the contents of the argument are wrong.
ArgumentNullException :
Thrown if you call a method where one of the arguments is
a null value. This could be because you are passing the null
value to the method or one of the arguments has a null value.
ArgumentOutOfRangeException :
 Thrown if you call a method where one of the arguments is not
in the expected range. While this exception sounds similar to
ArgumentException, :
  it is more specialized and targets whether
an argument is in an acceptable range. Check the
documentation of the method or the method implementation
on what the acceptable range is. If you throw this exception,
note the valid range in the error message.
ArithmeticException  :
 Thrown if a mathematical error is generated.
DivideByZeroException  :
 Thrown if you attempt to divide by zero.
FormatException  :
 Thrown if the format of the parameter is not correct. For
example, if a method expects a number to be formatted with
a period and you use a comma, an exception is generated.

IndexOutOfRangeException  :
 Thrown if you attempt to reference an index of an array that
would be beyond the limits of the array. This exception is
thrown if you have not allocated an array and then attempt to
reference an element, or if you attempt to reference a negative
index of the array.
InsufficientMemoryException :
  Thrown if not enough memory is available. Although this
exception is not generated often, it can be generated if you
attempt to allocate an array when you specify something along
the lines of 5 trillion elements (due to an improperly assigned
array size variable).
InvalidCastException  :
 Thrown if you attempt to cast one type to another type that is
not supported. This exception is very common when you use
inheritance and attempt a cast.
NotImplementedException :
  Thrown when using methods or properties without an
implementation. Often, you don’t have time to implement all
of the code at once. For those properties or methods that have
not been implemented, don’t leave an empty property or
method implementation. Instead, throw an exception. Then
you will know if you have forgotten to implement something.
NotSupportedException  :
 Thrown when you attempt to use an interface instance and
a method that cannot work. For example, if you open a readwrite
buffer to a read-only CD-ROM, you will get this exception
when writing to the CD-ROM. If you attempt to read from the
interface instance, an exception will not be thrown.
NullReferenceException :
  Thrown when you attempt to call a method or property of
a variable that has not been assigned with a valid type
OutOfMemoryException : Similar to InsufficientMemoryException.
OverflowException  :
 Thrown when you attempt to perform numeric operations that
are not supported, such as adding 2 billion to 2 billion using
a 32-bit integer.
SystemException Thrown by the operating system. :
 Do not attempt to derive
from this class.

Sep 18, 2011

Keep The Searched Values In The Fields In PHP

<script type="text/javascript">
      var __postBack =  '<?php echo json_encode($_POST); ?>';
      var obj = jQuery.parseJSON(__postBack);
      $.each(obj,function(key, value){

How to load data in a combobox without reloading the page from other page in PHP

Write the code in page a.php
<select name="company_id" id="company_id" >
                                                   $getCompany = "select customer_id, company_name from customer WHERE customet_type = 1";
                                                   $getCompanyResult = mysql_query($getCompany);
                                                   while($getCompanyRows = mysql_fetch_object($getCompanyResult)){
                                                   <option value="<?php echo $getCompanyRows->customer_id ; ?>" <?php if($getCompanyRows->customer_id == $var->company_id){ echo "selected"; } ?> ><?php echo $getCompanyRows->company_name ; ?></option>
<a href="#" onClick="window.open('b.php?hide_menu=1','popup','width=960,height=530,scrollbars=no,scrollbars=yes,toolbar=no,directories=no,location=no,menubar=no,status=no,left=300,top=300'); return false">Add New Data</a>

In Page B:
Write some code to insert the data in database.
<script language="javascript">
var optionstr = '<option></option>';
   $getCompany = "select customer_id, company_name from customer WHERE customet_type = 1";
   $getCompanyResult = mysql_query($getCompany);
   while($getCompanyRows = mysql_fetch_object($getCompanyResult)){
   optionstr +='<option value="<?php echo $getCompanyRows->customer_id ; ?>"><?php echo $getCompanyRows->company_name ; ?></option>';
window.opener.document.getElementById('company_id').innerHTML= optionstr;

Sep 14, 2011


1. You need a mac os x( mac mini, or mac book or mac pro, anything you like)
2. To submit your work to apple you need a apple developer license as well.
3. The SDK is free to download, so you can build you application and test it on simulator without any cost. But if you want to test it on your iPhone/iPod touch or submit it to apple store, you must have a developer license.
4. To test your application, you must have either iPod or iPhone because Simulator and device behaves differently on some features like memory.  So I highly recommand you to buy one device as well.
5. Programming language is Objective – C and its very similar to C/C++, You don't need to spend much time to understand the language.
If i missed some more points... pls let me know....

Sep 6, 2011

Search In Table View

#import <UIKit/UIKit.h>

#define COOKBOOK_PURPLE_COLOR    [UIColor colorWithRed:0.20392f green:0.19607f blue:0.61176f alpha:1.0f]

#define CRAYON_NAME(CRAYON)           [[CRAYON componentsSeparatedByString:@"#"] objectAtIndex:0]
#define CRAYON_COLOR(CRAYON) [self getColor:[[CRAYON componentsSeparatedByString:@"#"] lastObject]]

#define DEFAULTKEYS [self.crayonColors.allKeys sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]
#define FILTEREDKEYS [self.filteredArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]

@interface TableListViewController : UITableViewController
         NSMutableDictionary *crayonColors;
         NSArray *filteredArray;
         UISearchBar *searchBar;
         UISearchDisplayController *searchDC;
@property (retain) NSMutableDictionary *crayonColors;
@property (retain) NSArray *filteredArray;
@property (retain) UISearchBar *searchBar;
@property (retain) UISearchDisplayController *searchDC;

@implementation TableListViewController
@synthesize crayonColors;
@synthesize filteredArray;
@synthesize searchBar;
@synthesize searchDC;

- (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView
         return 1;

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
         [self.searchBar setText:@""];

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
         // Normal table
         if (aTableView == self.tableView) return self.crayonColors.allKeys.count;
         // Search table
         NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains[cd] %@", self.searchBar.text];
         self.filteredArray = [self.crayonColors.allKeys filteredArrayUsingPredicate:predicate];
         return self.filteredArray.count;

// Convert a 6-character hex color to a UIColor object
- (UIColor *) getColor: (NSString *) hexColor
         unsigned int red, green, blue;
         NSRange range;
         range.length = 2;
         range.location = 0;
         [[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&red];
         range.location = 2;
         [[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&green];
         range.location = 4;
         [[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&blue];
         return [UIColor colorWithRed:(float)(red/255.0f) green:(float)(green/255.0f) blue:(float)(blue/255.0f) alpha:1.0f];

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
         // Dequeue or create a cell
         UITableViewCellStyle style =  UITableViewCellStyleDefault;
         UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:@"BaseCell"];
         if (!cell) cell = [[[UITableViewCell alloc] initWithStyle:style reuseIdentifier:@"BaseCell"] autorelease];
         // Retrieve the crayon and its color
         NSArray *keyCollection = (aTableView == self.tableView) ? DEFAULTKEYS : FILTEREDKEYS;
         NSString *crayon = [keyCollection objectAtIndex:indexPath.row];
         cell.textLabel.text = crayon;
         if (![crayon hasPrefix:@"White"])
            cell.textLabel.textColor = [self.crayonColors objectForKey:crayon];
            cell.textLabel.textColor = [UIColor blackColor];
         return cell;

// Respond to user selections by updating tint colors
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
         NSArray *keyCollection = (aTableView == self.tableView) ? DEFAULTKEYS : FILTEREDKEYS;
         NSString *crayon = [keyCollection objectAtIndex:indexPath.row];
         self.navigationController.navigationBar.tintColor = [self.crayonColors objectForKey:crayon];
         self.searchBar.tintColor = [self.crayonColors objectForKey:crayon];

- (void) viewDidLoad
         // Prepare the crayon color dictionary
         NSString *pathname = [[NSBundle mainBundle]  pathForResource:@"crayons" ofType:@"txt" inDirectory:@"/"];
         NSArray *rawCrayons = [[NSString stringWithContentsOfFile:pathname encoding:NSUTF8StringEncoding error:nil] componentsSeparatedByString:@"\n"];
         self.crayonColors = [NSMutableDictionary dictionary];
         for (NSString *string in rawCrayons)
            [self.crayonColors setObject:CRAYON_COLOR(string) forKey:CRAYON_NAME(string)];
         // Create a search bar
         self.searchBar = [[[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)] autorelease];
         self.searchBar.tintColor = COOKBOOK_PURPLE_COLOR;
         self.searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
         self.searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
         self.searchBar.keyboardType = UIKeyboardTypeAlphabet;
         self.tableView.tableHeaderView = self.searchBar;
         // Create the search display controller
         self.searchDC = [[[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self] autorelease];
         self.searchDC.searchResultsDataSource = self;
         self.searchDC.searchResultsDelegate = self;

@interface TestBedAppDelegate : NSObject <UIApplicationDelegate>

@implementation TestBedAppDelegate
- (void)applicationDidFinishLaunching:(UIApplication *)application
         TableListViewController *tlvc = [[TableListViewController alloc] init];
         UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:tlvc];
         nav.navigationBar.tintColor = COOKBOOK_PURPLE_COLOR;
         UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
         [window addSubview:nav.view];
         [window makeKeyAndVisible];

int main(int argc, char *argv[])
         NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
         int retVal = UIApplicationMain(argc, argv, nil, @"TestBedAppDelegate");
         [pool release];
         return retVal;