PC Review


Reply
Thread Tools Rate Thread

Data String Manipulation

 
 
Jerry
Guest
Posts: n/a
 
      24th Feb 2009
I have a filed on a form that a barcode is being scanned into. The raw scan
contains characters I need to remove. I always need to remove the first
character, then I have to check the first, 6th and tenth sopt for 0 and
remove the first one, then stop. I then have a query that searches a table
for the string. Can this be done in Access? I am guessing it may involve
the instr function in some way, but I am just not sure.

Thanks for any input!
 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      24th Feb 2009
Not sure I really follow, but you'd use the Mid function to look at specific
positions.

Mid([MyString], 1, 1) will give you the content of the first position,
Mid([MyString], 6, 1) will give you the content of the sixth position,
Mid([MyString], 10, 1) will give you the content of the tenth position and
so on.

You can also use the Mid function to remove the first character:

Mid([MyString], 2) will return everything from position 2 on.



--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Jerry" <(E-Mail Removed)> wrote in message
news:79F0D63B-5527-4F71-A21C-(E-Mail Removed)...
>I have a filed on a form that a barcode is being scanned into. The raw
>scan
> contains characters I need to remove. I always need to remove the first
> character, then I have to check the first, 6th and tenth sopt for 0 and
> remove the first one, then stop. I then have a query that searches a
> table
> for the string. Can this be done in Access? I am guessing it may involve
> the instr function in some way, but I am just not sure.
>
> Thanks for any input!



 
Reply With Quote
 
Jerry
Guest
Posts: n/a
 
      24th Feb 2009
Thanks, using the Mid function gets me started. It gets very complicated! I
always need to delete the first character in the scanned string, then Check
the 1st number in the string - if it is 0, remove it to get the 10 digit NDC

路If the 1st number is not a zero, check the 6th - if it is 0, remove it to
get the 10 digit NDC

路If neither the 1st nor the 6th digits are 0, check the 10th digit - if it
is 0, remove it to get the 10 digit NDC

路If a 0 is not the 1st, the 6th, or the 10th character in the string, it is
an invalid 11 digit NDC

Hopefully that makes it a little clearer.

Thanks

"Douglas J. Steele" wrote:

> Not sure I really follow, but you'd use the Mid function to look at specific
> positions.
>
> Mid([MyString], 1, 1) will give you the content of the first position,
> Mid([MyString], 6, 1) will give you the content of the sixth position,
> Mid([MyString], 10, 1) will give you the content of the tenth position and
> so on.
>
> You can also use the Mid function to remove the first character:
>
> Mid([MyString], 2) will return everything from position 2 on.
>
>
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Jerry" <(E-Mail Removed)> wrote in message
> news:79F0D63B-5527-4F71-A21C-(E-Mail Removed)...
> >I have a filed on a form that a barcode is being scanned into. The raw
> >scan
> > contains characters I need to remove. I always need to remove the first
> > character, then I have to check the first, 6th and tenth sopt for 0 and
> > remove the first one, then stop. I then have a query that searches a
> > table
> > for the string. Can this be done in Access? I am guessing it may involve
> > the instr function in some way, but I am just not sure.
> >
> > Thanks for any input!

>
>
>

 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      24th Feb 2009
I'm assuming that your check of positions 1, 6 and 10 really refer to
positions 2, 7 and 11, since you've deleted the first position. (If no, I'm
confused!) I'm also assuming that your incoming string must be 12 characters
long, and that a valid NDC number is 10 characters long.

Function NDC(IncomingString As String) As String
' Returns an NDC, or a zero-length string ("")
' if IncomingString is invalid

If Len(IncomingString) = 12 Then
If Mid(IncomingString, 2, 1) = "0" Then
NDC = Mid(IncomingString, 3)
ElseIf Mid(IncomingString, 7, 1) = "0" Then
NDC = Mid(IncomingString, 2, 5) & _
Mid(IncomingString, 8)
ElseIf Mid(IncomingString, 11, 1) = "0" Then
NDC = Mid(IncomingString, 2, 9) & _
Mid(IncomingString, 12, 1)
End If
End If

End Function

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Jerry" <(E-Mail Removed)> wrote in message
news:8098A8FE-1ACB-48E9-B3DA-(E-Mail Removed)...
> Thanks, using the Mid function gets me started. It gets very complicated!
> I
> always need to delete the first character in the scanned string, then
> Check
> the 1st number in the string - if it is 0, remove it to get the 10 digit
> NDC
>
> 稩f the 1st number is not a zero, check the 6th - if it is 0, remove it to
> get the 10 digit NDC
>
> 稩f neither the 1st nor the 6th digits are 0, check the 10th digit - if it
> is 0, remove it to get the 10 digit NDC
>
> 稩f a 0 is not the 1st, the 6th, or the 10th character in the string, it
> is
> an invalid 11 digit NDC
>
> Hopefully that makes it a little clearer.
>
> Thanks
>
> "Douglas J. Steele" wrote:
>
>> Not sure I really follow, but you'd use the Mid function to look at
>> specific
>> positions.
>>
>> Mid([MyString], 1, 1) will give you the content of the first position,
>> Mid([MyString], 6, 1) will give you the content of the sixth position,
>> Mid([MyString], 10, 1) will give you the content of the tenth position
>> and
>> so on.
>>
>> You can also use the Mid function to remove the first character:
>>
>> Mid([MyString], 2) will return everything from position 2 on.
>>
>>
>>
>> --
>> Doug Steele, Microsoft Access MVP
>> http://I.Am/DougSteele
>> (no e-mails, please!)
>>
>>
>> "Jerry" <(E-Mail Removed)> wrote in message
>> news:79F0D63B-5527-4F71-A21C-(E-Mail Removed)...
>> >I have a filed on a form that a barcode is being scanned into. The raw
>> >scan
>> > contains characters I need to remove. I always need to remove the
>> > first
>> > character, then I have to check the first, 6th and tenth sopt for 0 and
>> > remove the first one, then stop. I then have a query that searches a
>> > table
>> > for the string. Can this be done in Access? I am guessing it may
>> > involve
>> > the instr function in some way, but I am just not sure.
>> >
>> > Thanks for any input!

>>
>>
>>



 
Reply With Quote
 
dymondjack
Guest
Posts: n/a
 
      24th Feb 2009
How about something like this


Function MakeString(Scan As String) As String
Dim Ret As String

'Get rid of the first character
Ret = Mid(Scan, 2, Len(Ret) - 1)

'Check 1st Number for 0
If Mid(Ret, 1, 1) = "0" Then
Ret = Mid(Ret, 2, Len(Ret) - 1)
GoTo Exit_Func
End If

'Check 6th Number
If Mid(Ret, 6, 1) = "0" Then
Ret = Mid(Ret, 1, 5) & Mid(Ret, 6, Len(Ret) - 6)
Goto Exit_Func
End If

'Check 10th Number
If Mid(Ret, 10, 1) = "0" Then
Ret = Mid(Ret, 1, 9) & Mid(Ret, 11, Len(Ret) - 11)
End If

Exit_Func:
MakeString = Ret
Exit Function
End Function


I haven't tried the function, you may have to adjust the Len() subtraction
numbers, but this should get you pretty close.

hth
--
Jack Leach
www.tristatemachine.com

- "First, get your information. Then, you can distort it at your leisure."
- Mark Twain


"Jerry" wrote:

> Thanks, using the Mid function gets me started. It gets very complicated! I
> always need to delete the first character in the scanned string, then Check
> the 1st number in the string - if it is 0, remove it to get the 10 digit NDC
>
> 路If the 1st number is not a zero, check the 6th - if it is 0, remove it to
> get the 10 digit NDC
>
> 路If neither the 1st nor the 6th digits are 0, check the 10th digit - if it
> is 0, remove it to get the 10 digit NDC
>
> 路If a 0 is not the 1st, the 6th, or the 10th character in the string, it is
> an invalid 11 digit NDC
>
> Hopefully that makes it a little clearer.
>
> Thanks
>
> "Douglas J. Steele" wrote:
>
> > Not sure I really follow, but you'd use the Mid function to look at specific
> > positions.
> >
> > Mid([MyString], 1, 1) will give you the content of the first position,
> > Mid([MyString], 6, 1) will give you the content of the sixth position,
> > Mid([MyString], 10, 1) will give you the content of the tenth position and
> > so on.
> >
> > You can also use the Mid function to remove the first character:
> >
> > Mid([MyString], 2) will return everything from position 2 on.
> >
> >
> >
> > --
> > Doug Steele, Microsoft Access MVP
> > http://I.Am/DougSteele
> > (no e-mails, please!)
> >
> >
> > "Jerry" <(E-Mail Removed)> wrote in message
> > news:79F0D63B-5527-4F71-A21C-(E-Mail Removed)...
> > >I have a filed on a form that a barcode is being scanned into. The raw
> > >scan
> > > contains characters I need to remove. I always need to remove the first
> > > character, then I have to check the first, 6th and tenth sopt for 0 and
> > > remove the first one, then stop. I then have a query that searches a
> > > table
> > > for the string. Can this be done in Access? I am guessing it may involve
> > > the instr function in some way, but I am just not sure.
> > >
> > > Thanks for any input!

> >
> >
> >

 
Reply With Quote
 
Jerry
Guest
Posts: n/a
 
      24th Feb 2009
Thanks for the input! I think this gets me close but I am not sureof the
best spot to call the function. Can I call it from a field exit event or is
there a better spot?
 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      24th Feb 2009
If you store only the "raw" number, you can create a query that uses the
function to give you the NDC and then use the query anywhere you would
otherwise have used the table.

Alternatively, only store the NDC. To do this, you'd have them key the "raw"
number into an unbound text box. In the AfterUpdate event of that text box,
you'd call the function to populate the actual NDC field.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Jerry" <(E-Mail Removed)> wrote in message
news:B90B84D0-F5FF-42EE-902F-(E-Mail Removed)...
> Thanks for the input! I think this gets me close but I am not sureof the
> best spot to call the function. Can I call it from a field exit event or
> is
> there a better spot?



 
Reply With Quote
 
Jerry
Guest
Posts: n/a
 
      26th Feb 2009
Git it working! thanks for all of your help!


"Douglas J. Steele" wrote:

> If you store only the "raw" number, you can create a query that uses the
> function to give you the NDC and then use the query anywhere you would
> otherwise have used the table.
>
> Alternatively, only store the NDC. To do this, you'd have them key the "raw"
> number into an unbound text box. In the AfterUpdate event of that text box,
> you'd call the function to populate the actual NDC field.
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Jerry" <(E-Mail Removed)> wrote in message
> news:B90B84D0-F5FF-42EE-902F-(E-Mail Removed)...
> > Thanks for the input! I think this gets me close but I am not sureof the
> > best spot to call the function. Can I call it from a field exit event or
> > is
> > there a better spot?

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: string manipulation - extract various data Stuart McCall Microsoft Access VBA Modules 0 5th Nov 2009 09:26 PM
String manipulation... help needed in making a string proper Anja Microsoft Access VBA Modules 2 26th Oct 2006 10:15 PM
Importing Long String - String Manipulation (INVRPT) (EDI EANCOM 96a) Brian Microsoft Excel Programming 3 9th Feb 2006 03:38 PM
Importing Long String - String Manipulation (EDI EANCOM 96a) Brian Microsoft Excel Programming 6 9th Feb 2006 12:27 PM
Re: String Manipulation Albert D. Kallal Microsoft Access Form Coding 3 25th Aug 2004 08:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:26 AM.