473,566 Members | 3,273 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validate entered path, close form

36 New Member
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 1660
MikeTheBike
639 Recognized Expert Contributor
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 Recognized Expert Expert
What is tlpath ? And what is Path1?
Nov 29 '07 #3
sdanda
36 New Member
Sorry for incomplete information...t lpath is the textbox name. and pathl is variable. I assign the textbox value to this varable..


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

pathl = tlpath.Text.ToS tring
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 Recognized Expert Expert
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 New Member
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 New Member
ya I got it...I keep me.close in the true part of If clause...
Nov 29 '07 #7
MikeTheBike
639 Recognized Expert Contributor
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
2697
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 server with PHP or just use one of the two and if yes which one? I don't want to reinvent the wheel too much. Thanks a lot
4
2108
by: Hernán Castelo | last post by:
hi should i validate cookies values? thanks -- atte, Hernán Castelo SGA - UTN - FRBA
4
3482
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 tried using the following After Update Code: Dim strSQL strSQL = "SELECT tblProducts.ProductSRP FROM tblProducts" strSQL = & "Where...
3
5948
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 validators, so I have a button on the form and the "causes validation" property is set to true. I have overridden the "Validate()" like so
11
11746
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 in the validated event. Is there a way to know if all validated controls pass validation when the user clicks an OK button? In ASP.Net there's...
1
1866
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 1st and the value entered in 3rd must not b the value entered in 1st,2nd etc.. like this. Please tell me how it can be done. I'm sending the code...
5
2559
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 which I validate as the user enters data, this is straight forward enough. Part of the validation ensures that all mandatory fields are entered before...
1
3980
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. Depends on the pull down list selection, I use script.aculo.us to validate the user input before submit and pass the necessary data, such as contact...
2
1935
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 validate a form. Its quite a simple form, but I am a wee bit stuck. Baically it consists of 9 text input fields and a select element. All elements on...
0
7673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6263
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.