473,404 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

left, right & mid functions HELP!

Having a bit of a problem
i need to extract the state code out of a field formated like this.

WEST BEND, WI 53095

I've managed to get the city and zip code in sperate fields using the right and left function in a query but the state is posing a problem because I cant use a mid function becasue the city lengh will change.

shipto3: IIf([id]=37,Left([field1],InStr([field1],",")-1))
my code to extract everything to the left of the comma
any one have an idea to extrac 3 characters to the right of the comma?

Thanks Ben
Dec 20 '07 #1
2 8610
Having a bit of a problem
i need to extract the state code out of a field formated like this.

WEST BEND, WI 53095

I've managed to get the city and zip code in sperate fields using the right and left function in a query but the state is posing a problem because I cant use a mid function becasue the city lengh will change.

shipto3: IIf([id]=37,Left([field1],InStr([field1],",")-1))
my code to extract everything to the left of the comma
any one have an idea to extrac 3 characters to the right of the comma?

Thanks Ben
Identify the constants, i.e. is there always a space between the town name and state abbreviation, then another space between the latter and the zip code? If so, use InStr to find the position of the first space, then a mid function use it again with a nested Mid / Instr combination to find the second space.
Here's a sample

string = "Treated and Discharged"
InStr([string]," ") tells me the first space is the 8th chr.
InStr(Mid([string],(InStr([string]," "))+1)," ") tells me the second space is the 4th character, or the 13th if I add the two together (because I added a chr in the second equation so it wouldn't just return the first space).

From here it's just maths and nesting to use a Mid to extract the string section you want.

For what it's worth I usually resort to doing this 'longhand' first, i.e. create each element as a separate field in a query, then nest them all together as one formula once I've got it all worked out in my head.

HTH
Kevin
Dec 20 '07 #2
missinglinq
3,532 Expert 2GB
If it's always formatted this way, the state portion would be

mid(strA,len([Field1])-7,2)

Welcome to TheScripts!

Linq ;0)>
Dec 20 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: orekinbck | last post by:
Hi There Say I want to check if object1.Property1 is equal to a value, but object1 could be null. At the moment I have code like this: if (object1 != null) { if (object1.Property ==...
1
by: Fred Nelson | last post by:
I'm a newby and I'm writing my first VB.NET print program! I need to change the default left and right margins for my printed output "e" is my "System.Drawing.Printing.PrintPageEventArgs By...
11
by: Bruce A. Julseth | last post by:
I have: If (Microsoft.VisualBasic.Left(TextBox1.Text, 1) = "$") Then TextBox1.Text = Microsoft.VisualBasic.Right(TextBox1.Text, TextBox1.Text.Length - 1) End If Adding: Imports...
19
by: gk245 | last post by:
I have something like this: printf("Enter numbers: "); scanf ("%i", &number); If the user put in a bunch of numbers (like 4568), instead of just one number, i know that you can extract the...
4
by: UJ | last post by:
I have a long list of items that the user will be able to select from. When they select an item, I'd like to have more detailed information appear on the right side of the screen. I've already got...
9
by: sql guy123 | last post by:
I normally use MS ACCESS vs MS SQL,, which has a left() and right() function. I need to use MS SQL for this project but I am not familiar with it. I have read a few books, but can not figure out...
3
by: sck10 | last post by:
Hello, What are the equivalent functions for Right and Left in c#? Thanks, sck10
5
by: Timeri | last post by:
This is a bit confusing until you actually see what I'm talking about but the main content of my page is not growing with the right column. I want the main content (left/larger column) to take into...
3
by: Noorain | last post by:
I designed a site. i want to header,footer,left & right column fixed but body information only scrolling. this site screen to be 800/600 px. i designed this way but when i used position fixed all...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.