|
-
Oct 3rd, 2012, 03:32 PM
#1
Thread Starter
New Member
How to enabling a command only after text boxes are filled
hello
i want to know How to enabling a command only after text boxes are filled
in VB6
-
Oct 3rd, 2012, 04:34 PM
#2
Re: How to enabling a command only after text boxes are filled
Try this
Code:
Private Sub Text1_Change()
If Text1.Text = vbNullString Then
Command1.Enabled = False
Else
Command1.Enabled = True
End If
End Sub
OR
Code:
Private Sub Text1_Change()
Command1.Enabled = Not (Text1.Text = vbNullString)
End Sub
-
Oct 3rd, 2012, 05:25 PM
#3
Re: How to enabling a command only after text boxes are filled
this would work also
Code:
Private Sub Text1_Change()
Command1.Enabled = Len(Text1.Text)
End Sub
-
Oct 3rd, 2012, 07:01 PM
#4
Re: How to enabling a command only after text boxes are filled
If there are several textboxes the you could iterate thru the form's controls (Controls Collection)
Declare a boolean... set it to true
Inside the loop
Ask if it is textbox (TypeOf Is Textbox) and if it's filled... set the boolean to false if empty
...
Outside of the loop
Ask for the boolean variable
If it is true then enable command button
JG
... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...
-
Oct 3rd, 2012, 07:18 PM
#5
Re: How to enabling a command only after text boxes are filled
Ask if it is textbox (TypeOf Is Textbox)
This is VB6 forum
-
Oct 3rd, 2012, 08:42 PM
#6
Re: How to enabling a command only after text boxes are filled
TypeOf is a valid keyword in VB6
The next piece of code changes the forecolor of all Text Box controls on Form1 to red:
Code:
Dim c As Control
For Each c In Form1.Controls
If TypeOf c Is TextBox Then
c.ForeColor = vbRed
End If
Next
You'll also find this approach useful for many other tasks, such as unchecking all of the CheckBox controls.
JG
... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...
-
Oct 4th, 2012, 06:04 AM
#7
Lively Member
Re: How to enabling a command only after text boxes are filled
In form load make command button disabled. In each textbox's change event check for emptiness (Len(Text...)=0) of all text boxes, if any one is empty keep Command Button disabled.
-
Oct 4th, 2012, 06:28 AM
#8
Re: How to enabling a command only after text boxes are filled
Along the same lines as Smartchap, you can grab the length of a series of textboxes and multiply those lengths together. If any textbox is empty, it will equate to 0 and any number multipled by 0 becomes 0 and 0 will equate to False. Example:
Code:
Option Explicit
Private Sub EnableButton()
Command1.Enabled = Len(Text1.Text) _
* Len(Text2.Text) _
* Len(Text3.Text) _
* Len(Text4.Text) _
* Len(Text5.Text)
End Sub
Private Sub Command2_Click()
EnableButton
End Sub
-
Oct 4th, 2012, 06:39 AM
#9
Thread Starter
New Member
Re: How to enabling a command only after text boxes are filled
hello all
thanks for all but i want that the command button disabled at default then enabled after After writing anything on textbox
-
Oct 4th, 2012, 06:44 AM
#10
Re: How to enabling a command only after text boxes are filled
 Originally Posted by Aiman H
thanks for all but i want that the command button disabled at default then enabled after After writing anything on textbox
There are a variety of responses to your question and all of them will do what you want. Pick one.
-
Oct 4th, 2012, 06:54 AM
#11
Thread Starter
New Member
Re: How to enabling a command only after text boxes are filled
 Originally Posted by Hack
 There are a variety of responses to your question and all of them will do what you want. Pick one.
hello
yes i've tried it but the problem is that the command button shift to disabled after writing anything on textbox and clean it
i'm loocking for any way to disable the command button at default
for exemple if you open my program you will see the command button disabled at default
-
Oct 4th, 2012, 07:03 AM
#12
Re: How to enabling a command only after text boxes are filled
Set Enabled = False in design mode, on the button's property page.
-
Oct 4th, 2012, 07:33 AM
#13
Thread Starter
New Member
Re: How to enabling a command only after text boxes are filled
 Originally Posted by Hack
Set Enabled = False in design mode, on the button's property page.
thanks so much
now it work but there is a small mistake
i've 3 textbox after writing anything on one textbox, the command button shift to Enabled without considering the two other textbox
this is the codethat i've used from 4x2y:
Code:
Private Sub Text1_Change()
If Text1.Text = vbNullString Then
calculateBtn.Enabled = False
Else
calculateBtn.Enabled = True
End If
End Sub
Private Sub Text2_Change()
If Text2.Text = vbNullString Then
calculateBtn.Enabled = False
Else
calculateBtn.Enabled = True
End If
End Sub
Private Sub Text3_Change()
If Text3.Text = vbNullString Then
calculateBtn.Enabled = False
Else
calculateBtn.Enabled = True
End If
End Sub
-
Oct 4th, 2012, 08:08 AM
#14
Re: How to enabling a command only after text boxes are filled
Or he can do it like this:
Code:
Private Function EnableButton() As Boolean
EnableButton = Len(Text1.Text) _
* Len(Text2.Text) _
* Len(Text3.Text) _
* Len(Text4.Text) _
* Len(Text5.Text)
End Function
'In Every Change-Event of the particular TextBoxes:
Private Sub Text1_Change()
Command1.Enabled = EnableButton
End Sub
'The same in Form_Load-Event
Private Sub Form_Load()
Command1.Enabled = EnableButton
End Sub
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Oct 4th, 2012, 10:21 AM
#15
Re: How to enabling a command only after text boxes are filled
 Originally Posted by Aiman H
thanks so much
now it work but there is a small mistake
i've 3 textbox after writing anything on one textbox, the command button shift to Enabled without considering the two other textbox
this is the codethat i've used from 4x2y:
Code:
Private Sub Text1_Change()
If Text1.Text = vbNullString Then
calculateBtn.Enabled = False
Else
calculateBtn.Enabled = True
End If
End Sub
Private Sub Text2_Change()
If Text2.Text = vbNullString Then
calculateBtn.Enabled = False
Else
calculateBtn.Enabled = True
End If
End Sub
Private Sub Text3_Change()
If Text3.Text = vbNullString Then
calculateBtn.Enabled = False
Else
calculateBtn.Enabled = True
End If
End Sub
To stay in your example:
vb Code:
Private Function EnableButton() As Boolean
EnableButton = Len(Text1.Text) * Len(Text2.Text) * Len(Text3.Text)
End Function
Private Sub Text1_Change()
Command1.Enabled = EnableButton
End Sub
Private Sub Text2_Change()
Command1.Enabled = EnableButton
End Sub
Private Sub Text3_Change()
Command1.Enabled = EnableButton
End Sub
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Oct 4th, 2012, 01:49 PM
#16
Thread Starter
New Member
Re: How to enabling a command only after text boxes are filled
 Originally Posted by Zvoni
To stay in your example:
vb Code:
Private Function EnableButton() As Boolean
EnableButton = Len(Text1.Text) * Len(Text2.Text) * Len(Text3.Text)
End Function
Private Sub Text1_Change()
Command1.Enabled = EnableButton
End Sub
Private Sub Text2_Change()
Command1.Enabled = EnableButton
End Sub
Private Sub Text3_Change()
Command1.Enabled = EnableButton
End Sub
thanks but the problem is after set these code and run my program
when it write anything on testbox i get an error with 3 button " end - debug - help"
-
Oct 4th, 2012, 04:55 PM
#17
Re: How to enabling a command only after text boxes are filled
What is the error message?
-
Oct 4th, 2012, 05:40 PM
#18
Thread Starter
New Member
Re: How to enabling a command only after text boxes are filled
 Originally Posted by 4x2y
What is the error message?
Now The Code Work Fine
Thanks For All
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|