Creating array out of contents of field 
Author Message
 Creating array out of contents of field

Hi...

Example of field:  123-456-789

What I want to do is be able to access the 1st, 3rd, 5th and 7th char of
this field and then add them together ( 1 + 3 + 5 + 7) and then do the
same with the 2nd, 4th, 6th and 8th chars ( 2 + 4 + 6 + 8 ).  I am VERY
new to Visual Basic and have minimal programming skills.  I thought the
easiest way might be to put the contents of the field into an array and
then add them together using a for...next structure but I DON'T KNOW HOW
TO DO THIS!!!!!

Any suggestions or other options would be very, very, very helpful!

THANX in advance.......Connie



Thu, 24 Aug 2000 03:00:00 GMT  
 Creating array out of contents of field

Hi,

you don't _have_ to store that value in an array.  Access has the Mid
function available for you.  Here's a small function
Function fRetChar(ByVal strInString As String, _
                intPos As Integer) As String
    If Not intPos > Len(strInString) Then
        fRetChar = Mid$(strInString, intPos, 1)
    End If
End Function

which will accept the string and the char position which you want to extract
and return it. So you can use it like

strString = "123-456-789"
msgbox fretchar(strString,1) & " " & fretchar(strString,3) _
        & " " & fretchar(strString,5) & " " &  fretchar(strString,7)
'or something similar

which should give you the desired results.  At least if I understand your
requirements properly. :-)

HTH

--
Just my $.001
Dev Ashish
---------------
The Access Web ( http://home.att.net/~dashish )
---------------

Quote:

>Hi...

>Example of field:  123-456-789

>What I want to do is be able to access the 1st, 3rd, 5th and 7th char of
>this field and then add them together ( 1 + 3 + 5 + 7) and then do the
>same with the 2nd, 4th, 6th and 8th chars ( 2 + 4 + 6 + 8 ).  I am VERY
>new to visual basic and have minimal programming skills.  I thought the
>easiest way might be to put the contents of the field into an array and
>then add them together using a for...next structure but I DON'T KNOW HOW
>TO DO THIS!!!!!

>Any suggestions or other options would be very, very, very helpful!

>THANX in advance.......Connie



Thu, 24 Aug 2000 03:00:00 GMT  
 Creating array out of contents of field

Hi Connie

I assume that the field in question is a text field, and that it doesn't
have the "-" characters in the data (otherwise the 4th  and 8th chars whould
be "-").

You can extract the Nth char from a text string S using the Mid function:

    Mid( S, N, 1)

and you can convert a digit char to a numeric value using the Val function:

    Val( "1" ) = 1

So you can use code something like this:

    iSum1 = Val(Mid(S,1,1)) + Val(Mid(S,3,1)) + Val(Mid(S,5,1))
+Val(Mid(S,7,1))

Good luck!
Graham Mandeno [Access MVP]
Alpha Solutions Limited
Auckland, New Zealand

Return mail address is invalid in a vain attempt to reduce spam.

Please post new questions to newsgroups.

Quote:

>Hi...

>Example of field:  123-456-789

>What I want to do is be able to access the 1st, 3rd, 5th and 7th char of
>this field and then add them together ( 1 + 3 + 5 + 7) and then do the
>same with the 2nd, 4th, 6th and 8th chars ( 2 + 4 + 6 + 8 ).  I am VERY
>new to visual basic and have minimal programming skills.  I thought the
>easiest way might be to put the contents of the field into an array and
>then add them together using a for...next structure but I DON'T KNOW HOW
>TO DO THIS!!!!!

>Any suggestions or other options would be very, very, very helpful!

>THANX in advance.......Connie



Fri, 25 Aug 2000 03:00:00 GMT  
 Creating array out of contents of field

Hi Connie

I assume that the field in question is a text field, and that it doesn't
have the "-" characters in the data (otherwise the 4th  and 8th chars whould
be "-").

You can extract the Nth char from a text string S using the Mid function:

    Mid( S, N, 1)

and you can convert a digit char to a numeric value using the Val function:

    Val( "1" ) = 1

So you can use code something like this:

    iSum1 = Val(Mid(S,1,1)) + Val(Mid(S,3,1)) + Val(Mid(S,5,1))
+Val(Mid(S,7,1))

Good luck!
Graham Mandeno [Access MVP]
Alpha Solutions Limited
Auckland, New Zealand

Return mail address is invalid in a vain attempt to reduce spam.

Please post new questions to newsgroups.

Quote:

>Hi...

>Example of field:  123-456-789

>What I want to do is be able to access the 1st, 3rd, 5th and 7th char of
>this field and then add them together ( 1 + 3 + 5 + 7) and then do the
>same with the 2nd, 4th, 6th and 8th chars ( 2 + 4 + 6 + 8 ).  I am VERY
>new to visual basic and have minimal programming skills.  I thought the
>easiest way might be to put the contents of the field into an array and
>then add them together using a for...next structure but I DON'T KNOW HOW
>TO DO THIS!!!!!

>Any suggestions or other options would be very, very, very helpful!

>THANX in advance.......Connie



Fri, 25 Aug 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. storing the contents of an array in a field

2. Storing the contents of an array in a field

3. storing the contents of an array in a field

4. Storing the contents of an array in a field

5. Creating Field Arrays

6. Modifying field contents in Access field

7. The contents of fields on the reports grows outside limits of field width

8. Combo Box array and Text field array synching

9. university EMR send outs

10. on the outs

11. Learning the ins and outs of Peek and Poke

12. How to handle print outs in VB?

 

 
Powered by phpBB® Forum Software