Why doesn’t this work? If State="NY", the resulting IF statement returns 31, if the State="NC" the resulting IF returns -27, yet NC is in the array list. Its random as to which stats work and which do not. AL will return 0, but AR will return -3, yet its in the list. I know the value when neg (-) is a bitwise representation, but most every state in the array list returns a neg number, Why? string[] strStateArray = new string[] {"AL","AK","AZ","AR","CA","CO","CT","DE","FL","GA","HI","ID","IL","IN","IN","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA","WA","DC","WV","WI","WY"}; if(Array.BinarySearch(strStateArray, State.ToString())<0) { ValidationStatus="Incoming State is invalid. The follow state abrevations are acceptable: " + strStateArray.ToString(); } -- JP
Oh duh! Thank you so much. Its been one of those Fridays. -- JP ..NET Software Develper [quoted text, click to view] "pvdg42" wrote: > > "JP" <JP@discussions.microsoft.com> wrote in message > news:E5653B86-F2E2-42F0-AC2E-86F2EF952CD1@microsoft.com... > > Why doesn't this work? If State="NY", the resulting IF statement returns > > 31, > > if the State="NC" the resulting IF returns -27, yet NC is in the array > > list. > > Its random as to which stats work and which do not. AL will return 0, but > > AR > > will return -3, yet its in the list. I know the value when neg (-) is a > > bitwise representation, but most every state in the array list returns a > > neg > > number, Why? > > > > string[] strStateArray = new string[] > > {"AL","AK","AZ","AR","CA","CO","CT","DE","FL","GA","HI","ID","IL","IN","IN","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA","WA","DC","WV","WI","WY"}; > > > > > > if(Array.BinarySearch(strStateArray, State.ToString())<0) > > { > > ValidationStatus="Incoming State is invalid. The follow state > > abrevations are acceptable: " + strStateArray.ToString(); > > } > > > > -- > > JP > > .NET Software Develper > > The elements to be searched by a binary search algorithm must be sorted. > Your failures (AZ, NC, etc) are out of order, and therefore, not found. > > -- > Peter [MVP Visual Developer] > Jack of all trades, master of none. > >
[quoted text, click to view] "JP" <JP@discussions.microsoft.com> wrote in message news:E5653B86-F2E2-42F0-AC2E-86F2EF952CD1@microsoft.com... > Why doesn't this work? If State="NY", the resulting IF statement returns > 31, > if the State="NC" the resulting IF returns -27, yet NC is in the array > list. > Its random as to which stats work and which do not. AL will return 0, but > AR > will return -3, yet its in the list. I know the value when neg (-) is a > bitwise representation, but most every state in the array list returns a > neg > number, Why? > > string[] strStateArray = new string[] > {"AL","AK","AZ","AR","CA","CO","CT","DE","FL","GA","HI","ID","IL","IN","IN","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA","WA","DC","WV","WI","WY"}; > > > if(Array.BinarySearch(strStateArray, State.ToString())<0) > { > ValidationStatus="Incoming State is invalid. The follow state > abrevations are acceptable: " + strStateArray.ToString(); > } > > -- > JP > .NET Software Develper
The elements to be searched by a binary search algorithm must be sorted. Your failures (AZ, NC, etc) are out of order, and therefore, not found. -- Peter [MVP Visual Developer] Jack of all trades, master of none.
[quoted text, click to view] "pvdg42" <pvdg42@newsgroups.nospam> wrote in message news:%23BEIjgIcGHA.3872@TK2MSFTNGP04.phx.gbl... > > "JP" <JP@discussions.microsoft.com> wrote in message > news:E5653B86-F2E2-42F0-AC2E-86F2EF952CD1@microsoft.com... >> Why doesn't this work? If State="NY", the resulting IF statement returns >> 31, >> if the State="NC" the resulting IF returns -27, yet NC is in the array >> list. >> Its random as to which stats work and which do not. AL will return 0, but >> AR >> will return -3, yet its in the list. I know the value when neg (-) is a >> bitwise representation, but most every state in the array list returns a >> neg >> number, Why? >> >> string[] strStateArray = new string[] >> {"AL","AK","AZ","AR","CA","CO","CT","DE","FL","GA","HI","ID","IL","IN","IN","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA","WA","DC","WV","WI","WY"}; >> >> >> if(Array.BinarySearch(strStateArray, State.ToString())<0) >> { >> ValidationStatus="Incoming State is invalid. The follow state >> abrevations are acceptable: " + strStateArray.ToString(); >> } >> >> -- >> JP >> .NET Software Develper > > The elements to be searched by a binary search algorithm must be sorted. > Your failures (AZ, NC, etc) are out of order, and therefore, not found.
More precisely, it looks like the state names, not the abbreviations, were sorted "New York" < "North Carolina" but "NC" < "NY" [quoted text, click to view] > > -- > Peter [MVP Visual Developer] > Jack of all trades, master of none. >
Don't see what you're looking for? Try a search.
|