restricting values of integers in code
Author 
Message 
Chery #1 / 5

restricting values of integers in code
I received code from someone at this site which involves generating six digit numbers and attaching labels to each, and inserting them in a table. The problem that I have, is that as the code adds 2 to 9, it returns 11 which increases the number of digits of my code. I need to restrict the output to values from 0 to 9. If the number is 9, then it adds 2 and outputs 1; and 8+2=0. I've attached the code I am working with, can someone please help?!? Public Function Set4(suffix, seed) Dim MyArray(4, 4) Dim rs As New ADODB.Recordset Dim a, b, c, d As Integer Dim start As Integer Dim sequence As Integer 'set up possible values to be used in the revolve For a = 1 To 4 start = Val(Mid(seed, 2 + a, 1)) For b = 1 To 4 MyArray(a, b) = start + 2 start = start + 2 Next b Next a sequence = 0 rs.Open "CodeTable", CurrentProject.Connection, adOpenKeyset, adLockOptimistic 'generate the codes and slap them into the table For d = 1 To 4 For c = 1 To 4 For b = 1 To 4 For a = 1 To 4 sequence = sequence + 1 With rs .AddNew !CodeFiledName = suffix & Format(sequence, "000") !Code = Left(seed, 2) & MyArray(1, a) & MyArray(2, b) & MyArray(3, c) & MyArray(4, d) .Update End With Next a Next b Next c Next d End Function .

Sun, 12 Dec 2004 01:24:09 GMT 


MV #2 / 5

restricting values of integers in code
Use the Mod operator in the proper place. 11 mod 10 = 1 21 mod 10 = 1 30 Mod 10 = 0 So probably: !Code = Left(seed, 2) & MyArray(1, a) Mod 10 & MyArray(2,b) Mod 10 & MyArray(3, c) Mod 10 & MyArray(4, d) Mod 10 OR you could probably use the right function since you are treating this as a string !Code = Left(seed, 2) & Right(MyArray(1, a),1) & Right(MyArray(2,b),1) & Right(MyArray(3, c),1) & Right(MyArray(4, d),1) Quote:
> I received code from someone at this site which involves > generating six digit numbers and attaching labels to each, > and inserting them in a table. The problem that I have, is > that as the code adds 2 to 9, it returns 11 which increases > the number of digits of my code. I need to restrict the > output to values from 0 to 9. If the number is 9, then it > adds 2 and outputs 1; and 8+2=0. I've attached the code I > am working with, can someone please help?!? > Public Function Set4(suffix, seed) > Dim MyArray(4, 4) > Dim rs As New ADODB.Recordset > Dim a, b, c, d As Integer > Dim start As Integer > Dim sequence As Integer > 'set up possible values to be used in the revolve > For a = 1 To 4 > start = Val(Mid(seed, 2 + a, 1)) > For b = 1 To 4 > MyArray(a, b) = start + 2 > start = start + 2 > Next b > Next a > sequence = 0 > rs.Open "CodeTable", CurrentProject.Connection, > adOpenKeyset, adLockOptimistic > 'generate the codes and slap them into the table > For d = 1 To 4 > For c = 1 To 4 > For b = 1 To 4 > For a = 1 To 4 > sequence = sequence + 1 > With rs > .AddNew > !CodeFiledName = suffix & Format(sequence, "000") > !Code = Left(seed, 2) & MyArray(1, a) & MyArray(2, > b) & MyArray(3, c) & MyArray(4, d) > .Update > End With > Next a > Next b > Next c > Next d > End Function > .

Sun, 12 Dec 2004 01:46:06 GMT 


Chery #3 / 5

restricting values of integers in code
Thanks. The Right Function works for this procedure. However, do you know of any other way to restrict the values? I have to make another procedure that only uses values 0 through 5. If you can think of anything, please let me know. Quote: >Original Message >Use the Mod operator in the proper place. > 11 mod 10 = 1 > 21 mod 10 = 1 > 30 Mod 10 = 0 >So probably: >!Code = Left(seed, 2) & MyArray(1, a) Mod 10 & >MyArray(2,b) Mod 10 & MyArray(3, c) Mod 10 & MyArray(4, d) Mod 10 >OR you could probably use the right function since you are treating this as a >string >!Code = Left(seed, 2) & Right(MyArray(1, a),1) & > Right(MyArray(2,b),1) & Right(MyArray(3, c),1) & > Right(MyArray(4, d),1)
>> I received code from someone at this site which involves >> generating six digit numbers and attaching labels to each, >> and inserting them in a table. The problem that I have, is >> that as the code adds 2 to 9, it returns 11 which increases >> the number of digits of my code. I need to restrict the >> output to values from 0 to 9. If the number is 9, then it >> adds 2 and outputs 1; and 8+2=0. I've attached the code I >> am working with, can someone please help?!? >> Public Function Set4(suffix, seed) >> Dim MyArray(4, 4) >> Dim rs As New ADODB.Recordset >> Dim a, b, c, d As Integer >> Dim start As Integer >> Dim sequence As Integer >> 'set up possible values to be used in the revolve >> For a = 1 To 4 >> start = Val(Mid(seed, 2 + a, 1)) >> For b = 1 To 4 >> MyArray(a, b) = start + 2 >> start = start + 2 >> Next b >> Next a >> sequence = 0 >> rs.Open "CodeTable", CurrentProject.Connection, >> adOpenKeyset, adLockOptimistic >> 'generate the codes and slap them into the table >> For d = 1 To 4 >> For c = 1 To 4 >> For b = 1 To 4 >> For a = 1 To 4 >> sequence = sequence + 1 >> With rs >> .AddNew >> !CodeFiledName = suffix & Format(sequence, "000") >> !Code = Left(seed, 2) & MyArray(1, a) & MyArray(2, >> b) & MyArray(3, c) & MyArray(4, d) >> .Update >> End With >> Next a >> Next b >> Next c >> Next d >> End Function >> . >.

Sun, 12 Dec 2004 19:25:45 GMT 


MV #4 / 5

restricting values of integers in code
It kind of depends on what you want to do if you have anumber greater than 5. You can use modulo arithmetic, a case statement, an if statement, etc. If you just want to force a number from 0 to 5 and you don't care than you could use the Mod operator. 9 Mod 6 = 3 12 Mod 6 = 0 34 Mod 6 = 4 What Mod does is divide the first number by the modulus number and return the remainder. It uses integer arithmetic (so numbers with a decimal portion get converted to integers (this means the number is rounded up or down to the closest whole number.) Quote:
> Thanks. The Right Function works for this procedure. > However, do you know of any other way to restrict the > values? I have to make another procedure that only uses > values 0 through 5. If you can think of anything, please > let me know. > >Original Message > >Use the Mod operator in the proper place. > > 11 mod 10 = 1 > > 21 mod 10 = 1 > > 30 Mod 10 = 0 > >So probably: > >!Code = Left(seed, 2) & MyArray(1, a) Mod 10 & > >MyArray(2,b) Mod 10 & MyArray(3, c) Mod 10 & MyArray(4, d) > Mod 10 > >OR you could probably use the right function since you are > treating this as a > >string > >!Code = Left(seed, 2) & Right(MyArray(1, a),1) & > > Right(MyArray(2,b),1) & Right(MyArray(3, c),1) & > > Right(MyArray(4, d),1)
> >> I received code from someone at this site which involves > >> generating six digit numbers and attaching labels to > each, > >> and inserting them in a table. The problem that I have, > is > >> that as the code adds 2 to 9, it returns 11 which > increases > >> the number of digits of my code. I need to restrict the > >> output to values from 0 to 9. If the number is 9, then > it > >> adds 2 and outputs 1; and 8+2=0. I've attached the code > I > >> am working with, can someone please help?!? > >> Public Function Set4(suffix, seed) > >> Dim MyArray(4, 4) > >> Dim rs As New ADODB.Recordset > >> Dim a, b, c, d As Integer > >> Dim start As Integer > >> Dim sequence As Integer > >> 'set up possible values to be used in the revolve > >> For a = 1 To 4 > >> start = Val(Mid(seed, 2 + a, 1)) > >> For b = 1 To 4 > >> MyArray(a, b) = start + 2 > >> start = start + 2 > >> Next b > >> Next a > >> sequence = 0 > >> rs.Open "CodeTable", CurrentProject.Connection, > >> adOpenKeyset, adLockOptimistic > >> 'generate the codes and slap them into the table > >> For d = 1 To 4 > >> For c = 1 To 4 > >> For b = 1 To 4 > >> For a = 1 To 4 > >> sequence = sequence + 1 > >> With rs > >> .AddNew > >> !CodeFiledName = suffix & Format(sequence, > "000") > >> !Code = Left(seed, 2) & MyArray(1, a) & > MyArray(2, > >> b) & MyArray(3, c) & MyArray(4, d) > >> .Update > >> End With > >> Next a > >> Next b > >> Next c > >> Next d > >> End Function > >> . > >.

Mon, 13 Dec 2004 01:33:57 GMT 


Chery #5 / 5

restricting values of integers in code
Thanks soooooo much! I was a little hesitant of the Mod function first because I didn't understand it. You have helped me do what our computing staff has been unable to. Thanks again. Quote: >Original Message >It kind of depends on what you want to do if you have
anumber greater than 5. Quote: >You can use modulo arithmetic, a case statement, an if
statement, etc. If you Quote: >just want to force a number from 0 to 5 and you don't care than you could use >the Mod operator. > 9 Mod 6 = 3 > 12 Mod 6 = 0 > 34 Mod 6 = 4 >What Mod does is divide the first number by the modulus
number and return the Quote: >remainder. It uses integer arithmetic (so numbers with a decimal portion get >converted to integers (this means the number is rounded up or down to the >closest whole number.)
>> Thanks. The Right Function works for this procedure. >> However, do you know of any other way to restrict the >> values? I have to make another procedure that only uses >> values 0 through 5. If you can think of anything, please >> let me know. >> >Original Message >> >Use the Mod operator in the proper place. >> > 11 mod 10 = 1 >> > 21 mod 10 = 1 >> > 30 Mod 10 = 0 >> >So probably: >> >!Code = Left(seed, 2) & MyArray(1, a) Mod 10 & >> >MyArray(2,b) Mod 10 & MyArray(3, c) Mod 10 & MyArray(4, d) >> Mod 10 >> >OR you could probably use the right function since you are >> treating this as a >> >string >> >!Code = Left(seed, 2) & Right(MyArray(1, a),1) & >> > Right(MyArray(2,b),1) & Right(MyArray(3, c),1) & >> > Right(MyArray(4, d),1)
>> >> I received code from someone at this site which involves >> >> generating six digit numbers and attaching labels to >> each, >> >> and inserting them in a table. The problem that I have, >> is >> >> that as the code adds 2 to 9, it returns 11 which >> increases >> >> the number of digits of my code. I need to restrict the >> >> output to values from 0 to 9. If the number is 9, then >> it >> >> adds 2 and outputs 1; and 8+2=0. I've attached the code >> I >> >> am working with, can someone please help?!? >> >> Public Function Set4(suffix, seed) >> >> Dim MyArray(4, 4) >> >> Dim rs As New ADODB.Recordset >> >> Dim a, b, c, d As Integer >> >> Dim start As Integer >> >> Dim sequence As Integer >> >> 'set up possible values to be used in the revolve >> >> For a = 1 To 4 >> >> start = Val(Mid(seed, 2 + a, 1)) >> >> For b = 1 To 4 >> >> MyArray(a, b) = start + 2 >> >> start = start + 2 >> >> Next b >> >> Next a >> >> sequence = 0 >> >> rs.Open "CodeTable", CurrentProject.Connection, >> >> adOpenKeyset, adLockOptimistic >> >> 'generate the codes and slap them into the table >> >> For d = 1 To 4 >> >> For c = 1 To 4 >> >> For b = 1 To 4 >> >> For a = 1 To 4 >> >> sequence = sequence + 1 >> >> With rs >> >> .AddNew >> >> !CodeFiledName = suffix & Format(sequence, >> "000") >> >> !Code = Left(seed, 2) & MyArray(1, a) & >> MyArray(2, >> >> b) & MyArray(3, c) & MyArray(4, d) >> >> .Update >> >> End With >> >> Next a >> >> Next b >> >> Next c >> >> Next d >> >> End Function >> >> . >> >. >.

Mon, 13 Dec 2004 02:14:35 GMT 


