-
Feb 23rd, 2007, 05:08 AM
#1
Thread Starter
New Member
[RESOLVED] how to check textbox/listbox not empty
What is the syntax to check the textbox and listbox values are not empty?
-
Feb 23rd, 2007, 05:15 AM
#2
Re: how to check textbox/listbox not empty
VB Code:
Private Sub Command1_Click()
If Text1.Text = "" Then MsgBox "textbox empty"
If List1.ListCount = 0 Then MsgBox "Listbox empty"
End Sub
-
Feb 23rd, 2007, 05:17 AM
#3
Re: how to check textbox/listbox not empty
VB Code:
'Textbox
If Len(Text1.Text) = 0 Then
Else
End If
VB Code:
'Listbox
If List1.ListCount = 0 Then
Else
End If
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Feb 23rd, 2007, 05:28 AM
#4
Thread Starter
New Member
Re: how to check textbox/listbox not empty
No both didnt work in my case.
I want to enable Command1 button enabled only if both text1 and text2 are not empty. I fill the 2 textboxes one after the other in the form after I run the pgm. Once I fill one text box and if I enter a single character also in the next textbox, the Command1 button shd be enabled.
I want to enable Command2 button only if listbox is not empty.
The same is the case with listbox also. As soon as a single list is added in the listbox, Command2 button shd be enabled.
----------------------------------------
Private Sub Form_Load()
Command1.Enabled = False
Command2.Enabled = False
If Text1.Text = "" And Text2.Text = "" Then
Command1.Enabled = False
Else
Command1.Enabled = True
End If
If List1.ListCount > 0 Then
Command2.Enabled = True
End If
End Sub
-
Feb 23rd, 2007, 05:34 AM
#5
Re: how to check textbox/listbox not empty
Well you only stated you wanted to check the values and nothing about what you actually wanted to do.
There are other events then you you will need to code to have the changes apply correctly. Completely different issue here.
VB Code:
Private Sub Form_Load()
Command1.Enabled = False
Command2.Enabled = False
End Sub
Private Sub Text1_Change()
If Len(Text1.Text) > 0 And Len(Text2.Text) > 0 Then
Command1.Enabled = True
Else
Command1.Enabled = False
End If
End Sub
Private Sub Text2_Change()
If Len(Text1.Text) > 0 And Len(Text2.Text) > 0 Then
Command1.Enabled = True
Else
Command1.Enabled = False
End If
End Sub
No for the listbox you need to provide more info as what is the event or criteria that an item will be added? After adding it via your code just endable the Command2 button. When items are removed via your code just disable the button if there are not more items in it.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Feb 23rd, 2007, 05:49 AM
#6
Re: how to check textbox/listbox not empty
Rather make a control array of Text1 TextBox:
VB Code:
Private Sub Text1_Change(Index As Integer)
If Len(Text1(0).Text) > 0 And Len(Text1(1).Text) > 0 Then
Command1.Enabled = True
Else
Command1.Enabled = False
End If
End Sub
If not anything, less code
-
Feb 23rd, 2007, 06:04 AM
#7
Thread Starter
New Member
Re: how to check textbox/listbox not empty
Thanks RobDog888!!! Its working fine now
Cheers
-
Feb 23rd, 2007, 11:47 AM
#8
Re: [RESOLVED] how to check textbox/listbox not empty
VB Code:
Private Sub Text1_Change()
Command1.Enabled = (Len(Text1.Text) > 0) And (Len(Text2.Text) > 0)
End Sub
Same for Text2
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Feb 24th, 2007, 07:15 AM
#9
Thread Starter
New Member
Re: [RESOLVED] how to check textbox/listbox not empty
I want my Command1 button to be enabled if I select any Combo1.text other than default text. I tried the following. Its not working. How shd I go abt it?
----------
Private Sub Combo1_Change()
If Combo1.Text <> "Combo1" Then
Command1.Enabled = True
Else
Command1.Enabled = False
End If
End Sub
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
|