使用VBScript对订单进行排序检查 [英] Sorting order check using VBScript
问题描述
假设我有一个数组arr1,其中包含如下日期值:
Suppose I have an array arr1 which contains date values as below :
Arr1(50)=(9/3/2012 4:57:02 AM ,22/3/2012 5:57:02 AM,9/5/2012 8:57:02 AM,9/3/2011 4:57:02 AM)
Arr1(50)=("9/3/2012 4:57:02 AM","22/3/2012 5:57:02 AM","9/5/2012 8:57:02 AM","9/3/2011 4:57:02 AM")
编辑
Edit
Dim CellCount
Dim Arr(10)
CellCount=0
Do Untill arr(CellCount)="" And Ubound(Arr)>9
If CStr(arr(CellCount) < arr(CellCount+1)) Then
MsgBox(arr(CellCount)&"is good")
Else
MsgBox(arr(CellCount +1)&"is bad")
Exit Do
End if
CellCount=CellCount+1
Loop
现在,有没有任何直接的方式,没有使用任何循环技术, Arr1()有日期值升序吗?
Now, Is there any direct way,without using any Looping technique,to find out if the Arr1() has the date values ascending or not?
谢谢,
推荐答案
他正在回答你的问题。你问, 有没有办法找到没有循环的排序?
他说不。你的眼睛,我的眼睛可以看到是否排序。但是,如何预期Excel /计算机不需要通过集合元素呢?
He is answering your question. You asked, is there a way to find if sorted without a loop? He said no. Your eyes, my eyes can see if it's sorted or not. But how do you expect Excel/computer to do so without going through collections elements?
当数据在数组中时,您需要循环遍历其元素。希望很清楚。
When data is in an array, you need to loop through its elements. Hope it's clear.
所以最好的可以说,
- 拆分如果需要,通过逗号分隔符变成一个变体。但是不必要,因为Array()可以将元素放入1D变体中。
- 使用转置 将其转储到
-
使用表排序方法/函数整理范围
范围
b $ b - split it by the comma delimiter into a variant if required. But not necessary since Array() can put elements into a 1D variant
- dump it into a
Range
using Transpose use Sheet sorting method/function to sort the range as a whole
--->所以你知道它现在被排序了。 p>
---> so you know it's now sorted.
有些代码片段让你走在这个方向上:
Some code snippet to get you going on this direction:
Option Explicit
Sub omgArraySort()
Dim inputArray As Variant
Dim outputArray As Variant
Dim upperB as Long
inputArray = Array("9/3/2012 4:57:02 AM","22/3/2012 5:57:02 AM", _
"9/5/2012 8:57:02 AM","9/3/2011 4:57:02 AM")
'-- sorted array
outputArray = sortRange(inputArray)
upperB = UBound(iArray, 1) '-- for 1D array you may also use UBound(iArray)
If (Err.Number <> 0) Then '-- if there's an error, it's erro code is > 0
MsgBox "Dates sorted, not empty"
End If
End Sub
'-- dump into sheet and sort in the sheet and dump back into the array
Function sortRange(ByVal iArray As Variant) As Variant
Dim rngSort as Range
Dim i As Long
Set rngSort = WorkSheets(1).Range("B2")
i = Ubound(iArray,1)
With rngSort.Resize(i)
.Value = WorksheetFunction.Transpose(iArray)
.Sort rngSort, xlDescending, Header:=xlNo
sortRange = .Value
End With
End Function
在从表单到代码流量方面,在处理大量数据时可能会降低性能。
In terms of to-from sheet to code traffic can slow down your performance when you are handling large amount of data.
请知道,当有可信度答复的人(例如Ekkehard的答案)时,您必须要注意。他们不说没有正当理由。
这篇关于使用VBScript对订单进行排序检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!