473,387 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Validate entered path, close form

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
7 1653
MikeTheBike
639 Expert 512MB
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
Killer42
8,435 Expert 8TB
What is tlpath ? And what is Path1?
Nov 29 '07 #3
sdanda
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
Killer42
8,435 Expert 8TB
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
sdanda
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
sdanda
36
ya I got it...I keep me.close in the true part of If clause...
Nov 29 '07 #7
MikeTheBike
639 Expert 512MB
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

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

Similar topics

9
by: varois83 | last post by:
Hi Newbie here. I have been working on creating a guestbook for my site as practice and am learning a lot. Do you guys validate your forms first on the client with javascript and then on the...
4
by: Hernán Castelo | last post by:
hi should i validate cookies values? thanks -- atte, Hernán Castelo SGA - UTN - FRBA
4
by: fred | last post by:
I'm trying to validate data entered into a form field by using a Query. I've discovered that the validation rule is pretty useless if you need anything other than very basic validation. I've...
3
by: Martin | last post by:
Hi, I am implemeting a form in asp.net. The form is quite large and the validation is reasonably complex, so I have decieded to implement my own validation rather than use any custon...
11
by: jjbutera | last post by:
I know how to use the ErrorProvider in my winforms..or do I? I validate the values and set the ErrorProvider in the validating event. If not valid, I set e.Cancel = True. I clear the ErrorProvider...
1
by: anilareddy | last post by:
I have an application like this. I need to validate the start time in 2nd row against the start row in first row. I mean The start time value entered in the second row must not b the value entered in...
5
nathj
by: nathj | last post by:
Hi, I have been looking around the forum and the web for a way to achieve this and so far I have drawn a blank. So I head to the forum as I'm sure someone knows how to do this. I have a form...
1
by: SkipNRun | last post by:
I am a novice when comes to JavaScript, AJAX. I am working on a form, which will allow users to update their contact information. In order to make the form flexible, I need to use pull down list. ...
2
by: Mick Walker | last post by:
Hi, I have a problem that I have been trying to figure for a couple of days, and am wondering if anyone out there would be so kind as to give me a solution. (Deadline time) I am trying to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.