访问VBA-创建文本框公式检查(检查最后一位) [英] Access VBA - create Textbox formula check (check last digit)

查看:123
本文介绍了访问VBA-创建文本框公式检查(检查最后一位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用VBA中的公式为文本框中的输入值创建一些Number字段检查,但什至不知道如何开始.这是示例:

I have to create some Number field-check of entered values in Textbox with formula in VBA, but don't know how to even start. Here is example:

文本框字段值-132549

Textbox field value - 132549

  1. 您排除了6,因此您使用了13254
  2. 然后您进行乘积运算并与其他数字求和,例如: 4 * 2 + 5 * 3 + 2 * 3 + 3 * 4 + 1 * 5 = 46

  1. you exclude 6, so you use 13254
  2. then you do product and sum with other numbers like: 4*2 + 5*3 + 2*3 + 3*4 + 1*5 = 46

然后您执行46 mod 11 = 2

then you do 46 mod 11 = 2

然后11减2 = 9,并且这里的结果必须与最后一位数字匹配(在此示例中,最后一位数字是正确的)

then 11 minus 2 = 9 and result here must match last digit (in this example last digit is correct)

我是一名中级VBA程序员,但这让我头疼.任何建议,不胜感激!

I'm an intermediate VBA programmer, but this is over my head. Any advice much appreciated !

推荐答案

我自己解决了它-我知道这看起来有些幼稚,但可以正常工作.

I have solved It on my own - I know this looks a bit childish, but It works as It should.

  Sub test()

        Dim Seven As Integer
        Dim Six As Integer
        Dim Five As Integer
        Dim Four As Integer
        Dim Three As Integer
        Dim Two As Integer
        Dim One As Integer

        Dim Seven_Sum As Integer
        Dim Six_Sum As Integer
        Dim Five_Sum As Integer
        Dim Four_Sum As Integer
        Dim Three_Sum As Integer
        Dim Two_Sum As Integer
        Dim One_Sum As Integer

        Dim All_Sum As Integer
        Dim Do_Modulus As Integer
        Dim Check_Digit As Integer

        Seven = Mid(Text0, 7, 1)
        Seven_Sum = Seven * 2

        Six = Mid(Text0, 6, 1)
        Six_Sum = Six * 3

        Five = Mid(Text0, 5, 1)
        Five_Sum = Five * 4

        Four = Mid(Text0, 4, 1)
        Four_Sum = Four * 5

        Three = Mid(Text0, 3, 1)
        Three_Sum = Three * 6

        Two = Mid(Text0, 2, 1)
        Two_Sum = Two * 7

        One = Mid(Text0, 1, 1)
        One_Sum = One * 8

        All_Sum = Seven_Sum + Six_Sum + Five_Sum + Four_Sum + Three_Sum + Two_Sum + One_Sum

        Do_Modulus = All_Sum Mod 11
        Check_Digit = 11 - Do_Modulus

'Finally check for correct serial number validation based on last digit in Textbox
        If Mid(Text0, 8, 1) <> Check_Digit Then

        MsgBox "This serial number is faulty. Last digit of this entered serial number should be :" & Check_Digit
        End If

        End Sub

这篇关于访问VBA-创建文本框公式检查(检查最后一位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆