Geoff Vane
Geoff Vane

Reputation: 43

VB.net - ReadAllLines - File not declared error

Public Class Form1

    Dim pad As String = My.Application.Info.DirectoryPath

    Dim AutoCompleteDataBase As String() = File.ReadAllLines(pad + "\autocompletedb.txt")

End Class

Error BC30451 'File' is not declared.

What is going wrong? It seems VB is looking for Form1.vb in stead of autocompletedb.txt

I got many problems anyway, declaring variables in the Form part of the code. That seems only allowed with the "=" following the Dim where you immediately put a value in the variable. Which is a pity, because I would like to keep all variable declarations at the start of the code, not inside the code parts for buttons and such. What am I doing wrong?

If you want to answer, I can only understand examples of code as I got problems understanding proper explanations like true programmers can understand. I'm just an amateur connecting some dots.

Upvotes: 0

Views: 452

Answers (1)

Idle_Mind
Idle_Mind

Reputation: 39122

Here's two comments put together:

Private AutoCompleteDataBase As String() = System.IO.File.ReadAllLines(System.IO.Path.Combine(pad, "autocompletedb.txt"))

Note that I changed Dim to Private, as that is the default access, and Dim shouldn't be used at class level.

Upvotes: 1

Related Questions