By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,344 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,344 IT Pros & Developers. It's quick & easy.

'Type Expected' and 'Identifier Expected' errors (VB 2010)

P: 1
Hi there!

I'm having a small problem with my coding. I am new to this level of VB coding, and coding in general really, the only coding I've ever done in VB is to make a simple login manager!

Anyway, I am getting the errors that are mentioned in the title. Here is my code:

Expand|Select|Wrap|Line Numbers
  1. Imports System.Net
  2. Imports System.IO
  3. Imports System.Security.Policy
  4.  
  5.  
  6.  
  7. Public Class Form1
  8.  
  9.     Private Sub TabPage1_Click(sender As System.Object, e As System.EventArgs)
  10.  
  11.     End Sub
  12.  
  13.     Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
  14.  
  15.     End Sub
  16.  
  17.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  18.  
  19.     End Sub
  20.     Private Sub listFTP(ByVal URL As String, ByVal bk As String, ByVal pw As String)
  21.         Dim requ As FtpWebRequest = Nothing
  22.         Dim resp As FtpWebResponse = Nothing
  23.         Dim reader As StreamReader = Nothing
  24.         Try
  25.             requ = CType(WebRequest.Create(URL), WebRequest)
  26.             requ.Credentials = New NetworkCredential(bk, pw)
  27.             requ.Method = WebRequestMethods.Ftp.ListDirectory
  28.             resp = CType(requ.GetResponse(), FtpWebResponse)
  29.             reader = New StreamReader(resp.GetResponseStream())
  30.             While (reader.Peek() > -1)
  31.                 ListBox1.Items.Add(reader.ReadLine())
  32.             End While
  33.             ToolStripStatusLabel1.Text = "Listing Complete!"
  34.         Catch ex As UriFormatException
  35.             ToolStripStatusLabel1.Text = ex.Message
  36.         Catch ex As WebException
  37.             ToolStripLabel2.Text = ex.Message
  38.         Finally
  39.             If reader IsNot Nothing Then reader.Close()
  40.         End Try
  41.     End Sub
  42.  
  43.     Private Sub downloadFTP(ByVal URL As String, ByVal bk As String, ByVal pw As String)
  44.         Dim requ As FtpWebRequest = Nothing
  45.         Dim resp As FtpWebResponse = Nothing
  46.         Dim respStrm As Stream = Nothing
  47.         Dim fileStrm As FileStream = Nothing
  48.         Try
  49.             requ = CType(WebRequest.Create(URL), FtpWebRequest)
  50.             requ.Credentials = New NetworkCredential(bk, pw)
  51.             requ.Method = WebRequestMethods.Ftp.DownloadFile
  52.             resp = CType(requ.GetResponse(), FtpWebResponse)
  53.             respStrm = resp.GetResponseStream()
  54.             SaveFileDialog1.FileName = Path.GetFileName(requ.RequestUri.LocalPath)
  55.             If (SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
  56.                 fileStrm = File.Create(SaveFileDialog1.FileName)
  57.                 Dim buff(1024) As Byte
  58.                 Dim bytesRead As Integer = 0
  59.                 While (True)
  60.                     bytesRead = respStrm.Read(buff, 0, buff.Length)
  61.                     If (bytesRead = 0) Then Exit While
  62.                     fileStrm.Write(buff, 0, bytesRead)
  63.                 End While
  64.                 ToolStripStatusLabel1.Text = "Download Complete!"
  65.             End If
  66.         Catch ex As UriFormatException
  67.             ToolStripStatusLabel1.Text = ex.Message
  68.         Catch ex As WebException
  69.             ToolStripStatusLabel1.Text = ex.Message
  70.         Catch ex As IOException
  71.             ToolStripStatusLabel2.Text = ex.Message
  72.         Finally
  73.             If respStrm IsNot Nothing Then respStrm.Close()
  74.             If fileStrm IsNot Nothing Then fileStrm.Close()
  75.         End Try
  76.     End Sub
  77.  
  78.     Private Sub uploadFTP(ByVal uri As String, ByVal filename As String, ByVal bk As String, ByVal pw As String)
  79.         Dim requ As FtpWebRequest = Nothing
  80.         Dim resp As FtpWebResponse = Nothing
  81.         Dim requStrm As Stream = Nothing
  82.         Dim fileStrm As FileStream = Nothing
  83.         Try
  84.             requ = CType(WebRequest.Create(Url), FtpWebRequest)
  85.             requ.Credentials = New NetworkCredential(bk, pw)
  86.             requ.Method = WebRequestMethods.Ftp.UploadFile
  87.             requ.Timeout = System.Threading.Timeout.Infinite
  88.             requ.Proxy = Nothing
  89.             requStrm = requ.GetRequestStream()
  90.             Dim buff As(2048) byte
  91.             Dim bytesread As Integer = 0
  92.             fileStrm = File.OpenRead(filename)
  93.             Do While (True)
  94.                 bytesread = fileStrm.Read(buff, 0, buff.length)
  95.                 If (bytesread = 0) Then Exit Do
  96.                 requStrm.Write(buff, 0, bytesread)
  97.             Loop
  98.             requStrm.Close()
  99.             resp = CType(requ.GetResponse(), FtpWebResponse)
  100.             ToolStripLabel1.Text = "Upload Complete!"
  101.         Catch ex As UriFormatException
  102.             ToolStripStatusLabel1.Text = ex.Message
  103.         Catch ex As IOException
  104.             ToolStripStatusLabel2.Text = ex.Message
  105.         Catch ex As WebException
  106.             ToolStripLabel2.Text = ex.Message
  107.         Finally
  108.             If resp IsNot Nothing Then resp.Close()
  109.             If fileStrm IsNot Nothing Then fileStrm.Close()
  110.             If requStrm IsNot Nothing Then requStrm.Close()
  111.         End Try
  112.     End Sub
  113.  
  114.     Private Sub deleteFTP(ByVal URL As String, ByVal bk As String, ByVal pw As String)
  115.         Dim requ As FtpWebRequest = Nothing
  116.         Dim resp As FtpWebResponse = Nothing
  117.         Try
  118.             requ = CType(WebRequest.Create(URL), FtpWebRequest)
  119.             requ.Credentials = New NetworkCredential(bk, pw)
  120.             requ.Method = WebRequestMethods.Ftp.DeleteFile
  121.             resp = CType(requ.GetResponse(), FtpWebResponse)
  122.             ToolStripStatusLabel1.Text = "File Deleted!"
  123.         Catch ex As UriFormatException
  124.             ToolStripStatusLabel1.Text = ex.Message
  125.         Catch ex As WebException
  126.             ToolStripStatusLabel2.Text = ex.Message
  127.         Finally
  128.             If resp IsNot Nothing Then resp.Close()
  129.         End Try
  130.  
  131.     End Sub
  132.  
  133.     Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
  134.         downloadFTP(TextBox4.Text, txt_user.Text, txt_pw.Text)
  135.     End Sub
  136.  
  137.     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  138.         ListBox1.Items.Clear()
  139.         listFTP(txt_server.Text, txt_user.Text, txt_pw.Text)
  140.     End Sub
  141.  
  142.     Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
  143.         TextBox4.Text = txt_server.Text & "/" & ListBox1.SelectedItems.(0).ToString()
  144.     End Sub
  145.  
  146.     Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
  147.         If (OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
  148.             uploadFTP(OpenFileDialog1.FileName, txt_server.Text + "/" + Path.GetFileName(OpenFileDialog1.FileName), txt_user.Text, txt_pw.Text)
  149.         End If
  150.     End Sub
  151.  
  152.     Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
  153.         If (MessageBox.Show("Delete File?", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes) Then
  154.             deleteFTP(TextBox4.Text, txt_user.Text, txt_pw.Text)
  155.         End If
  156.     End Sub
  157.  
  158.     Private Sub Button5_Click(sender As System.Object, e As System.EventArgs) Handles Button5.Click
  159.         ListBox1.Items.Clear()
  160.         listFTP(txt_server.Text, txt_user.Text, txt_pw.Text)
  161.     End Sub
  162.  
  163.     Private Function Url() As String
  164.         Throw New NotImplementedException
  165.     End Function
  166.  
  167.     Private Function buff() As Byte()
  168.         Throw New NotImplementedException
  169.     End Function
  170.  
  171. End Class
  172.  

Errors:

Identifier Expected (Line 143, Column 72)
Type Expected (Line 90, Column 24)

Any help will be appreciated! Thanks,

JJE990
Nov 5 '13 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.