[英]VB.Net Array.Sort nullifying values
I'm having some serious trouble with the Array.Sort functionality within my VB.net program. 我在VB.net程序中的Array.Sort功能遇到了严重的麻烦。 Everything within my code, including what is pasted here seems to function all the way through the loop (which is at the end of my code), including populating FinalDataArray with the information that I expect, however when I pass it to Array.Sort, then I end up with FinalDataArray having a null value at every index.
我代码中的所有内容,包括粘贴到此处的内容,似乎在循环中一直都起作用(在代码的末尾),包括用我期望的信息填充FinalDataArray, 但是当我将其传递给Array.Sort时,然后我最终得到在每个索引处都有一个空值的FinalDataArray。 Any thoughts on what could be causing this?
有什么想法可能导致这种情况?
The applicable portion of my code is as follows: 我的代码的适用部分如下:
UPDATE: I've updated my code block to show the entire Sub from this program. 更新:我已经更新了代码块,以显示该程序中的整个Sub。
Private Sub btnDisplay_Click(sender As System.Object, e As System.EventArgs) Handles btnDisplay.Click
frmMain.CurrentFigure = txtFigure.Text
frmFigureViewer.Show()
Dim ArrayUpperBound = FGCFigNo.Length
FigureResult = Enumerable.Range(0, FGCFigNo.Length).Where(Function(f) FGCFigNo(f) = frmMain.CurrentFigure).ToArray
frmFigureViewer.lblFGCfromFGCList.Text = FGCCode(FigureResult(0))
frmFigureViewer.lblTOPCurrentFigureTitle.Text = FGCTitle(FigureResult(0))
frmFigureViewer.lblTOPDisplayFigure.Text = FGCFigNo(FigureResult(0))
frmFigureViewer.lblCurrentSheet.Text = FGCSheetNo(FigureResult(0))
frmFigureViewer.lblFinalSheet.Text = FGCSheetNo(FigureResult(FigureResult.Length - 1))
ArtResult = FGCArtID(FigureResult(frmFigureViewer.lblCurrentSheet.Text - 1))
Dim JpgFilePath As String = "C:\Temp\StandaloneRPSTLViewer" + "\" + Mid(ArtResult, 1, ArtResult.Length - 4) + ".jpg"
If File.Exists(JpgFilePath) Then
GoTo OnlyDisplay
End If
Dim SourceFile As String = ""
Dim DestinationFile As String = ""
Dim EpsFilePath As String = ARTFOLDER + "\" + ArtResult
If Not Directory.Exists("C:\Temp\StandaloneRPSTLViewer") Then
MkDir("C:\Temp\StandaloneRPSTLViewer")
End If
SourceFile = EpsFilePath
DestinationFile = Mid(EpsFilePath, 1, Len(EpsFilePath) - 4) + " view.eps"
FileCopy(SourceFile, DestinationFile)
EpsFilePath = DestinationFile
RunGS("-q", "-dNOPAUSE", "-dBATCH", "-dSAFER", "-sDEVICE=jpeg", _
"-r600", "-dJPEGQ=100", "-dEPSCrop", "-dDownScaleFactor=0", "-dTextAlphaBits=4", "-dGraphicsAlphaBits=4", _
"-sPAPERSIZE=letter", "-sOutputFile=" & JpgFilePath, EpsFilePath)
Kill(EpsFilePath) 'KILLS THE "...view.eps" temporary file in the working folder.
OnlyDisplay:
frmFigureViewer.picMyJPEG.Image = Image.FromFile(JpgFilePath)
Fig036Result = Enumerable.Range(0, FIGURENO.Length).Where(Function(f) FIGURENO(f) = frmMain.CurrentFigure).ToArray
'BUILD DICTIONARY HERE'
Dim dict As Dictionary(Of String, String) = New Dictionary(Of String, String)
Dim DictionaryFigureNumber As Integer = 1
Dim DictionarySortPosition As Integer = 1
Do Until DictionaryFigureNumber = 1000
Dim DictionaryFigureLetterASCII As Integer = 65
dict.Add(DictionaryFigureNumber, DictionarySortPosition)
DictionarySortPosition = DictionarySortPosition + 1
Do Until DictionaryFigureLetterASCII = 91
dict.Add(DictionaryFigureNumber & Chr(DictionaryFigureLetterASCII), DictionarySortPosition)
DictionarySortPosition = DictionarySortPosition + 1
DictionaryFigureLetterASCII = DictionaryFigureLetterASCII + 1
Loop
DictionaryFigureNumber = DictionaryFigureNumber + 1
Loop
'END OF DICTIONARY BUILDING
Dim TempLength = Fig036Result.GetLength(0)
TempLength = TempLength - 1
Dim CurrentPlace As Integer = 0
Dim TempItemNo As String
Dim ArrayString As String = ""
Do Until CurrentPlace > TempLength
Dim ArrayLocation As Integer = Fig036Result(CurrentPlace)
TempItemNo = ITEMNO(ArrayLocation)
TempSMR = SMnR(ArrayLocation)
TempNSN = NSN(ArrayLocation)
TempCAGE = CAGE(ArrayLocation)
TempPartNum = PARTNUM(ArrayLocation)
TempDescription = ITEMName(ArrayLocation)
TempUOC = UOC(ArrayLocation)
TempQTY = QTYFIG(ArrayLocation)
TempIndvFGC = FGC(ArrayLocation)
Dim TempValue As String = ""
dict.TryGetValue(TempItemNo, TempValue)
ArrayString = TempValue + "::" + TempItemNo + "|" + TempSMR + "|" + TempNSN + "|" + TempCAGE + "|" + TempPartNum + "|" + TempDescription + "|" + TempUOC + "|" + TempQTY + "|" + TempIndvFGC + "|"
FinalDataArray(CurrentPlace) = ArrayString
'FinalSortArray(CurrentPlace) = TempValue
CurrentPlace = CurrentPlace + 1
Loop
Array.Sort(FinalDataArray)
End Sub
Update2: I've updated the looping portion of the code as follows: Update2:我已经更新了代码的循环部分,如下所示:
Dim TempValue As String = ""
dict.TryGetValue(TempItemNo, TempValue)
ArrayString = TempItemNo + "|" + TempSMR + "|" + TempNSN + "|" + TempCAGE + "|" + TempPartNum + "|" + TempDescription + "|" + TempUOC + "|" + TempQTY + "|" + TempIndvFGC + "|"
FinalDataArray(CurrentPlace) = ArrayString
FinalSortArray(CurrentPlace) = TempValue
CurrentPlace = CurrentPlace + 1
Loop
Array.Sort(FinalSortArray, FinalDataArray)
My new declaration for my two arrays are: 我对两个数组的新声明是:
Public FinalSortArray(50000) As Integer
Public FinalDataArray(50000) As String
I think your problem is that you have no idea how large the array really is, it's bigger than you expect and Array.Sort
refills the array from the back... Consider: 我认为您的问题是您不知道数组的实际大小,它比您预期的
Array.Sort
大,并且Array.Sort
从背面重新Array.Sort
数组...考虑:
Dim arr() As String
ReDim arr(10)
arr(0) = "Z"
arr(2) = "3"
arr(1) = "Boolean"
arr(5) = "Hello"
Array.Sort(arr)
For i As Integer = 0 To 10
Debug.Print(arr(i))
Next
Even though I specified the size of the array as 11 and filled only 4 random spots with data, after the Array.Sort
my data is sorted at the back of the array and only arr(7)...arr(10)
contain data (in the proper order). 即使我将数组的大小指定为11并仅在数据中填充了4个随机点,在
Array.Sort
之后,我的数据Array.Sort
数组的后面排序,并且只有arr(7)...arr(10)
包含数据(以正确的顺序)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.