2016-04-07 6 views
2

配列からの日付の一致の柱脚に動的に配列をソートする助けが必要なので、日付を一致させるために探しているイム私は、文字列

dim datearray 
datearray(0) = "3/1/2016" 
datearray(1) = "3/2/2016" 
datearray(2) = "3/3/2016" 
for var = lbound(datearray) to ubound(datearray) 

needed code here 
next 

で動作するようにしようとし

myarray(uid,3/1/2016,3/4/2016,3/5/2016,3/6/2016,3/7/2016,3/8/2016 
1,8,6,3,5,3,2 
2,3,7,2,3,9,4 
3,6,7,1,1,1,7 
4,1,5,2,4,7,4 
5,9,9,9,7,4,3 
6,5,4,2,9,6,4 
7,5,1,5,2,6,8 
8,7,1,7,9,3,4 
9,4,2,7,8,4,9 
10,1,1,2,9,8,4) 

サンプルコードイム配列から配列を並べ替えて

+0

PSイムを参照してください。あなたが完全に今の質問を変更しました –

+0

。解決策の1つに質問を合わせるだけではありません。 – Lankymart

答えて

1

日付と思われる文字列の部分を取得するにはRegExpを使用し、IsDate関数を使用してそれを検証する必要があります。

Option Explicit 
Dim myarray,i,MyDate 
myArray=Array("3/1/2016","3/4/2016","3/5/2016","3/6/2016","3/7/2016","3/8/2016",_ 
"1","8","6","3","5","3","2",_ 
"2","3","7","2","3","9","4",_ 
"3","6","7","1","1","1","7",_ 
"4","1","5","2","4","7","4",_ 
"5","9","9","9","7","4","3",_ 
"6","5","4","2","9","6","4",_ 
"7","5","1","5","2","6","8",_ 
"8","7","1","7","9","3","4",_ 
"9","4","2","7","8","4","9",_ 
"10","1","1","2","9","8","4") 
'Before sorting the array 
WScript.Echo "Before sorting the array " & VbCrLF & VbCrLF & Join(myArray, vbTab) 
Sort myarray 'Sort the array 
'After sorting the array 
WScript.Echo "After sorting the array " & VbCrLF & VbCrLF & Join(myArray, vbTab) 

For i=LBound(myArray) to UBound(myArray) 
    If FormatOutput(myArray(i)) <> "" Then 
     MyDate = Mydate & FormatOutput(myArray(i)) & VbCrLF 
    End If 
Next 
wscript.echo MyDate 
'********************************************* 
Function FormatOutput(s) 
    Dim re, match 
    Set re = New RegExp 
    re.Pattern = "[\d]+[\/-][\d]+[\/-][\d]+" 
    re.Global = True 
    For Each match In re.Execute(s) 
     if IsDate(match.value) then 
      FormatOutput = CDate(match.value) 
      Exit For 
     end if 
    Next 
    Set re = Nothing 
End Function 
'********************************************* 
Sub Sort(ByRef myArray) 
    Dim i, j, strHolder 
    For i = (UBound(myArray) - 1) to 0 Step -1 
     For j= 0 to i 
      If UCase(myArray(j)) > UCase(myArray(j + 1)) Then 
       strHolder  = myArray(j + 1) 
       myArray(j + 1) = myArray(j) 
       myArray(j)  = strHolder 
      End If 
     Next 
    Next 
End Sub 
'********************************************* 
+0

私は行番号が の小文字を持っています。 "i10 =(UBound(counterlist) - 1)〜0のステップ-1" インデックスが範囲外です、ここにどのようにコードを適用しようとしましたか –

+0

何をしているのですか? –

+0

@demetriushenningあなたの変更をロールバックします。あなたが元の質問に追加しようとしたことを示すつもりなら、それを置き換えずに元の文脈を失います。 – Lankymart

1

レコードセットは、配列よりもフィルタリングすることができ、配列とは異なる配列をソートすることができます。これは標準入力から読み取り、標準出力に書き込みます。また、自分自身をディスクに保存することもできます。

これは、ソートキーとテキスト行の2つのフィールドを持つレコードセットをメモリに作成します。

次に入力をループし、テキスト行と行から抽出したソートキーをレコードセットに書き込みます。並べ替えの列を設定します。ソートされたレコードセットを標準出力に書き戻します。

これは、データベースのクエリではなく、メモリ内に切断されたレコードを作成するため、レコードセットのほとんどの使用とは異なります。

vbsファイルを使用してhttps://msdn.microsoft.com/en-us/library/ms681510(v=vs.85).aspx

Set rs = CreateObject("ADODB.Recordset") 
With rs 
    .Fields.Append "SortKey", 4 
    .Fields.Append "Txt", 201, 5000 
    .Open 
    Do Until Inp.AtEndOfStream 
     Lne = Inp.readline 
     SortKey = Mid(Lne, LCase(Arg(3)), LCase(Arg(4)) - LCase(Arg(3))) 
     If IsNumeric(Sortkey) = False then 
      Set RE = new Regexp 
      re.Pattern = "[^0-9\.,]" 
      re.global = true 
      re.ignorecase = true 
      Sortkey = re.replace(Sortkey, "") 
     End If 
     If IsNumeric(Sortkey) = False then 
      Sortkey = 0 
     ElseIf Sortkey = "" then 
      Sortkey = 0 
     ElseIf IsNull(Sortkey) = true then 
      Sortkey = 0 
     End If 
     .AddNew 
     .Fields("SortKey").value = CSng(SortKey) 
     .Fields("Txt").value = Lne 
     .UpDate 
    Loop 
    If LCase(Arg(2)) = "a" then SortColumn = "SortKey ASC" 
    If LCase(Arg(2)) = "d" then SortColumn = "SortKey DESC" 
    .Sort = SortColumn 
    Do While not .EOF 
     Outp.writeline .Fields("Txt").Value 
     .MoveNext 
    Loop 
End With 
+0

これは 'ADODB.Recordset'オブジェクトがうまくいくことの1つです。 – Lankymart

+0

もしあなたが私がitllの助けを適用する方法を私にshiwできれば –

関連する問題