|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 31 楼』:
使用 LLM 解释/回答一下
PS:vbs的速度应该很快……具体多少我没有数据,你自己测试下吧。
PS: The speed of vbs should be quite fast... I don't have specific data, you can test it yourself.
|
|
2008-2-1 03:26 |
|
|
dhlmdsnw
初级用户
 
积分 127
发帖 59
注册 2008-1-29
状态 离线
|
『第 32 楼』:
使用 LLM 解释/回答一下
非常感谢slore大大的帮忙,用了大大的代码还会产生以下的小问题:
请再帮助看看:
1.OutStr = OutStr & "14080005020214080100112003624143" & AddZero(i,6)
OutStr = OutStr & "00000000001775000000000000000000072 " '你上面是不是写漏了2? 2的含义不清。
真不好意思是我漏写了一个1,2代表明细行,1代表汇总行。应该是如下:
OutStr = OutStr & "114080005020214080100112003624143" & AddZero(i,6)
OutStr = OutStr & "00000000001775000000000000000000072 "
2.另外我最后一行汇总行的17750不是固定是变动的,规则如下:
b文件中的最后一行是汇总行,在这个例子中只有三个地方有变动,一个是顺序号:8,一个是汇总数据:17750,一个是汇总编号:7。也就是说前面114080005020214080100112003624143是固定的,后面的000008是变动的,是前面一行000007流水号往下填的(例如:前面一行是000011,后面一行这个地方就是000012,如果前面一行是000111,那这个地方就变成000112),再后面的00是固定的,而后面的00000000177500又是变动的,00000000177500是前面所有行对应位置数据的汇总数如(第1行对应位置的数据是000000000270200+第1行对应位置的数据是000000000250000+....+第7行对应位置的数据是000000000250000=00000000177500),再后面的000000000000000007是变动的,用来表示前面总共有几行(例如:除最后一行外,前面总共有100行,那这个位置数据就该为000000000000000100),最后的2 (包括空白)都是固定的。
3.用大大代码生成的每一行,名字后面的空白的字节都没有了,关于“名字+后面的空白字节”的规则如下:
需要的是这样的结果:“名字+后面的空白”全部选中,然后把它复制粘贴到Excel的单元格中,用函数len来验证,如果名字是两个字的,“名字+后面的空白”len的返回值是51;如果名字是三位数的,“名字+后面的空白”len的返回值是50;如果名字是四位数的,“名字+后面的空白”len的返回值是49。
最后一行汇总行,最后一个数据2后面所需的空白数,用Excel的len函数返回值来表示是需要82个字节。
上面的细节全部处理后,所产生的文件用Ctrl+A全选后,蓝色的光幕是填满每一行,没有任何的空白,每一行的字节在文本文件中应该是相等的。
还请大大继续帮我改善这个代码!
고 맙 습 니 다 !!
Thank you very much for the help from user slore. After using the code from you, the following small issues occur:
Please help take a look again:
1. OutStr = OutStr & "14080005020214080100112003624143" & AddZero(i,6)
OutStr = OutStr & "00000000001775000000000000000000072 " 'Is there a missing 2 above? The meaning of 2 is unclear.
I'm really sorry that I missed writing a 1. 2 represents the detailed line, and 1 represents the summary line. It should be as follows:
OutStr = OutStr & "114080005020214080100112003624143" & AddZero(i,6)
OutStr = OutStr & "00000000001775000000000000000000072 "
2. In addition, the 17750 in the last summary line of my file is not fixed but variable. The rules are as follows:
The last line in file b is the summary line. In this example, there are only three places that change. One is the sequence number: 8, one is the summary data: 17750, and one is the summary number: 7. That is to say, the preceding 114080005020214080100112003624143 is fixed. The following 000008 is variable and is filled in sequentially from the serial number of the previous line (for example: if the previous line is 000011, this place in the next line is 000012; if the previous line is 000111, this place becomes 000112). Then the following 00 is fixed. And the following 00000000177500 is variable. 00000000177500 is the summary number of the corresponding positions of all previous lines (for example: the data of the corresponding position of line 1 is 000000000270200 + the data of the corresponding position of line 1 is 000000000250000 +.... + the data of the corresponding position of line 7 is 000000000250000 = 00000000177500). Then the following 000000000000000007 is variable, which is used to represent the total number of previous lines (for example: if there are 100 lines before the last line, this position data should be 000000000000000100). The final 2 (including the blank) are all fixed.
3. In each line generated by your code, the blank bytes after the name are gone. The rule for "name + subsequent blank bytes" is as follows:
What is needed is the result that "name + subsequent blank" is all selected, and then copy and paste it into the cell of Excel. Use the function len to verify. If the name is two characters, the return value of len for "name + subsequent blank" is 51; if the name is three characters, the return value of len for "name + subsequent blank" is 50; if the name is four characters, the return value of len for "name + subsequent blank" is 49.
For the last summary line, the number of blank bytes needed after the last data 2 is represented by the return value of the len function in Excel as 82 bytes.
After all the above details are processed, the generated file, when all selected with Ctrl+A, the blue screen is filled for each line without any blank, and the number of bytes in each line should be equal in the text file.
Please continue to improve this code for me!
Thank you very much!
|
|
2008-2-1 11:30 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 33 楼』:
使用 LLM 解释/回答一下
会VBA看不懂?自己不能适当的修改下。。。你起的真早。。。
Example2+.vbs:
Const ForReading = 1 '设定打开文本方式为读取
Const ForWriting = 2 '设定打开文本方式为写入
Const ForAppending = 8 '设定打开文本方式为追加
Const InFile = "a.txt" '设定打开的文本
Dim i,Sum
Dim StrLine,OutStr
i = 1:Sum = 0
'On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject") '引用FSO对象,读写文件要用到的
Set objFile = objFSO.OpenTextFile(InFile, ForReading) '以读取方式打开InFile
Do Until objFile.AtEndOfStream
StrLine = objFile.ReadLine '读取一行
If Len(StrLine) Then '如果不是空行
StrLine = FixStr(StrLine)
NeedData = Split(StrLine," ")
If Right(NeedData(1),1) = "*" Then NeedData(1) = Left(NeedData(1),Len(NeedData(1)) - 1)
NeedData(4) = NeedData(4) & Space(53 - Len(NeedData(4)))
OutLine = "2140800050202" & NeedData(1) & "3" & AddZero(i,6) & "00" & NeedData(2)
OutLine = OutLine & "000000000000000011 " & AddZero(i - 1,9) & NeedData(4)
OutStr = OutStr & OutLine & vbCrLf
i = i + 1
Sum = Sum + CLng(NeedData(2))
End If
Loop
OutStr = OutStr & "14080005020214080100112003624143" & AddZero(i,6)
OutStr = OutStr & "00" & AddZero(Sum,15) & "0000000" & AddZero(i - 1,9) & "2" & Space(82)
objFile.Close '关闭文件对象
OutFile = "140820" & FormatDate(Date) & "001.txt"
Set objFile = objFSO.OpenTextFile(OutFile, ForWriting,True) '以写入方式打开OutFile
objFile.Write OutStr
objFile.Close '关闭文件对象
Set objFile = Nothing
Set objFSO = Nothing
Function FixStr(StrExp)
Do While InStr(StrExp," ")
StrExp = Replace(StrExp," "," ")
Loop
FixStr = StrExp
End Function
Function FormatDate(tDate)
FormatDate = Right(Year(tDate),2) & AddZero(Month(tDate),2) & AddZero(Day(tDate),2)
End Function
Function AddZero(sNum,iLen)
Addzero = Right("000000000" & sNum,iLen)
End Function
Can't understand VBA? Can't modify it appropriately by yourself... You get up really early...
Example2+.vbs:
Const ForReading = 1 'Set the text opening mode to read
Const ForWriting = 2 'Set the text opening mode to write
Const ForAppending = 8 'Set the text opening mode to append
Const InFile = "a.txt" 'Set the text to open
Dim i,Sum
Dim StrLine,OutStr
i = 1:Sum = 0
'On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject") 'Reference the FSO object, which is needed for reading and writing files
Set objFile = objFSO.OpenTextFile(InFile, ForReading) 'Open InFile in read mode
Do Until objFile.AtEndOfStream
StrLine = objFile.ReadLine 'Read a line
If Len(StrLine) Then 'If it's not an empty line
StrLine = FixStr(StrLine)
NeedData = Split(StrLine," ")
If Right(NeedData(1),1) = "*" Then NeedData(1) = Left(NeedData(1),Len(NeedData(1)) - 1)
NeedData(4) = NeedData(4) & Space(53 - Len(NeedData(4)))
OutLine = "2140800050202" & NeedData(1) & "3" & AddZero(i,6) & "00" & NeedData(2)
OutLine = OutLine & "000000000000000011 " & AddZero(i - 1,9) & NeedData(4)
OutStr = OutStr & OutLine & vbCrLf
i = i + 1
Sum= Sum+ CLng(NeedData(2))
End If
Loop
OutStr = OutStr & "14080005020214080100112003624143" & AddZero(i,6)
OutStr = OutStr & "00" & AddZero(Sum,15) & "0000000" & AddZero(i - 1,9) & "2" & Space(82)
objFile.Close 'Close the file object
OutFile = "140820" & FormatDate(Date) & "001.txt"
Set objFile = objFSO.OpenTextFile(OutFile, ForWriting,True) 'Open OutFile in write mode
objFile.Write OutStr
objFile.Close 'Close the file object
Set objFile = Nothing
Set objFSO = Nothing
Function FixStr(StrExp)
Do While InStr(StrExp," ")
StrExp = Replace(StrExp," "," ")
Loop
FixStr = StrExp
End Function
Function FormatDate(tDate)
FormatDate = Right(Year(tDate),2) & AddZero(Month(tDate),2) & AddZero(Day(tDate),2)
End Function
Function AddZero(sNum,iLen)
Addzero = Right("000000000" & sNum,iLen)
End Function
|
|
2008-2-1 12:31 |
|
|
dhlmdsnw
初级用户
 
积分 127
发帖 59
注册 2008-1-29
状态 离线
|
『第 34 楼』:
使用 LLM 解释/回答一下
sorry,大大,小妹的VBA也是很菜的啦。。。刚入门啊。。。还在学当中啊。。。不能说会啊。。。也是半路出家啊。。。刚学了三个月,前面都是教在Excel中怎么操作,到目前才学到文本导入导出这方面的知识啊。。。还未试,听了大大的教训,惶恐中。。。先回了大大。。
努力学习中。。。以后还要大大继续帮助啊!
测试中。。。
고 맙 습 니 다 !!
Sorry, big brother, my VBA is also very amateurish. I just started learning. I'm still in the process of studying. I can't say I can do it. I also came into this halfway. I just started learning for three months. At first, it was all about how to operate in Excel. So far, I've only learned about text import and export knowledge. I haven't tried it yet. After hearing your lesson, I'm very apprehensive. I'll reply to you first.
Studying hard. In the future, I still need big brother to continue to help!
Testing...
감사합니다!
|
|
2008-2-1 12:54 |
|
|
dhlmdsnw
初级用户
 
积分 127
发帖 59
注册 2008-1-29
状态 离线
|
『第 35 楼』:
使用 LLM 解释/回答一下
报告slore大大,用了大大的代码,虽然出现了一些小问题,但受大大点拨许多,这点小问题还是决定要自己努力克服,要不然怎么会进步呢。。。埋头了半天,终于明白了主要原因所在,len函数在Excel2000中应用,一个汉字,它的返回值是1,而在文本文件中一个汉字是占两位字节的。虽然结果出来可能会被大大们嗤之以鼻,但是毕竟是我自己总结的,也向大大说明,我也是积极的在努力学习中,而不是一个只要代码的懒人,同时在埋头研究大大的代码过程中,也是学到许多精华。。。现把个人稍微修改后的代码上传:
Const ForReading = 1 '设定打开文本方式为读取
Const ForWriting = 2 '设定打开文本方式为写入
Const ForAppending = 8 '设定打开文本方式为追加
Const InFile = "a.txt" '设定打开的文本
Dim i,Sum
Dim StrLine,OutStr
i = 1:Sum = 0
'On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject") '引用FSO对象,读写文件要用到的
Set objFile = objFSO.OpenTextFile(InFile, ForReading) '以读取方式打开InFile
Do Until objFile.AtEndOfStream
StrLine = objFile.ReadLine '读取一行
If Len(StrLine) Then '如果不是空行
StrLine = FixStr(StrLine)
NeedData = Split(StrLine," ")
If Right(NeedData(1),1) = "*" Then NeedData(1) = Left(NeedData(1),Len(NeedData(1)) - 1)
NeedData(4) = NeedData(4) & Space(53 - Len(NeedData(4))*2)
OutLine = "2140800050202" & mid((NeedData(1) & space(10)),1,19) & "3" & AddZero(i,6) & "00" & NeedData(2)
OutLine = OutLine & "000000000000000011 " & AddZero(i - 1,9) & NeedData(4)
OutStr = OutStr & OutLine & vbCrLf
i = i + 1
Sum = Sum + CLng(NeedData(2))
End If
Loop
OutStr = OutStr & "114080005020214080100112003624143" & AddZero(i,6)
OutStr = OutStr & "00" & AddZero(Sum,15) & "0000000" & AddZero(i - 1,10) & "2" & Space(82)
objFile.Close '关闭文件对象
OutFile = "140800050" & FormatDate(Date) & "001.txt"
Set objFile = objFSO.OpenTextFile(OutFile, ForWriting,True) '以写入方式打开OutFile
objFile.Write OutStr
objFile.Close '关闭文件对象
Set objFile = Nothing
Set objFSO = Nothing
Function FixStr(StrExp)
Do While InStr(StrExp," ")
StrExp = Replace(StrExp," "," ")
Loop
FixStr = StrExp
End Function
Function FormatDate(tDate)
FormatDate = Right(Year(tDate),2) & AddZero(Month(tDate),2) & AddZero(Day(tDate),2)
End Function
Function AddZero(sNum,iLen)
Addzero = Right("00000000000" & sNum,iLen)
End Function
真的非常感谢slore大大对我帮助。。请大大务必在以后继续给我以帮助。。。谢了先!
本问题已经解决了,谢谢各位大大们的关注与支持。
고 맙 습 니 다 !!
努力学习中。。。。
Report to Great Slore, I used the great's code. Although some small problems occurred, with the great's guidance, I have learned a lot. These small problems are determined to be overcome by myself. Otherwise, how can I make progress... After working hard for a long time, I finally understood the main reason. The return value of the Len function when applied in Excel 2000 is 1 for one Chinese character, while one Chinese character occupies two bytes in a text file. Although the result may be scorned by the greats, after all, it is my own summary. I also explain to the great that I am actively studying, not just a lazy person who only wants code. At the same time, I have learned many essences while studying the great's code... Now I upload the slightly modified code of myself:
Const ForReading = 1 'Set the way to open the text as reading
Const ForWriting = 2 'Set the way to open the text as writing
Const ForAppending = 8 'Set the way to open the text as appending
Const InFile = "a.txt" 'Set the text to be opened
Dim i, Sum
Dim StrLine, OutStr
i = 1: Sum = 0
'On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject") 'Reference the FSO object, which is needed for reading and writing files
Set objFile = objFSO.OpenTextFile(InFile, ForReading) 'Open InFile in reading mode
Do Until objFile.AtEndOfStream
StrLine = objFile.ReadLine 'Read a line
If Len(StrLine) Then 'If it is not an empty line
StrLine = FixStr(StrLine)
NeedData = Split(StrLine, " ")
If Right(NeedData(1), 1) = "*" Then NeedData(1) = Left(NeedData(1), Len(NeedData(1)) - 1)
NeedData(4) = NeedData(4) & Space(53 - Len(NeedData(4)) * 2)
OutLine = "2140800050202" & mid((NeedData(1) & space(10)), 1, 19) & "3" & AddZero(i, 6) & "00" & NeedData(2)
OutLine = OutLine & "000000000000000011 " & AddZero(i - 1, 9) & NeedData(4)
OutStr = OutStr & OutLine & vbCrLf
i = i + 1
Sum = Sum + CLng(NeedData(2))
End If
Loop
OutStr = OutStr & "114080005020214080100112003624143" & AddZero(i, 6)
OutStr = OutStr & "00" & AddZero(Sum, 15) & "0000000" & AddZero(i - 1, 10) & "2" & Space(82)
objFile.Close 'Close the file object
OutFile = "140800050" & FormatDate(Date) & "001.txt"
Set objFile = objFSO.OpenTextFile(OutFile, ForWriting, True) 'Open OutFile in writing mode
objFile.Write OutStr
objFile.Close 'Close the file object
Set objFile = Nothing
Set objFSO = Nothing
Function FixStr(StrExp)
Do While InStr(StrExp, " ")
StrExp = Replace(StrExp, " ", " ")
Loop
FixStr = StrExp
End Function
Function FormatDate(tDate)
FormatDate = Right(Year(tDate), 2) & AddZero(Month(tDate), 2) & AddZero(Day(tDate), 2)
End Function
Function AddZero(sNum, iLen)
Addzero = Right("00000000000" & sNum, iLen)
End Function
Really thank you, Great Slore, for your help. Please be sure to continue to help me in the future... Thanks in advance!
This problem has been solved. Thank you all greats for your attention and support.
감사합니다!
Studying hard...
|
|
2008-2-1 18:22 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 36 楼』:
使用 LLM 解释/回答一下
那个中文的我本来想问呢。就觉得怪怪的。
不过你那样都*2了,如果是e文的就不对了……
不过应该都是中文吧。。。。
I originally wanted to ask about that in Chinese. Just felt it was a bit strange.
But if you did that *2, it wouldn't be right if it's in English...
But it should all be in Chinese...
|
|
2008-2-1 18:56 |
|
|
dhlmdsnw
初级用户
 
积分 127
发帖 59
注册 2008-1-29
状态 离线
|
『第 37 楼』:
使用 LLM 解释/回答一下
是的,目前实际操作当中都还只是中文,如果出现e文呢?——大大可有改进的通用版可以给我吗?。。。。嘿嘿。。。不要怪我贪心啊。。。
고 맙 습 니 다 !!
Yes, currently in actual operation, it's still only in Chinese. What if English appears? -- Can the Great One provide me with an improved general version?...... Hehe...... Don't blame me for being greedy......
감사합니다!
|
|
2008-2-1 19:02 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 38 楼』:
使用 LLM 解释/回答一下
甚至支持中英混合名...汗~应该没有吧。
只该了一个地方,len该成了MixLen。
Example++.vbs:
Const ForReading = 1 '设定打开文本方式为读取
Const ForWriting = 2 '设定打开文本方式为写入
Const ForAppending = 8 '设定打开文本方式为追加
Const InFile = "a.txt" '设定打开的文本
Dim i,Sum
Dim StrLine,OutStr
i = 1:Sum = 0
'On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject") '引用FSO对象,读写文件要用到的
Set objFile = objFSO.OpenTextFile(InFile, ForReading) '以读取方式打开InFile
Do Until objFile.AtEndOfStream
StrLine = objFile.ReadLine '读取一行
If Len(StrLine) Then '如果不是空行
StrLine = FixStr(StrLine)
NeedData = Split(StrLine," ")
If Right(NeedData(1),1) = "*" Then NeedData(1) = Left(NeedData(1),Len(NeedData(1)) - 1)
NeedData(4) = NeedData(4) & Space(53 - MixLen(NeedData(4)))
OutLine = "2140800050202" & NeedData(1) & "3" & AddZero(i,6) & "00" & NeedData(2)
OutLine = OutLine & "000000000000000011 " & AddZero(i - 1,9) & NeedData(4)
OutStr = OutStr & OutLine & vbCrLf
i = i + 1
Sum = Sum + CLng(NeedData(2))
End If
Loop
OutStr = OutStr & "14080005020214080100112003624143" & AddZero(i,6)
OutStr = OutStr & "00" & AddZero(Sum,15) & "0000000" & AddZero(i - 1,9) & "2" & Space(82)
objFile.Close '关闭文件对象
OutFile = "140820" & FormatDate(Date) & "001.txt"
Set objFile = objFSO.OpenTextFile(OutFile, ForWriting,True) '以写入方式打开OutFile
objFile.Write OutStr
objFile.Close '关闭文件对象
Set objFile = Nothing
Set objFSO = Nothing
Function AddZero(sNum,iLen)
Addzero = Right("000000000" & sNum,iLen)
End Function
Function FixStr(StrExp)
Do While InStr(StrExp," ")
StrExp = Replace(StrExp," "," ")
Loop
FixStr = StrExp
End Function
Function MixLen(StrExp)
Dim i,c
For i = 1 To Len(StrExp)
c = Asc(Mid(StrExp, i, 1))
If Not (C >= 0 And C < 128) Then MixLen = MixLen + 1
MixLen = MixLen + 1
Next
End Function
Function FormatDate(tDate)
FormatDate = Right(Year(tDate),2) & AddZero(Month(tDate),2) & AddZero(Day(tDate),2)
End Function
Even supports mixed Chinese and English names... Sweat~ There shouldn't be, right?
Only one place was changed, len was changed to MixLen.
Example++.vbs:
Const ForReading = 1 'Set the text opening method to reading
Const ForWriting = 2 'Set the text opening method to writing
Const ForAppending = 8 'Set the text opening method to appending
Const InFile = "a.txt" 'Set the text to open
Dim i,Sum
Dim StrLine,OutStr
i = 1:Sum = 0
'On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject") 'Reference the FSO object, needed for reading and writing files
Set objFile = objFSO.OpenTextFile(InFile, ForReading) 'Open InFile in reading mode
Do Until objFile.AtEndOfStream
StrLine = objFile.ReadLine 'Read a line
If Len(StrLine) Then 'If it's not an empty line
StrLine = FixStr(StrLine)
NeedData = Split(StrLine," ")
If Right(NeedData(1),1) = "*" Then NeedData(1) = Left(NeedData(1),Len(NeedData(1)) - 1)
NeedData(4) = NeedData(4) & Space(53 - MixLen(NeedData(4)))
OutLine = "2140800050202" & NeedData(1) & "3" & AddZero(i,6) & "00" & NeedData(2)
OutLine = OutLine & "000000000000000011 " & AddZero(i - 1,9) & NeedData(4)
OutStr &= OutLine & vbCrLf
i += 1
Sum += CLng(NeedData(2))
End If
Loop
OutStr &= "14080005020214080100112003624143" & AddZero(i,6)
OutStr &= "00" & AddZero(Sum,15) & "0000000" & AddZero(i - 1,9) & "2" & Space(82)
objFile.Close 'Close the file object
OutFile = "140820" & FormatDate(Date) & "001.txt"
Set objFile = objFSO.OpenTextFile(OutFile, ForWriting,True) 'Open OutFile in writing mode
objFile.Write OutStr
objFile.Close 'Close the file object
Set objFile = Nothing
Set objFSO = Nothing
Function AddZero(sNum,iLen)
Addzero = Right("000000000" & sNum,iLen)
End Function
Function FixStr(StrExp)
Do While InStr(StrExp," ")
StrExp = Replace(StrExp," "," ")
Loop
FixStr = StrExp
End Function
Function MixLen(StrExp)
Dim i,c
For i = 1 /color]To Len(StrExp)
c= Asc(Mid(StrExp, i, 1))
If Not (C /color]>= 0 /color]And C /color]< 128) Then MixLen /color]= MixLen /color]+ 1
MixLen /color]= MixLen /color]+ 1
Next
End Function
Function FormatDate(tDate)
FormatDate = Right(Year(tDate),2) & AddZero(Month(tDate),2) & AddZero(Day(tDate),2)
End Function
|
|
2008-2-1 19:36 |
|
|
dhlmdsnw
初级用户
 
积分 127
发帖 59
注册 2008-1-29
状态 离线
|
『第 39 楼』:
使用 LLM 解释/回答一下
哇噻,slore大大,你太酷了。。。。
不好意思,我想问一下Mixlen功能可以吗?
Wow, Great Slore, you're so cool...
Excuse me, may I ask about the Mixlen function?
|
|
2008-2-1 21:10 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 40 楼』:
使用 LLM 解释/回答一下
MsgBox MixLen("我是Slore") '返回结果9。
'MixLen把中文按2个长度,数字e文和一些符号
'(常见的字符的ASCII码都是在0~128以内的)
'按1个长度处理。
Function MixLen(StrExp)
Dim i,c
For i = 1 To Len(StrExp)
c = Asc(Mid(StrExp, i, 1))
If Not (C >= 0 And C < 128) Then MixLen = MixLen + 1
MixLen = MixLen + 1
Next
End Function
MsgBox MixLen("I am Slore") 'Returns the result 9.
'MixLen treats Chinese as 2 lengths, and numbers, English letters, and some symbols
'(Common characters have ASCII codes within 0 to 128)
'Treated as 1 length.
Function MixLen(StrExp)
Dim i,c
For i = 1 To Len(StrExp)
c = Asc(Mid(StrExp, i, 1))
If Not (C >= 0 And C < 128) Then MixLen = MixLen + 1
MixLen = MixLen + 1
Next
End Function
|
|
2008-2-1 21:28 |
|
|
dhlmdsnw
初级用户
 
积分 127
发帖 59
注册 2008-1-29
状态 离线
|
|
2008-2-1 21:33 |
|
|