validaition check... urgent...

Thread Solved

Join Date: Aug 2008
Posts: 53
Reputation: smile4evr is an unknown quantity at this point 
Solved Threads: 2
smile4evr's Avatar
smile4evr smile4evr is offline Offline
Junior Poster in Training

validaition check... urgent...

 
0
  #1
Oct 12th, 2008
hey all!
please help me to check for validaiton such that... i hv few textboxes and combo boxes and if data is not entered in them then the submit button should be locked... and also tell me where should i write the code as in .... in form_load or submit_click... im confused... the code i wrote was...


Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2.  
  3. If cname.Text = "" Or empname2.Text = "" Or reason2.Text = "" Or days2.Text = "" Or approval.Text = "Yes" Then
  4. MsgBox "Please fill all details"
  5. SUBMIT2(1).Enabled = False
  6. Else: SUBMIT2(1).Enabled = True
  7. End If


thanks a tonne... plz do help!
good day!... enjoy programming!...
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: validaition check... urgent...

 
0
  #2
Oct 12th, 2008
Submit or Ok-button is the proper place to validate input. Since you have many things to validate, I would use a separate function:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Function ValidateForm() As Boolean
  2. ' Validate form fields
  3. If cname.Text = "" Or empname2.Text = "" Or reason2.Text = "" Or days2.Text = "" Or approval.Text = "Yes" Then
  4. MsgBox "Please fill all details"
  5. ValidateForm = False
  6. Exit Function
  7. End If
  8. ValidateForm = True
  9.  
  10. End Function
and in the Submit or Ok-button validate:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Command1_Click()
  2. ' Ok-button, validate before exit
  3. If ValidateForm Then
  4. ' Fields are ok, return from the form
  5. Me.Hide
  6. End If
  7. End Sub
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 300
Reputation: jireh is an unknown quantity at this point 
Solved Threads: 42
jireh's Avatar
jireh jireh is offline Offline
Posting Whiz

Re: validaition check... urgent...

 
0
  #3
Oct 13th, 2008
You can also make the function as common for all...

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Public Function isAllFilledUp(frm As Form) As Boolean
  2. Dim ctrl As Control
  3.  
  4. isAllFilledUp = True
  5. For Each ctrl in frm
  6. If TypeOf ctrl Is TextBox Then
  7. If ctrl = vbNullString Then
  8. isAllFilledUp = False
  9. Exit Function
  10. End If
  11. End If
  12. Next
  13. End Function
Last edited by jireh; Oct 13th, 2008 at 8:33 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 44
Reputation: K.Vanlalliana is an unknown quantity at this point 
Solved Threads: 3
K.Vanlalliana K.Vanlalliana is offline Offline
Light Poster

Re: validaition check... urgent...

 
0
  #4
Oct 13th, 2008
There are many ways to validate whether it is a text box or a button or submit button, the way you write the code and the place you put your code can be vary, depending upon your decision, one simple way is to write the validation code and make that code as public so that you can call it from any where and any time you need. Let me give you one example:

Public Sub ControlMyButton()

if MyText1.Text="" OR MyCombo.Text="" then
Submitbutton.enable=False
else
Submitbutton.enable=True
end if

End Sub


The above code can be easily called (Instead of writing in event of the form) like this:
Say in the KeyUp Event of the text Box:

Call ControlMyButton


Even, In the MyText1_Change, and in the form Load event you can called 'Call ControlMyButton'

So, Only when the textbox is filled, the button will be enabled.

I think this will give you an Idea. Try in different way. Its not difficult.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 53
Reputation: smile4evr is an unknown quantity at this point 
Solved Threads: 2
smile4evr's Avatar
smile4evr smile4evr is offline Offline
Junior Poster in Training

Re: validaition check... urgent...

 
0
  #5
Oct 14th, 2008
thanks a lot for the responses... but its not working... i tried each of them invidually... but it is not working...
sorry... pls do keep helping!
thnx!
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: validaition check... urgent...

 
0
  #6
Oct 14th, 2008
No. None of them is a complete solution and nobody can give one without seeing the whole code.

There may be a just a little spot everyone's missed. Can you give more details?

But few things to try out:
Text may contain spaces, so trim them off like Trim(cname.Text) = ""
Then split your validation code to validate every control separately:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. If Trim(cname.Text) = "" Then
  2. MsgBox "Please fill all details (cname)"
  3. End If
  4. If Trim(empname2.Text) = "" Then
  5. MsgBox "Please fill all details (empname)"
  6. End If
  7. ... etc.
and tell us at which point validation fails and what was the input. You may do validation in any of the suggested places (Ok_Click, Form_Unload etc.).
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 300
Reputation: jireh is an unknown quantity at this point 
Solved Threads: 42
jireh's Avatar
jireh jireh is offline Offline
Posting Whiz

Re: validaition check... urgent...

 
0
  #7
Oct 14th, 2008
Ok, I will just correct your code and make a little changes to make it more useful...

your code...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. If cname.Text = "" Or empname2.Text = "" Or reason2.Text = "" Or days2.Text = "" Or approval.Text = "Yes" Then
  2. MsgBox "Please fill all details"
  3. SUBMIT2(1).Enabled = False
  4. Else: SUBMIT2(1).Enabled = True
  5. End If

put your code in a function let's name it as isFilledUp()

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Function isFilledUp() As Boolean
  2. isFilledUp = True
  3.  
  4. If Trim(cname.Text) = "" Then
  5. Msgbox "Please enter Customer Name."
  6. cname.SetFocus
  7. isFilledUp = False
  8. Exit Function
  9. End If
  10.  
  11. If Trim(empname2.Text) = "" Then
  12. Msgbox "Please enter Employee Name."
  13. empname2.SetFocus
  14. isFilledUp = False
  15. Exit Function
  16. End If
  17.  
  18. If Trim(reason2.Text) = "" Then
  19. Msgbox "Please enter reason."
  20. reason2.SetFocus
  21. isFilledUp = False
  22. Exit Function
  23. End If
  24.  
  25. If Trim(days2.Text) = "" Then
  26. Msgbox "Please enter days."
  27. days2.SetFocus
  28. isFilledUp = False
  29. Exit Function
  30. End If
  31.  
  32. If Trim(approval.Text = "Yes" Then
  33. Msgbox " " 'put your comment here.
  34. isFilledUp = False
  35. Exit Function
  36. End If
  37. End Function

Suppose you have a save button...

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub btnSave_Click()
  2. If Not isFilledUp Then
  3. SUBMIT2(1).Enabled = False
  4. 'add your code here if not all were filled up
  5. Else
  6. SUBMIT2(1).Enabled = True
  7. 'add your code here if all are filled up
  8. End If
  9. End Sub

Huh! so much homework... Hope this would help you.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: validaition check... urgent...

 
0
  #8
Oct 14th, 2008
smile4evr said there are also combo boxes. Could the validation fail with combos?
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 300
Reputation: jireh is an unknown quantity at this point 
Solved Threads: 42
jireh's Avatar
jireh jireh is offline Offline
Posting Whiz

Re: validaition check... urgent...

 
0
  #9
Oct 14th, 2008
WT?!!! just replace the checking in textboxes to combo boxes... You guys still in school? think this is a homework... anyways...
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 8
Reputation: Bhatti302 is an unknown quantity at this point 
Solved Threads: 1
Bhatti302 Bhatti302 is offline Offline
Newbie Poster

Re: validaition check... urgent...

 
0
  #10
Oct 15th, 2008
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dear I think I Solve Your Problime.
  2. When You Open Your Curent Form VB use
  3.  
  4. Private sub Form1_load()
  5.  
  6. endsub
  7.  
  8. this Code is used for Form Load. When You Form Load You enter the following Code
  9.  
  10. Private sub form1_load()
  11. text1.text=""
  12. text2.text=""
  13. text3.text=""
  14. text4.text=""
  15. Command1.Enable=false
  16. Msgbox "Enter All Deatiles && fill All Fileds",VBInformation,"Add Detailes"
  17. end Sub
  18.  
  19.  
  20. I Hope This Code Work Accourding To Your Problime
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC