Tim Tim - 7 months ago 32
Vb.net Question

overload resolution failed because no accessible 'writealltext' accepts this number of arguments

I am trying to edit "AM830.txt" with the users information that they enter into the Global****** variables

Public DestinationTick As String
Public PlaneTick As String
Public TimeTick As String
Public NameTick As String
Public DayTick As String
Public Stockitems() As String = IO.File.ReadAllLines("AM830.csv")
Public SortedStock(Stockitems.Length - 1)
Public Stocktypes(Stockitems.Length - 1) As Flight

Public Structure Flight
Public Destination As String
Public Plane As String
Public Time As String
Public Name As String
Public Day As String
Public Address As String
End Structure


''' when they press the button names P1A1
System.IO.File.WriteAllText("AM830.csv", "")
If P1A1.BackColor = Color.Red Then
Stocktypes(0).Destination = GlobalDestination
Stocktypes(0).Plane = GlobalPlane
Stocktypes(0).Time = GLobalTime
Stocktypes(0).Name = GlobalName
Stocktypes(0).Day = GlobalDay
Stocktypes(0).Address = GlobalAddress
P1A1.Enabled = False
End If


For Each item In Stocktypes
My.Computer.FileSystem.WriteAllText("AM830.txt", item.Destination & "," & item.Plane & "," & item.Time & "," & item.Name & "," & item.Day & "," & item.Address)
Next


in the "My.Computer.Filesystem.WriteAllTest(...........) i get the error "overload resolution failed because no accessible 'WriteAllText' accepts this number of arguments" i have no clue what this even means??

Im very new to VB and this is my first program using files so sorry if this is a stupid question

Answer

My.Computer.FileSystem.WriteAllText need at least 3 parameters. You have to add True or False to indicate whether you want the text to be added to the existing text in the file or overwrite everything in the file. The correct way would be:

For Each item In Stocktypes
   My.Computer.FileSystem.WriteAllText("AM830.txt", item.Destination & "," & item.Plane & "," & item.Time & "," & item.Name & "," & item.Day & "," & item.Address,True)
Next

More info My.Computer.FileSystem.WriteAllText Method