尝试运行此代码时,我一直收到“输入字符串格式不正确”的错误。
结果是将数据从一个列表框检索到另一个列表框,仅传输数据的某些部分。
Private Sub LoadButton_Click(sender As Object, e As EventArgs) Handles LoadButton.Click
'checks there is raw data loaded
If RawDataListBox.Items.Count = 0 Then
MessageBox.Show("No Data Has Been Loaded")
Exit Sub
End If
'Splits the raw data into the structure
Try
Dim counterInteger As Integer = 12
Dim FinalDataStructure(RawDataListBox.Items.Count) As FinalData
Dim CleanDataString As String
While counterInteger < RawDataListBox.Items.Count
'reads one row into a string
Dim FinalDataLineString As String = RawDataListBox.Items(counterInteger).ToString
'Splits string by comma
Dim FinalDataArrayString As String() = FinalDataLineString.Split(","c)
FinalDataLineString.Replace("""", " ")
With FinalDataStructure(counterInteger)
.LocationNameString = FinalDataArrayString(0)
.TypeString = FinalDataArrayString(1)
.StateString = FinalDataArrayString(2)
.FemalesInteger = Integer.Parse(FinalDataArrayString(3))
.MalesInteger = Integer.Parse(FinalDataArrayString(4))
'calculate the percentages and totals
.TotalInteger = .FemalesInteger + .MalesInteger
.PercentageFemaleInteger = .FemalesInteger + .TotalInteger
.PercentageMaleInteger = .MalesInteger + .TotalInteger
End With
CleanDataString = "Location" + FinalDataStructure(counterInteger).LocationNameString + ","
CleanDataString += "Type" + FinalDataStructure(counterInteger).TypeString + ","
CleanDataString += "State" + FinalDataStructure(counterInteger).StateString + ","
CleanDataString += "Females" + FinalDataStructure(counterInteger).FemalesInteger.ToString + ","
CleanDataString += "Males" + FinalDataStructure(counterInteger).MalesInteger.ToString + ","
CleanDataString += "Female Percentage" + FinalDataStructure(counterInteger).PercentageFemaleInteger.ToString + ","
CleanDataString += "Male Percentage" + FinalDataStructure(counterInteger).PercentageMaleInteger.ToString + ","
CleanDataString += "Total Population" + FinalDataStructure(counterInteger).TotalInteger.ToString + ","
'Add to list box
FinalDataListBox.Items.Add(CleanDataString)
counterInteger += 1
End While
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub