Guest User

Untitled

a guest
Jan 17th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. Imports System.Windows.Forms
  2. Imports System.IO
  3. Imports System.Globalization
  4.  
  5. Class MainWindow
  6. Private foldername As String
  7. Private arrGemeenten As String()
  8. Private arrOppervlakte As Double()
  9. Private arrInwoners As Integer()
  10. Private arrDeelgemeenten As Integer()
  11.  
  12.  
  13. Private Sub cboProvincie_SelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs) Handles cboProvincie.SelectionChanged
  14. CSVInlezen()
  15. End Sub
  16.  
  17. Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
  18.  
  19.  
  20. FileBrowserAanmaken()
  21. comboBoxVullen()
  22.  
  23. End Sub
  24.  
  25.  
  26.  
  27. Private Sub comboBoxVullen()
  28. For Each file As String In IO.Directory.GetFiles(foldername)
  29.  
  30. If file.EndsWith(".csv") Then
  31. Dim filenaam As String = System.IO.Path.GetFileNameWithoutExtension(file)
  32. cboProvincie.Items.Add(filenaam)
  33. End If
  34.  
  35. Next
  36. End Sub
  37.  
  38. Private Sub FileBrowserAanmaken()
  39. 'folderbrowserdialog aanmaken
  40. Dim fbd As New FolderBrowserDialog
  41.  
  42. fbd.SelectedPath = AppDomain.CurrentDomain.BaseDirectory
  43.  
  44.  
  45. ' Show the FolderBrowserDialog.
  46.  
  47. Dim result As DialogResult = fbd.ShowDialog()
  48.  
  49. If (result = Forms.DialogResult.OK) Then
  50. foldername = fbd.SelectedPath
  51. End If
  52. End Sub
  53.  
  54.  
  55.  
  56. Private Sub CSVInlezen()
  57. Dim filepath As String = foldername & "" & cboProvincie.SelectedValue & ".csv"
  58. If File.Exists(filepath) Then
  59. fileInlezenHulpMethode(filepath)
  60. End If
  61. End Sub
  62.  
  63. Private Sub fileInlezenHulpMethode(ByVal path As String)
  64. 'declarations
  65. Dim sr As New StreamReader(path)
  66. Dim iTeller As Integer = 0
  67. Dim arrLijn As String()
  68. Dim culture As New System.Globalization.CultureInfo("nl-BE")
  69.  
  70. 'eerste lijn meteen uitlezen, dit zijn kolomkoppen en hebben we niet nodig
  71. 'read out first line, these are titles and we don't need them
  72. sr.ReadLine()
  73.  
  74. Do While sr.Peek <> -1
  75. Dim lijn As String = sr.ReadLine()
  76. arrLijn = lijn.Split(";")
  77. arrGemeenten(iTeller) = Convert.ToString(arrLijn(0)) 'HERE I GET THE ERROR!
  78. arrOppervlakte(iTeller) = Double.Parse(arrLijn(2), NumberStyles.AllowDecimalPoint, culture.NumberFormat)
  79. arrInwoners(iTeller) = Integer.Parse(arrLijn(3), NumberStyles.Integer Or NumberStyles.AllowThousands, culture.NumberFormat)
  80. arrDeelgemeenten(iTeller) = Convert.ToString(arrLijn(4))
  81. Loop
  82. End Sub
  83.  
  84. End Class
  85.  
  86. Private arrGemeenten As String(100)
  87.  
  88. Private gemeenten As New List(Of String)()
  89.  
  90. gemeenten.Add(Convert.ToString(arrLijn(0)))
Add Comment
Please, Sign In to add comment