V
V
Vahe2015-01-17 14:49:12
Visual Basic
Vahe, 2015-01-17 14:49:12

Visual Basic method or operation not performed?

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        OpenFileDialog1.Title = "Select File"
        OpenFileDialog1.Filter = "All files(*.*)|*.*"
        OpenFileDialog1.CheckPathExists = "True"
        OpenFileDialog1.CheckFileExists = "True"

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        OpenFileDialog1.ShowDialog()
        TextBox1.Text = OpenFileDialog1.FileName
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
            If TextBox1 = Acct_NoTextbox.Text Then
                MsgBox("Select file for get size!")
            Else
                If System.IO.File.Exists(TextBox1.Text) = True Then
                    Dim file As System.IO.FileInfo
                    file = My.Computer.FileSystem.GetFileInfo(TextBox1.Text)
                    MessageBox.Show(file.Length & "Bytes")
                Else
                    MsgBox("Thise file is not existes on your PC")
                End If
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

End Class

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Nemiro, 2015-01-17
@vahe_2000

I see the code, the question is not clear. We need more letters, preferably in the form of words that form sentences filled with meaning :)
According to the code, here:

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    OpenFileDialog1.ShowDialog()
    TextBox1.Text = OpenFileDialog1.FileName
End Sub

There is no dialog result handler. Should be something like:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    ' если пользователь не захотел выбирать файл, выходим
    If Not OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then Return 
    ' пользователь выбрал файл
    TextBox1.Text = OpenFileDialog1.FileName
End Sub

Here in this line:
It is better to explicitly specify the Text property when checking the value of the TextBox1 element :
Although, if you make the OpenFileDialog work normally , as I showed above, then this condition should not be needed at all. Well, or you can just check for the presence of a value in TextBox1 :
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      Try
            ' если значение TextBox1.Text - пустая строка или Nothing, то
            If String.IsNullOrEmpty(TextBox1.Text) Then 
                MessageBox.Show("Select file for get size!")
                Return ' выходим
            End If

            'можно сразу создать FileInfo и проверять существование файла через него
            Dim file As New System.IO.FileInfo(TextBox1.Text)
            If file.Exists Then
                MessageBox.Show(file.Length & "Bytes")
            Else
                MessageBox.Show("Thise file is not existes on your PC")
            End If
      Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
      End Try
End Sub

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question