需要帮助解析一个字符串 - 反向Val? [英] Need help parsing a string - reverse Val?

查看:98
本文介绍了需要帮助解析一个字符串 - 反向Val?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实施一些可以加速数据输入的东西。我希望
能够接受一个字符串,并且只增加最右边的
数字字符。此字段中的数据的类型结构可能会有所不同。这是一个机械设备清单,它是如何指定的b $ b b根据客户标记的方式而有所不同。对于

的例子,他们的设备列表可能如下:


CH-1

CH-2

CH-3


或者它可能是


AH-1-1

AH- 1-2

AH-1-3

甚至


FC-1-1G
FC-1-2G

FC-1-3G


并且有时会更加模糊,但是我会在

中说至少75%的时间,字符串中最右边的数字部分将如上所述增加
。似乎我需要的是以某种方式获得

Val函数从右到左阅读(它确实停在破折号,

对吗?),拉出那个数字,增加它,然后将其推回到

字符串中。我已经设置了我的表单,以便该字段自动填充上一条记录中的值(因此它们只需要

进入并编辑该数字到是正确的,而不是键入整个

字符串),但我想做的也是双击

的执行代码,它将取值那个字段,并执行上面的递增

(当单位跳过
时,它会有一个额外的优势......只需双击两次)。


有什么想法吗?


谢谢!

I''m trying to implement something that would speed up data entry. I''d
like to be able to take a string, and increment ONLY the right-most
numerical characters by one. The type structure of the data that is in
this field can vary. It''s a list of mechanical equipment, and how it
is designated varies based on how the customer has them labeled. For
example, a list of their equipment might look like:

CH-1
CH-2
CH-3

or it might be

AH-1-1
AH-1-2
AH-1-3

or even

FC-1-1G
FC-1-2G
FC-1-3G

And there will be times where it''s even more obscure, but I''d say at
least 75% of the time, the right-most numerical part of the string will
increment like above. It seems that what I need is to somehow get the
Val function to read from right to left (it does stop at dashes,
right?), pull out that number, increment it, then shove it back in the
string. I already have my form set up so that the field automatically
populates with the value from the previous record (so they only have to
go in & edit the number to be correct instead of typing the entire
string), but what I''d like to do is also implent code on a double-click
that will take the value of that field, and do the above incrementing
(which would have the added advantage of making it easy when units are
skipped... just double-click twice).

Any ideas?

Thanks!

推荐答案

这似乎是towork


函数IncrLast(RHS As String)as String

Dim intInstr As Integer

Dim strLeft As String

Dim strRight As String

Dim strAlpha As String

Dim intNumber As Integer


intInstr = InStrRev(RHS, - ,比较:= vbBinaryCompare)


st rLeft = left(RHS,intInstr)

strRight = Mid(RHS,intInstr + 1)

intNumber = Val(strRight)

strAlpha =中(strRight,Len(intNumber))

intNumber = intNumber + 1


IncrLast = strLeft& intNumber& strAlpha

结束功能


测试值

?IncrLast(" CH-1")

CH-2

?IncrLast(AH-1-1)

AH-1-2

?IncrLast(" FC-1-1G")

FC-1-2G


-

Terry Kreft

MVP Microsoft Access

< go **** @ darincline.com>在消息中写道

news:11 ********************** @ g49g2000cwa.googlegr oups.com ...
This seems towork

Function IncrLast(RHS As String) as String
Dim intInstr As Integer
Dim strLeft As String
Dim strRight As String
Dim strAlpha As String
Dim intNumber As Integer

intInstr = InStrRev(RHS, "-", Compare:=vbBinaryCompare)

strLeft = left(RHS, intInstr)
strRight = Mid(RHS, intInstr + 1)
intNumber = Val(strRight)
strAlpha = Mid(strRight, Len(intNumber))
intNumber = intNumber + 1

IncrLast = strLeft & intNumber & strAlpha
End Function

Test values
?IncrLast("CH-1")
CH-2
?IncrLast("AH-1-1")
AH-1-2
?IncrLast("FC-1-1G")
FC-1-2G

--
Terry Kreft
MVP Microsoft Access
<go****@darincline.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
我正在尝试实施一些可以加速数据输入的东西。我希望能够取一个字符串,并且只增加最右边的数字字符。此字段中数据的类型结构可能有所不同。这是一个机械设备清单,它的指定方式因客户标记的方式而异。例如,他们的设备清单可能如下:

CH-1
CH-2
CH-3

或它可能是AH-1-1
AH-1-2
AH-1-3

甚至

FC-1-1G
FC-1-2G
FC-1-3G

有时甚至会更加模糊,但我至少在75%的时间里说,字符串中最右边的数字部分会像上面那样增加。看来我需要的是以某种方式让
Val函数从右向左读取(它确实在破折号处停止,
对吗?),拉出该数字,递增它,然后将其推回在
字符串中。我已经设置了表单,以便字段自动填充上一条记录中的值(因此它们只需要进入并编辑数字是正确的,而不是键入整个
string),但是我想要做的还是双击
的执行代码,它将获取该字段的值,并执行上面的递增
(这将具有在单位被忽略时使其变得简单的额外优势......只需双击两次)。

任何想法?

谢谢!
I''m trying to implement something that would speed up data entry. I''d
like to be able to take a string, and increment ONLY the right-most
numerical characters by one. The type structure of the data that is in
this field can vary. It''s a list of mechanical equipment, and how it
is designated varies based on how the customer has them labeled. For
example, a list of their equipment might look like:

CH-1
CH-2
CH-3

or it might be

AH-1-1
AH-1-2
AH-1-3

or even

FC-1-1G
FC-1-2G
FC-1-3G

And there will be times where it''s even more obscure, but I''d say at
least 75% of the time, the right-most numerical part of the string will
increment like above. It seems that what I need is to somehow get the
Val function to read from right to left (it does stop at dashes,
right?), pull out that number, increment it, then shove it back in the
string. I already have my form set up so that the field automatically
populates with the value from the previous record (so they only have to
go in & edit the number to be correct instead of typing the entire
string), but what I''d like to do is also implent code on a double-click
that will take the value of that field, and do the above incrementing
(which would have the added advantage of making it easy when units are
skipped... just double-click twice).

Any ideas?

Thanks!



优秀!第一次通过似乎有效,除非你到达10。它

想要使下一个数字110.事实上,它开始失败

比单身更多数字。我不是很擅长这些功能,我需要全神贯注地看看他们做什么看看

如果我能理解什么是'正在发生。

Excellent! First pass seems to work, EXCEPT once you get to 10. It
wants to make the next number 110. In fact, it starts to fail on
anything more than single digit numbers. I''m not very good at all
these functions, I need to look them all up to see what they do to see
if I can understand what''s happening.


好的,现在我看到InStrRev做了什么,这可能是问题的一部分

(将会是对于不使用 - 的其他格式,如AHU1。我

假设破折号的定义位置是导致
$ b $的原因b一旦增加的数字部分超过一位数就会增加数字。我将不得不消化更多。

Ok, now that I see what InStrRev does, that may be part of the problem
(and will be for other formats that don''t use a "-", like AHU1. I
assume that the defined position of the dash is what''s causing the
numbers to grow once the numeric portion that is being incremented gets
past a single digit. I''ll have to digest some more.


这篇关于需要帮助解析一个字符串 - 反向Val?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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