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

Validate entered path, close form

P: 36
I am working on windows applications(VB.net). I created a form with a textbox and one button. I would like to test the value entered in the textbox after this textbox loses the focus. The value entered in this textbox is some file path. I would like to check whether this path exists or not. But I did this in button click event. But I want to do this after the textbox loses the focus. And If the value entered in the textbox is not an existing path once again the form will appear with clear the contents of the textbox. How to do this? In my code even though the value entered in textbox is not a existing path, the form will be closed upon clicking on the button instead of showing the form with null value in the textbox. How to do this? Can anyone help me?
My code is:

Expand|Select|Wrap|Line Numbers
  1. Private Sub blok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles blok.Click
  2.             If (System.IO.File.Exists(pathl) = True) Then
  3.                 MessageBox.Show("File exist")
  4.             Else
  5.                 MessageBox.Show("The file is not found in that specified path")
  6.                 Me.Show()
  7.                 tlpath.Clear()
  8.             End If
  9.            Me.Close()
  10. End Sub
Nov 28 '07 #1
Share this Question
Share on Google+
7 Replies


Expert 100+
P: 634
I am working on windows applications(vb.net). I created a form with textbox and one button.I would like to test the value entered in the textbox after this textbox looses the focus. The value entered in this textbox is some file path. I would like to check whether this path exist or not.But i did this in button click event. But i want to do this after the textbox looses the focus. And If the value entered in the textbox is not existing path Once again the form will appear with clear the contents of the textbox. How to do this..In my code eventhough the value entered in textbox is not a exixsting path, the form will be closed upon clicking on the button instead of showing the form with null vaue in the textbox.How to do this?Can anyone help me?
My code is


Expand|Select|Wrap|Line Numbers
  1. Private Sub blok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles blok.Click
  2.             If (System.IO.File.Exists(pathl) = True) Then
  3.                 MessageBox.Show("File exist")
  4.             Else
  5.                 MessageBox.Show("The file is not found in that specified path")
  6.                 Me.Show()
  7.                 tlpath.Clear()
  8.             End If
  9.            Me.Close()
  10. End Sub
Hi
Would this do it
Expand|Select|Wrap|Line Numbers
  1. Private Sub blok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles blok.Click
  2.         If (System.IO.File.Exists(pathl) = True) Then
  3.             MessageBox.Show("File exist")
  4.             Me.Close()
  5.         Else
  6.             MessageBox.Show("The file is not found in that specified path")
  7.             tlpath.Clear()
  8.         End If
  9. End Sub
??

MTB
Nov 28 '07 #2

Expert 5K+
P: 8,434
What is tlpath ? And what is Path1?
Nov 29 '07 #3

P: 36
Sorry for incomplete information...tlpath is the textbox name. and pathl is variable. I assign the textbox value to this varable..


Private Sub blok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles blok.Click
Dim f1 As New Form1

pathl = tlpath.Text.ToString
If (System.IO.File.Exists(pathl) = True) Then
MessageBox.Show("File exist")
Else
MessageBox.Show("The file is not found in that specified path")
Me.Show()
tlpath.Clear()
End Sub.
Nov 29 '07 #4

Expert 5K+
P: 8,434
This sounds to me as though it should work. Except that I would move the Clear before the Show.

Do you get the dialog?
Nov 29 '07 #5

P: 36
I would like to close the dialog upon clicking on the button if and onlt if the value entered in the textbox is correct. so I wrote my code like this
Expand|Select|Wrap|Line Numbers
  1. Private Sub blok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles blok.Click
  2.          pathl = tlpath.Text.ToString
  3.  
  4.             If (System.IO.File.Exists(pathl) = True) Then
  5.                 MessageBox.Show("File exist")
  6.             Else
  7.                 MessageBox.Show("The file is not found in that specified path")
  8.                 tlpath.Clear()
  9.                 Me.Show()
  10.             End If
  11.             Me.Close()
  12.  End Sub
  13.  
In the above if i remove the line me.close its working correctly.. But i want to close the dialog after clicking on the button(If the value entered in the textbox is correct). If i keep me.close line it closes the dialog eventhough the textbox value is not a correct path. I want to show the dialog if the value entered in the textbox is not the correct one, if it is correct value then closes the dialog.Can u plz help me?
Nov 29 '07 #6

P: 36
ya I got it...I keep me.close in the true part of If clause...
Nov 29 '07 #7

Expert 100+
P: 634
ya I got it...I keep me.close in the true part of If clause...
Glad you got there in the end !

MTB
Nov 29 '07 #8

Post your reply

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