Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Making VB.NET code case insensitive

Posted on 2007-07-30
9
Medium Priority
?
713 Views
Last Modified: 2013-11-26
Hi,

Using VB.NET,  I have following field in my hash table:
Account_Nr and Bankcode.

Now, I later read the values using:
x = htab_Accounts.Item("BankCode")
Now x has value of Nothing. When I did some exploration, I found that because the character case for C in BankCode. Like when I add the field to hastable, I use C in lower case and when I try to read later, I use C in upper case. I do not want my code to be case sensitive. SO I used Tools->Options and set the Option Compare to Text. But still this is not making any difference. Is there any way I can make my code insensitve to char case?

Regards,
MI
0
Comment
Question by:vj_mi
  • 3
  • 2
6 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1000 total points
ID: 19593983
You can add the values to the Hashtable with upper-case values as the key, and then retrieve them this way:

x = htab_Accounts("BANKCODE")

Bob
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 19594056
Hi vj_mi;

Because the HashTable uses a hash function to store the key it can not do a hash function on every combination of characters to check to see if it exist. A work around would be to convert the Key you use for the TashTable to upper case or lower case and when you check to see if there is a key you are looking form convert the string to Upper/Lower case with the string function, for example:

x = htab_Accounts.Item("BankCode".ToUpper())


Fernando
0
 

Author Comment

by:vj_mi
ID: 19615026
It does not work since I check it like this:
if  htab_Accounts.Item("BankCode") ="" then Return.

In this case, because it is case sensitive, the above "if  htab_Accounts.Item("BankCode") " returns Nothing. I found that the same problems are with grid columns. In Vs 2003, they are not case sensitive. I do not know why suddenly in Vs 2005 they are case sensitive. Is there any way I can make my project case-insensitive?

Regards,
MI
0
[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 19616485
If you aren't adding to the Hashtable with an upper-case key, and retrieving with an upper-case key, then it won't work.

Bob
0
 
LVL 64

Assisted Solution

by:Fernando Soto
Fernando Soto earned 1000 total points
ID: 19616953
As TheLearnedOne has stated and I stated in my last post, if you enter a key of BankCode as a key to a HashTable when you access that key to get a value back you must enter the key as BankCode and NOT bankcode or Bankcode or any combination of upper or lower case characters that spells out BankCode. The reason for this is that when the HashTable.Add method is called to add the key/value pair it calculates the position of where to place it in the hash table by the value of the key. The hash function used to calculate the value of the key will be different for values of the same word but different character case. So the hash value of the following words are all different, BankCode, Bankcode, bankcode, BaNkCoDe, ....

So either add all keys as upper case or lower case and access the keys with the same case as you stored them with. The last option is mixed case which means that if you add a key as BankCode you MUST get that key with BankCode.
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 19751114
Hi Bob;

I would like to see a resolution to this question seeming that both experts provided a solution to the problem. I would like to see a point split.

Thanks;

Fernando
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month12 days, 6 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question