473,395 Members | 1,677 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,395 software developers and data experts.

Search String for Return Value

I once again come before you all to request assistance.

I have a lengthy String of Data Of which I would like to create new Columns for.

Example:
[Description] = "1, Bob, Brown, 58, Argyle, Big Jacket"

I would like to search that string for "Brown" and Return that value into a new Column called [Color].

"Brown" can appear anywhere in that string.

I have tried a combination of iif and instr to no success.
Expand|Select|Wrap|Line Numbers
  1. Color: IIf(InStr(Null,[Description],"Brown",1),"BROWN","magic")
Thank you
Mar 16 '09 #1
6 2092
In case others were wondering, I got it to work with:

Expand|Select|Wrap|Line Numbers
  1. Color: IIf(InStr([Description],"Brown")>1,"Brown","Miss")
It will return the Color into a new field.

However, this does not address the issues when another color is there, since the return values are Numerical.

Any ideas?
Mar 16 '09 #2
DonRayner
489 Expert 256MB
This should give you a starting point. It will ignore case but not spelling errors.

Expand|Select|Wrap|Line Numbers
  1. Dim vSource As Variant, vData As Variant
  2. Dim sResult As String, sSource As String, sData As String
  3. sSource = REPLACE
  4. sData = "Blue, Brown, Green, Black"
  5. For Each vSource In Split(sSource, ",")
  6.     For Each vData In Split(sData, ",")
  7.         If Trim(vSource) = Trim(vData) Then
  8.             sResult = Trim(vSource)
  9.         End If
  10.     Next vData
  11. Next vSource
Replace "REPLACE" with whatever your source is. You will have to enter all possible colours in sData or set sData = to whatever you use as the source for your colour list. Output will be sResult as a string.
Mar 17 '09 #3
NeoPa
32,556 Expert Mod 16PB
I should warn you that searching in this way is fundamentally prone to problems and mistakes. Values of one type too often match values for another. In this case consider data for surnames and colour. How would you determine which it were if you found the value "Brown" in the data. This is a fundamentally poor way to manage data I'm afraid.

If this has been imposed upon you (often the case here with such questions), then you need to consider reporting back that this is inherently flawed and they will suffer ultimately if they persist in forcing this approach.
Mar 17 '09 #4
DonRaynor, Thank You - I will give it a try.

---

NeoPa, I understand your concern as I addressed them myself. They have told me that they will validate their data beforehand. I have to try and make it work unfortunately.

Thanks - I will update will any results.
Mar 17 '09 #5
OldBirdman
675 512MB
If the search counts the number of times a color is found, and it is not 1, then the record should be rejected. This should address NeoPa's concern.

Color list will probably have to be a table, as list will go beyond the 11 simple colors to Teal, Peach, Scarlet, Forest, and anything else a sales dept. can come up with.
Mar 17 '09 #6
DonRayner
489 Expert 256MB
@OldBirdman
Also much easier to add another record to a lookup table rather than having to edit your VBA when they add a new color. You could then request an excel spreadsheet with all their possible colors listed and import the data your database as the lookup table.
Mar 17 '09 #7

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

Similar topics

0
by: todd | last post by:
here is a search tool SP I wrote. How many times have you wanted to search all your Stored procs or views (in a database) for a keyword but couldn't!? Well now you can! THis can makes life a...
22
by: Phlip | last post by:
C++ers: Here's an open ended STL question. What's the smarmiest most templated way to use <string>, <algorithms> etc. to turn this: " able search baker search charlie " into this: " able...
4
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working,...
1
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and...
31
by: lovecreatesbeauty | last post by:
Any comments are welcome for following the two sequential search C functions of both integer and string versions. Though they are simple, please do not laugh at it :) Could you give your great...
1
by: Eric | last post by:
Hi: I have two files. I search pattern ":" from emails text file and save email contents into a database. Another search pattern " field is blank. Please try again.", vbExclamation + vbOKOnly...
5
by: int main(void) | last post by:
Hi all, Following is my attempt to write a string search and replace function. #include <stdio.h> #include <stdlib.h> #include <string.h>...
4
by: BenCoo | last post by:
Hello, In a Binary Search Tree I get the error : Object must be of type String if I run the form only with the "Dim bstLidnummer As New BinarySearchTree" it works fine. Thanks for any...
0
by: coosa | last post by:
Dear all; My code is is a bit long but is modular at least. I'm attempting to implement the depth first search for an application that is supposed to: 1- Fetch based on an ID from the database a...
2
by: slizorn | last post by:
hi guys, i need to make a tree traversal algorithm that would help me search the tree.. creating a method to search a tree to find the position of node and to return its pointer value basically i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.