Solved

Foxpro - Searching for numbers in separate column

Posted on 2016-10-03
8
36 Views
Last Modified: 2016-11-06
Here is my issue:  I have a dbf table with following fields:
Part Number               Orig Information
123                                Seat, 123, Viton
456                                Seat, 04567, Viton

I am trying to flag a field when the Part Number (123) is identified in the original field so that I can easily find items that need to be corrected.  The 456 is incorrectly entered into the Part Number field, it should be 04567 but I need to identify the ones that we need to look at.
0
Comment
Question by:appelonia21
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 41826329
Is the Orig Information always in that format?
If so you can do something like
select * from table1 where [part number] <> mid([Orig Information],7,instr(7,[Orig Information],",")-7)

Open in new window

0
 

Author Comment

by:appelonia21
ID: 41826410
No unfortunately it isn't.  It is a raw data field and can be in any format, I just want to be able to search within it for the match
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 41826431
@I just want to be able to search within it for the match

Are there any sure delimiters? If not you should create some code to check into any string to strip out the value to match

For example this query will select every record where part number is contained into Orig Information
select * from table1 where [Orig Information] LIKE "*"+[Part Number]+"*"

Open in new window

but if let's say every part number into the Orig Information is in format [space]Part No.[comma] (that is   " 04567,") then you could use a query like
select * from table1 where [Orig Information] not LIKE "* "+[Part Number]+",*"

Open in new window

0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 36

Expert Comment

by:PatHartman
ID: 41826552
The ampersand (&) is the standard Access concatenation character.  The plus (+) can be used but it handles nulls differently so unless you need the special treatment of nulls, it is best to stick with standard.
0
 
LVL 20

Assisted Solution

by:crystal (strive4peace) - Microsoft MVP, Access
crystal (strive4peace) - Microsoft MVP, Access earned 100 total points (awarded by participants)
ID: 41826574
not sure if this works in FoxPro, but here is VBA code to pull DIGITS out of a string:
Function GetDigits(psStringWithNumbers As String) As String
'8-6-08 s4p
   Dim sNumber As String _
      , i As Integer _
      , sChar As String * 1
      
   sNumber = ""
   'loop through and only keep numeric characters
   For i = 1 To Len(psStringWithNumbers)
      sChar = Mid(psStringWithNumbers, i, 1)
      If IsNumeric(sChar) Then
         sNumber = sNumber & sChar
      Else
         'comment if you don't want to stop looking
         If Len(sNumber) > 0 Then
            GetDigits = sNumber
            Exit Function
         End If
      End If
   Next i
   GetDigits = sNumber
End Function

Open in new window

0
 
LVL 42

Accepted Solution

by:
pcelba earned 400 total points (awarded by participants)
ID: 41826808
FoxPro allows much easier solution but you should tell what data type is the Part Number column and what is its true name as the "Part Number" looks like a title.

Let say the table is open in the current workarea already and column names are PartNum  and  OrigInfo so you may just SET FILTER to records of your interests:

Following commands shoul dwork independently on the PartNum data type.

*-- Display all rows where the PartNum is inside the OrigInfo:
SET FILTER TO TRANSFORM(PartNum) $ OrigInfo

*-- Display all rows where the PartNum isn't inside the OrigInfo:
SET FILTER TO NOT TRANSFORM(PartNum) $ OrigInfo

*-- Display all rows where the numeric part of OrigInfo is inside the PartNum:
SET FILTER TO CHRTRAN(OrigInfo, CHRTRAN(Originfo, "0123456789", ""), "") $ TRANSFORM(partNum)

*-- Display all rows where the numeric part of OrigInfo isn't inside the PartNum:
SET FILTER TO NOT CHRTRAN(OrigInfo, CHRTRAN(Originfo, "0123456789", ""), "") $ TRANSFORM(partNum)

*-- Clear the filter
SET FILTER TO

You may display the data by BROWSE command after you set the filter.

The TRANSFORM() function converts possible numeric value in the PartNum into a text, the double CHRTRAN() use will remove all nonnumeric characters from the text. The $ operator tests the string for a substring occurence.

But I am saying again: post right column names and data types to allow us to help better.
0
 
LVL 42

Expert Comment

by:pcelba
ID: 41847240
The only solution or help suitable for FoxPro environment is in the post https:#a41826808. It explains how to define filters on the data in question to display data which follow given filter condition.

Other answers did not reflect FoxPro environment so they cannot work.

appelonia21, if you have additional questions to this subject ask then, if not then please close the question and mark the solution.
0
 
LVL 42

Expert Comment

by:pcelba
ID: 41875976
Unfortunately, just one correct solution suitable for FoxPro was provided. Other solutions do not work correctly in FoxPro or they suppose FoxPro knows VBA etc. Assisted points were assigned for the good Access solution.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to fix orphan DBF 9 647
VFP9 wscript.shell .run won't work with task scheduler 9 618
Mysql Search for contact 6 242
Can't Build Exe in VFP9 8 390
Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
This article discusses how to implement server side field validation and display customized error messages to the client.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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