Syntax, not a member of string, and other errors

  • Thread starter Thread starter Van wilderer
  • Start date Start date
V

Van wilderer

Guest
I have to wright a program using VB.Net that does the following:

This project once completed, will read from a file (ZipCity.txt that will need to be created from the data below – copy and paste into the file), search through that file, and return either the zip code (if the user enters a city), the city (if the user enters a zip code), or an error if the zip/city does not exist in the file. You must convert the input string to the appropriate case.
Below, is the data for the SAZC.txt file. Copy and paste the data into a .txt file.
44114,CLEVELAND
44203,BARBERTON
44214,BURBANK
44216,CLINTON
44217,CRESTON
44230,DOYLESTOWN
44270,RITTMAN
44273,SEVILLE
44276,STERLING
44281,WADSWORTH
44287,WESTSALEM
44325,AKRON
44606,APPLECREEK
44611,BIG PRAIRIE
44614,CANAL FULTON
44618,DALTON
44624,DUNDEE
44627,FREDERICKSBURG
44636,KIDRON
44638,LAKEVILLE
44645,MARSHALLVILLE
44659,MOUNT EATON
44662,NAVARRE
44666,NORTHLAWRENCE
44667,ORRVILLE

The form designer looks like the following:

565863


Im specifically having trouble with the following lines of code:

If IO.File.Exists(""C:\Users\dgrossi0914\Documents\Visual Studio 2013\Projects\program10\SAZC.txt"") Then


For intIndex As Integer = 0 To txtStartZip.Text.Count - 1 AndOr txtStartCity.Text.Count - 1
outFile = IO.File.CreatText("C:\Users\dgrossi0914\Documents\Visual Studio 2013\Projects\program10\ZipCity.txt")


and

txtStartCity.Text.Clear()
txtStartZip.Text.Clear()


, which are causing the following errors:

Error 8 Syntax error. 94 31 program10
Error 1 Statement cannot appear within a method body. End of method assumed. 24 5 program10
Error 2 End of statement expected. 83 67 program10
Error 7 Character constant must contain exactly one character. 94 27 program10
Error 4 System.Data.Index is not accessible in this context because it is Friend. 87 14 program10
Error 3 CreatText is not a member of System.IO.File. 84 23 program10
Error 5 Clear is not a member of String. 91 9 program10
Error 6 Clear is not a member of String. 92 9 program10



My entire code is as follows and is not bulky with comments at the moment:

Option Strict On
Imports System.Text.RegularExpressions
Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub

Private Function Capitalize(ByVal Name As String) As String
Dim Result1 As String = ""
For Each startcity As String In Name.Split(CChar(" "))
Result1 &= startcity.Substring(0, 1).ToUpper
Result1 &= startcity.Substring(1).ToUpper & " "

Next
Return Result1
End Function
Function GetInputs() As String()
Dim R As New Regex("(?<=[.-[0-9]])*\d*") Declares the variable R as a regular expression matching this expression
Return R.Matches(txtStartZip.Text).OfType(Of Match)().Where(Function(m) m.Value <> "").Select(Function(m) m.Value).ToArray return the R regular expression matching the values declared
End Function
Private Sub Displaysides(ByVal Area As Double, ByVal Area2 As Double, ByVal Area3 As Double, ByVal Volume As Double)

Private Sub lblStartZip_Click(sender As Object, e As EventArgs) Handles lblStartZip.Click

End Sub

Private Sub lblStartCity_Click(sender As Object, e As EventArgs) Handles lblStartCity.Click

End Sub

Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles txtStartZip.TextChanged

End Sub

Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles txtStartCity.TextChanged

End Sub

Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
If txtStartCity.Text = "" And txtStartZip.Text = "" Then
MessageBox.Show("You Must enter a City and Zip")
End If
If txtStartCity.Text = txtStartZip.Text Then
txtFoundCity.Text = CStr(CDbl(0))
txtFoundZip.Text = CStr(CDbl(0))
MessageBox.Show("Must enter different city and zip")
End If
If (txtStartCity.Text <> txtStartZip.Text) Then
Dim Name = txtStartCity.Text
Dim Name2 = txtStartZip.Text
End If
Dim AraSize As Integer = 7
Dim Distances(AraSize - 1, AraSize - 1) As Integer
Dim cities() As String = {""}
Dim zip() As String = {""}
txtStartCity.Focus()
txtStartCity.Text = String.Empty
txtStartZip.Text = String.Empty
Dim result1 = Capitalize(Name)
Dim inputs = GetInputs() Declares the variable inputs as the function called GetInputs
If inputs.Count = 1 Then tests if inputs variable with Count function is equal to 1
txtStartZip.Text = CStr(inputs(0))
Else
Throw New Exception("Too many or too few input values. This function requires only a single input")
End If
Dim result2 = txtStartZip.Text
If result1.Count < 1 Then
MessageBox.Show("Must have at least a one word name")
Throw New Exception("Must have at least a one word name")
Exit Sub
End If
If inputs(0).Count < 1 Then
MessageBox.Show("Must have at least a one string of five numbers")
Throw New Exception("Must have at least a one string of five numbers")
Exit Sub
End If
txtStartCity.Text = CStr(result1)
txtStartZip.Text = CStr(result2)
Dim CityoutFile As IO.StreamWriter
Dim ZipoutFile As IO.StreamWriter
Dim outFile As IO.StreamWriter
For intIndex As Integer = 0 To txtStartZip.Text.Count - 1 AndOr txtStartCity.Text.Count - 1
outFile = IO.File.CreatText("C:\Users\dgrossi0914\Documents\Visual Studio 2013\Projects\program10\ZipCity.txt")
outFile = IO.File.AppendText("C:\Users\dgrossi0914\Documents\Visual Studio 2013\Projects\program10\ZipCity.txt")
outFile.WriteLine(txtStartCity.Text(intIndex) & txtStartZip.Text(intIndex))
Next Index
outFile.Close()
Dim strName As String
outFile.Close()
txtStartCity.Text.Clear()
txtStartZip.Text.Clear()
txtStartCity.Focus()
If IO.File.Exists(""C:\Users\dgrossi0914\Documents\Visual Studio 2013\Projects\program10\SAZC.txt"") Then
Dim infile As IO.StreamReader
infile = IO.File.OpenText("C:\Users\dgrossi0914\Documents\Visual Studio 2013\Projects\program10\SAZC.txt")
Do Until infile.Peek = -1
strName = infile.Readline
Loop
infile.Close()
Else

End If
MessageBox.Show("Cant find the file", "SAZC.txt",
MessageBoxButtons.OK,
MessageBoxIcon.Information)



End Sub

Private Sub txtFoundCity_TextChanged(sender As Object, e As EventArgs) Handles txtFoundCity.TextChanged

End Sub

Private Sub txtFoundZip_TextChanged(sender As Object, e As EventArgs) Handles txtFoundZip.TextChanged

End Sub

Private Sub btnFind_Click(sender As Object, e As EventArgs) Handles btnFind.Click

End Sub
End Class

Continue reading...
 
Back
Top