Need Help Manipulating Data Within a Field 
Author Message
 Need Help Manipulating Data Within a Field

Here's my problem; I have a field that contains data like this:  BA1037.
I want to take the first letter and combine it with the first two numbers
and create a new field that look like this:  B10.  Any help would be
appreciated.



Sat, 09 Oct 1999 03:00:00 GMT
 Need Help Manipulating Data Within a Field

Quote:

> Here's my problem; I have a field that contains data like this:  BA1037.
> I want to take the first letter and combine it with the first two numbers
> and create a new field that look like this:  B10.  Any help would be
> appreciated.

If the characters are always in the same position than

newField=oldField.substr(1,1)+oldField.substr(3,2)

will do the trick.  However if the numbers will move then
its a bit more tricky!

method run(var eventInfo Event)
var
  i,x  SmallInt
  c,n,
  d    String
endvar

  d=<the field with the data in it>.value
  n=d.substr(1,1); GRAB THE FIRST CHARACTER
  x=0
  for i from 1 to d.size()
    c=d.substr(i,1)
    if ansiCode(c)<58 then
      n=n+string(c)
      x=x+1
    endif
    if x=2 then ; ONLY GET 2 CHARACTERS.
      quitLoop
    endif
  endFor
  n.view()

endmethod

Hope this helps you out

Che



Sat, 09 Oct 1999 03:00:00 GMT
 Need Help Manipulating Data Within a Field

you did not say which version you are using but you can use scan endscan
with substr() on the field as follows

you will need to place the table in edit mode to do this

scan

[newfield]=substr( [oldfield],1,1)+substr( [oldfield],3,2)

endscan

don't forget to end edit after the scan is done

essentially what this does is as follows

scan looks at every record in the table starting with the first record

substr which is sub string is a pdox parsing mechanism where

substr( value to be parsed, starting position, number of position from
starting position to include)

substr( [oldfield],1,1) translates to start at position 1 in field and
capture 1 character in field thus this would capture in your example B

substr( [oldfield],3,2) would grab the 1 and 0

let me know if this helps
--



Quote:
> Here's my problem; I have a field that contains data like this:  BA1037.
> I want to take the first letter and combine it with the first two numbers
> and create a new field that look like this:  B10.  Any help would be
> appreciated.



Sat, 09 Oct 1999 03:00:00 GMT
 Need Help Manipulating Data Within a Field

Quote:
> Here's my problem; I have a field that contains data like this:  
> BA1037. I want to take the first letter and combine it with the first
> two numbers and create a new field that look like this:  B10.

You need to learn about the subString function. Try this:

var
   x,
   FirstChar,
   TwoNum       string
endVar

x = tCursor."FIELD NAME"
FirstChar = subStr(x,1,1)
TwoNum = subStr(x,3,2)
x = FirstChar+TwoNum
x.view("Here's What You Asked For")

Daniel A. Morgan



Sat, 09 Oct 1999 03:00:00 GMT
 
 [ 4 post ] 

 Relevant Pages 

1. need help to manipulate text field in store procedure

2. New User needs help manipulating phone number field

3. Need help with referencing fields within a construct

4. Need help searching for empty date fields within an If statement

5. Manipulating Fields usin VB 5 Data Bound Comtrols

6. NEED TO MANIPULATE PDOXRUN BASED DATA

7. HELP!!!! How to manipulate text fields on triggers

8. Help: Manipulating SQL Server's Binary Fields in VB

9. HELP!!!! How to manipulate text fields in triggers

10. Help: Manipulating SQL Server's Binary Fields in VB

11. need help with manipulating dates

12. Need Help Manipulating Excel 2000 from Access 2000 using VBA


 
Powered by phpBB® Forum Software