Solved

VB 2005 Analog to VBA Instr() Function

Posted on 2010-11-19
10
412 Views
Last Modified: 2012-05-10
I have this cool little form in an Access app that allows the user to use sort of a "Thumb Index" to filter a large file of customers. There are 27 buttons - one for each letter, and one with a pound sign on it for customers with names like "123 Plumbing" or "1-800-Ask Gary."

Getting the sql to filter on the first letter is easy. But to get all the clients whose names start with a non-letter, I used this:

If strAlpha = "#" Then 'Number Picked
            strCritString = " WHERE InStr('ABCDEFGHIJKLMNOPQRSTUVWXYZ', UCase(Left([Accounts]![Customer],1))) = 0 "
           
        Else 'Letter Picked
            strCritString = " WHERE UCase(Left([Accounts]![Customer],1))='" & strAlpha & "'"
        End If

Evidently the InStr function in VB 2005 functions a little differently. I just want to be able to test for the case where the "strAlpha" variable is not one of the 26 letters.

THANKS!
0
Comment
Question by:Buck_Beasom
  • 4
  • 3
  • 2
  • +1
10 Comments
 

Expert Comment

by:LVMB1417
ID: 34175980
Substring is what you are looking for

Dim s as String

s = "abcdefghijklmnopqrstuvwxyz"

console.writeline s.Substring(2,1)  

2 is the starting position
1 is the length you want to take

s.substring(2,1) = b
s.substring(2,3) = bcd

etc...



0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34179711
The other option is Not In
" WHERE  UCase(Left([Accounts]![Customer],1)) Not In ('A', 'B', ...) = 0 "
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 250 total points
ID: 34179713
The other option is Not In
" WHERE  UCase(Left([Accounts]![Customer],1)) Not In ('A', 'B', ...)"
0
 
LVL 17

Expert Comment

by:Zhaolai
ID: 34180211
Try this:
If Char.IsNumber(strAlpha.Substring(0, 1)) Then 'Number Picked

Open in new window

0
 

Author Comment

by:Buck_Beasom
ID: 34180811
OK. I am working remote from my house on my work computer, so this is a little difficult to test. But here goes.

LVMB's solution is valuable information, but doesn't get me where I want. If I interpret Zhaolai correctly,  this would work, but only if the 1st character of the customer name is a number. I also have all kinds of other bizarre cases like +, /, # and so on. Some are actually names that begin with those characters and sometimes it's just a typo. (I even have spaces, in a few cases.)

So it looks like Codecatcher's solution is best for my specific need, but I need to confirm. If I continue the SECOND solution you propose so that there are 26 arguments in the "Not In" function - basically each of the 26 regular letters of the alphabet - I'm guessing that will return a list of all those customers that start with a character that is Not In ABCDEFGHIJKLMNOPQRSTUVWXYZ. Of course, I have to list each letter in ' ' and separated by a comma.

Right? (Or is it the first solution?)

THANKS!
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 17

Expert Comment

by:Zhaolai
ID: 34180946
If you want anything not starting with a letter, then try this:
If Not Char.IsLetter(strAlpha.Substring(0, 1)) Then 'Not a Number Picked

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34182997
I think the second option is right for you and yes you will have to add all the alphabets in '' in the "Not In" clause.

My solution is T-SQL based whereas the other solutions are .NET based and I dont know how this line will help you

"If Not Char.IsLetter(strAlpha.Substring(0, 1))"
0
 

Author Comment

by:Buck_Beasom
ID: 34183001
Zhaolai:

That seems a more elegant solution. But I am using the test in an SQL criteria string. So I need something like "WHERE Char.Isletter(UCase(Left([Accounts]![Customer],1))) = False". I will try your solution and see if the SQL gets interpreted properly.

Thanks.
0
 

Author Closing Comment

by:Buck_Beasom
ID: 34196295
After trying all of the various permutations, this was the one that functioned the way I wanted it to in the SQL string.

Thanks!
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34196537
Glad to help.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now