Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB buttons Text
Hello, I am new to Visual Basic so I have so me questions here.
 
I have created a form where there are 3 textboxes namely: Name, Last Name and Address. And below there is a button where the user has to click, the information will be saved to drive C.
Posted 19-Mar-11 22:16pm
555336631
Edited 11-Apr-11 9:44am
v2
Comments
Аslam Iqbal at 20-Mar-11 5:54am
   
VB6 or VB.NET?
bunnyali2011 at 20-Mar-11 6:06am
   
Visual Basic
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

There are 2 ways to solve ur problem..
 
1) Method First:
 
(a)U should change the Property of "Save" Button to enable false at the time of form load event (or set the "Save" Button enable property to False at design time from the property window in VB 6.0)
 
(b) Then enable the "Save" Button Property only when Textbox properties of all 1 or 2 or all 3 (i.e. Name, Last Name & Address textbox changing event)
 
By this u can Stop the user & validate that whatever user fill the Text box and u can stop user to click on save button without filling the Textboxes and there will be no empty recorded will be inserted into the Database.
 
2) Method Second:
(a) U can also change the Property of "Save" Button to enable false at the Run-time. By placing the following code on the form load event.
 
(Assuming that ur Save Button name is btnSave)
 

Form Load()
 
   btnSave.enable=False
 
End Sub
 

(b) Placed following code on the TextBox(s) changing event
(Assuming that ur Name, Last Name and Address Textboxes names are txtName, txtLName & txtAddress respectively)
 

 
Private Sub txtName_Changing(ByVal sender As Object, ByVal e As System.EventArgs)
 
        If Not txtName.Text = "" Then
            btnSave.Enabled = True
        End If
 
Private Sub txtLName_Changing(ByVal sender As Object, ByVal e As System.EventArgs)
 
        If Not txtLName.Text = "" Then
             btnSave.Enabled = True
        End If
 
Private Sub txtAddress_Changing(ByVal sender As Object, ByVal e As System.EventArgs)
 
        If Not txtAddress.Text = "" Then
             btnSave.Enabled = True
        End If
 
Use One of these method to solve ur problem.
  Permalink  
v2
Comments
bunnyali2011 at 20-Mar-11 6:06am
   
Hello, I tried the above examples and they work thank you. But there is a problem, I have included a combobox, numecicupanddown and a maskedtextbox as well.
 
However, I am having difficulties when doing the coding for the three above. For example, my combo box is 'cboDrawer', so when I do:
 
If Not cboDrawer.Text = " " Then
btnSave.Enabled = True
End If
 
it does not work, as there is no 'Text' after I put the 'cboDrawer.' compared to the other textboxes. For numericupanddown and maskdtextbox also the same.
 
How to do that?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Hello again,
 
Now u have 3 different tools (which are not text boxes) i.e. combobox, numecicupandown and maskedtextbox
remain ur "Save" Button enable property to False
palce following codes:
 
1) For Combobox: (Assuming that ur combo box is "cboDrawer")
 
Private Sub cboDrawer_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboDrawer.SelectedIndexChanged
If Not cboDrawer.Text = cboDrawer.SelectedText Then
btnSave.Enabled = True
End If
End Sub
 

2) For Numecicupanddown: (Assuming that ur box is "NupDown")
 
Private Sub NupDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NupDown.ValueChanged
If Not NupDown.Increment = Nothing Then
btnSave.Enabled = True
End If
End Sub
 

3) For Maskedttextbox: (Assuming that ur box is "mtxtValue")
 
Private Sub mtxtValue_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles mtxtValue.LostFocus
If Not mtxtValue.Text = "" Then
btnSave.Enabled = True
End If
End Sub
 

Try This one & Best of Luck....!
  Permalink  
Comments
bunnyali2011 at 20-Mar-11 14:32pm
   

 
Thank you
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Hi,
So u want the maskedtextbox to be disabled from filling...
I assume that u hv items Product Size and Cost but ur maskedtextbox should be enable only both Combo box Items are selected i.e. When u select Products size from Products combo box and cost from Cost combo box
 
I assume that ur first combo box is & Product Size and second one is Cost
 
(Assuming that first combo box name is cboProductsize & second one is cbocost & maskedtextbox name is mtxtValue)
 
(1) First change maskedtextbox Enable property to False
 
(2) Now place the following code on the Lost Focus Event of Cost combo box if u want ur maskedtextbox should be enabled only when both of these combo boxes (i.e. cboProductsize and cboCost) will be selected otherwise it will be disabled.
 

Private Sub cbocost_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbocost.LostFocus
If Not (cboProductsize.Text = cboProductsize.SelectedText) And Not (cbocost.Text = cbocost.SelectedText) Then
mtxtValue.Enabled = True
End If
End Sub
 

OR
 
(2) But if ur first combo box is Cost and second one is Product Size than same code will be placed on the Lost Focus Event of Product Size combo box...
 

i.e.
 
Private Sub cboProductsize_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboProductsize.LostFocus
If Not (cboProductsize.Text = cboProductsize.SelectedText) And Not (cbocost.Text = cbocost.SelectedText) Then
mtxtValue.Enabled = True
End If
End Sub
 

Hope this simple code solve ur problem..
  Permalink  
Comments
bunnyali2011 at 21-Mar-11 15:20pm
   
Hi, by the way I have already managed and I did it. Thank you for your time and help friend. However, Im having immense difficulties doing a search box.
 
Well, I have to do a search textbox, which will be based on two categories of search.
 
When a user makes a query, he has to get results from a text file in the drive C.
 
I included a combobox with two items namely: Product and All categories.
 
How to do a code, when the user will select "Product" on the combobox, he has to get the results on a richtextbox included in the form? The search box also should have a feature where if the the user mmakes a misspelling mistake, he will get the results as well.
 
Can you help me in terms of streamreader on itt as it must read the text file in the drive C.
 
Thank you
Khaleel-Ahmed at 22-Mar-11 13:08pm
   
Hi,
Sorry friend due to busy shedule I reply late. U ask a query but i m little bit confused in it I think u want User interface form like windows explorer search box?
Could u plz gave some more details So will understand ur problem & try to solve it..
 
Have nice day...
 
bunnyali2011 at 22-Mar-11 13:42pm
   
Imagine there is search box (textbox), and below there are a search button
Thank you!
Khaleel-Ahmed at 24-Mar-11 1:14am
   
Hi,
 
U r using text file where data is stored if u use access database file as Back-End so ur problem will solved easily..
 
If inplace of text file database can be used than ur data should also be secure & any query can be applied to it so u get results acording to as required.
 
So I suggest plz try to use access database so i can provide easy solution for it.
 
Inform me soon i m waiting ur reply..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can try this simple solution:
Keep Save_button enable.
Inside button_Click Event:
If txt1.text="" or txt2.text="" or txt3.text="" then
 msgbox "Please fill all text boxes"
 exit sub ' return
end if
''Here the main execution starts.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

In general, you do not want to disable a button just because the input data are not complete. Because the user would be lost when he/she gets nowhere to go. Or he/she would click other buttons if any exists.
 
The way to do the validation is to give the user choices of input, then when he/she click the button, the code does the validation and provide helpful massege.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Mathew Soji 274
1 BillWoodruff 270
2 Afzaal Ahmad Zeeshan 244
3 Sergey Alexandrovich Kryukov 240
4 Raul Iloc 160
0 OriginalGriff 6,219
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,103
3 Manas Bhardwaj 4,549
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 11 Apr 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100