Solved

Foxpro - Searching for numbers in separate column

Posted on 2016-10-03
8
28 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
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
 
LVL 34

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 19

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 41

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 41

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 41

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

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…
A procedure for exporting installed hotfix details of remote computers using powershell
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 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

21 Experts available now in Live!

Get 1:1 Help Now