Home AMX User Forum NetLinx Studio

Address book Module/Code

Hi all,
I was wondering if any one would have or know of an "Address book" module/code that I could get my hands on.
I'm after function like add, remove, edit, sort and find.

Regards
Craig

Comments

  • SensivaSensiva Posts: 211
    Module/Code

    Hi.... You should say address book for what?? which device, model, manufacturer..

    Go to InConcert and .. search, if you don't have an account, sign up for one.
  • AMXJeffAMXJeff Posts: 450
    Addressbook Functions

    This should give you an idea how to do it, just provided the helper functions.
    DEFINE_CONSTANT
    
    MAX_STRUCT_ITEM_LENGTH = 50;
    MAX_ADDRESSBOOK_ENTRIES = 100;
    
    DEFINE_TYPE
    
    STRUCTURE _AddressBookEntry
    {
    	CHAR cFirstName[MAX_STRUCT_ITEM_LENGTH];
    	CHAR cLastName[MAX_STRUCT_ITEM_LENGTH];
    	CHAR cAddress1[MAX_STRUCT_ITEM_LENGTH];
    	CHAR cAddress2[MAX_STRUCT_ITEM_LENGTH];
    	CHAR cCity[MAX_STRUCT_ITEM_LENGTH];
    	CHAR cState[MAX_STRUCT_ITEM_LENGTH];
    	CHAR cZip[MAX_STRUCT_ITEM_LENGTH];
    	CHAR cPhone[MAX_STRUCT_ITEM_LENGTH];
    	CHAR cFax[MAX_STRUCT_ITEM_LENGTH];
    	CHAR cEmail[MAX_STRUCT_ITEM_LENGTH];
    }
    
    
    DEFINE_VARIABLE
    
    non_volatile _AddressBookEntry uMyAddressbook[MAX_ADDRESSBOOK_ENTRIES];
    VOLATILE _AddressBookEntry uUserEntryItem;
    
    DEFINE_FUNCTION INTEGER CompareAddressBookItems (_AddressBookEntry uItem1, _AddressBookEntry uItem2)
    {
    	IF ( (uItem1.cAddress1 	== uItem2.cAddress1) 	&& 
                          (uItem1.cAddress2 	== uItem2.cAddress2) 	&&
    	      (uItem1.cCity 		== uItem2.cCity) 		&&
    	      (uItem1.cEmail 		== uItem2.cEmail) 		&&
    	      (uItem1.cFax 		== uItem2.cFax) 		&&
    	      (uItem1.cFirstName              == uItem2.cFirstName)              &&
    	      (uItem1.cLastName 	== uItem2.cLastName) 	&&
    	      (uItem1.cPhone 		== uItem2.cPhone) 		&&
    	      (uItem1.cState 		== uItem2.cState) 		&&
    	      (uItem1.cZip 		== uItem2.cZip) )
    		RETURN TRUE;
    	ELSE
    		RETURN FALSE;
    
    }
    
    DEFINE_FUNCTION INTEGER FindAddressBookEntry (_AddressBookEntry uItem)
    {
    	STACK_VAR INTEGER nLoop;
    	
    	FOR (nLoop = 1; nLoop <= MAX_LENGTH_ARRAY(uMyAddressbook); nLoop++)
    		IF (CompareAddressBookItems(uItem, uMyAddressbook[nLoop]) == TRUE)
    			RETURN nLoop;
    			
    	RETURN 0;
    }
    
    DEFINE_FUNCTION INTEGER AddAddressBookEntry (_AddressBookEntry uItem)
    {
    	STACK_VAR INTEGER nLoop, nLocation;
    	STACK_VAR _AddressBookEntry uAddressbookNull;
    
    	// SEE IF ALREADY IN ADDRESSBOOK
    	nLocation = FindAddressBookEntry(uItem);
    	
    	IF (nLocation == 0)
    	{
    		// GET NEXT AVAILABLE SPOT
    		nLocation = FindAddressBookEntry(uAddressbookNull);
    		
    		IF (nLocation > 0)
    		{
    			uMyAddressbook[nLocation] = uItem;
    			
    			SortAddressbook(uMyAddressbook);			
    
    			RETURN nLocation;
    		}
    	}
    			
    	RETURN 0;
    }
    
    DEFINE_FUNCTION INTEGER DeleteAddressBookEntry (_AddressBookEntry uItem)
    {
    	STACK_VAR INTEGER nLoop, nLocation;
    	STACK_VAR _AddressBookEntry uAddressbookNull;
    	
    	// SEE IF ALREADY IN ADDRESSBOOK
    	nLocation = FindAddressBookEntry(uItem);
    	
    	IF (nLocation > 0)
    	{
    		uMyAddressbook[nLocation] = uAddressbookNull;
    		
    		SortAddressbook(uMyAddressbook);			
    
    		RETURN nLocation;
    	}
    			
    	RETURN 0;
    }
    
    DEFINE_FUNCTION INTEGER UpdateAddressBookEntry (_AddressBookEntry uOldItem,_AddressBookEntry uUpdateItem)
    {
    	STACK_VAR INTEGER nLoop, nLocation;
    	
    	// SEE IF ALREADY IN ADDRESSBOOK
    	nLocation = FindAddressBookEntry(uOldItem);
    	
    	IF (nLocation > 0)
    	{
    		uMyAddressbook[nLocation] = uUpdateItem;
    		
    		SortAddressbook(uMyAddressbook);			
    
    		RETURN nLocation;
    	}
    			
    	RETURN 0;
    }
    
    DEFINE_FUNCTION SortAddressbook(_AddressBookEntry uAddressbook[])
    {
    	STACK_VAR INTEGER nLoopA, nLoopB;
    	STACK_VAR _AddressBookEntry uHold;
    	STACK_VAR _AddressBookEntry uAddressbookNull;
    	
    	FOR (nLoopA = 1; nLoopA <= MAX_LENGTH_ARRAY(uAddressbook); nLoopA++)
    	{
    		FOR (nLoopB = nLoopA + 1; nLoopB <= MAX_LENGTH_ARRAY(uAddressbook); nLoopB++)
    		{
    			IF (CompareAddressBookItems(uAddressbook[nLoopB], uAddressbookNull) == FALSE)
    			{
    				IF (uAddressbook[nLoopA].cLastName >= uAddressbook[nLoopB].cLastName && uAddressbook[nLoopA].cFirstName > uAddressbook[nLoopB].cFirstName)
    				{
    					uHold = uAddressbook[nLoopB];
    					
    					uAddressbook[nLoopB] = uAddressbook[nLoopA];
    					
    					uAddressbook[nLoopA] = uHold;
    				}
    			}
    		}
    	}
    }
    
    DEFINE_START
    
    uUserEntryItem.cFirstName = 'Judy';
    uUserEntryItem.cLastName = 'Jetson';
    
    AddAddressBookEntry (uUserEntryItem);
    
    uUserEntryItem.cFirstName = 'Astro';
    uUserEntryItem.cLastName = 'Jetson';
    
    AddAddressBookEntry (uUserEntryItem);
    
    uUserEntryItem.cFirstName = 'George';
    uUserEntryItem.cLastName = 'Jetson';
    
    AddAddressBookEntry (uUserEntryItem);
    
    uUserEntryItem.cFirstName = 'Jane';
    uUserEntryItem.cLastName = 'Jetson';
    
    AddAddressBookEntry (uUserEntryItem);
    
    uUserEntryItem.cFirstName = 'Rosy';
    uUserEntryItem.cLastName = 'The Maid';
    
    AddAddressBookEntry (uUserEntryItem);
    
    uUserEntryItem.cFirstName = 'Elroy';
    uUserEntryItem.cLastName = 'Jetson';
    
    AddAddressBookEntry (uUserEntryItem);
    
    
Sign In or Register to comment.