Text from Texboxes in Tabs

stevecking

Active member
Joined
Dec 27, 2006
Messages
32
Programming Experience
5-10
I have an application where I check the length of the text in textboxes with If Len(txtAnalysis.Text) > 0. Frequently this does not find text that IS in the textboxes. After I click to open each tabpage on the tab control it always seems to locate the text properly. Do I need to set the focus to these textboxes or tabs in some way before checking the length? I do not seem to have this problem in controls on the main form.:confused:
 
Posted Code

Here is the first part of the sub, going to the first check for lenth of the text. Everything works but when I create the body no data is included for SOME of the check textboxes. Those in textboxes part of a tab on a tabcontrol seem to be the guilty parties.

Private Sub btnMessage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMessage.Click
Dim oMailApp, oMail As Object
Dim strTO As String = ""
Dim strTitle As String = ""
Dim strBody As String = ""
Dim strDescription As String = ""
Dim strHistory As String = ""
Dim strConfig As String = ""
Dim strAnalysis As String = ""
Dim strComments As String = ""
Dim strInstructions As String = ""
Dim strCorrectiveAction As String = ""
Dim strComment As String = ""
Dim strStatus As String = ""
Dim strApproval As String = ""
Dim strClass As String = ""
Try
' Initilize the Outlook objects using late binding
oMailApp = CreateObject("Outlook.Application")
oMail = oMailApp.CreateItem(olMailItem)
Catch ex As Exception
' Any failure could only result from not being
' able to instantiate the Outlook objects
MsgBox("Microsoft Outlook not running. " & ex.Message)
Exit Sub
End Try
Try
' Set all string values from the form controls
If Len(Me.cboApproval.Text) > 0 Then
strApproval = "Approval: " & Me.cboApproval.Text.ToString & vbCrLf & vbCrLf
End If

strBody = strClass & strStatus & strApproval & strInstructions & strDescription & strHistory & strAnalysis & strCorrectiveAction & strComments & strConfig & strComment
 
You're checking the length of the text in a ComboBox. It's the same ComboBox no matter what, so what does the TabControl have to do with anything? I'd guess the same is true for the TextBoxes.

Also, don't use Len(). The Text property is type String so use its Length property.

Also, as the Text property is type String there is no point calling its ToString method.

Also, don't use vbCrLf. Use ControlChars .NewLine or Environment.NewLine.

Also, don't use a literal empty string, i.e. don't set a variable to "". Use the String.Empty property.


Also, using string concatenation like that is very inefficent. You should be using String.Format or a StringBuilder.
 
Appreciate the Advice

I'll take you advice. As you can easily detect, I'm a VB developer converting to vb.net so I've fallen into a slight trap of using code I'm familiar with and assuming it will convert directly.
 
I've implemented every recommendation and still the text does not include text from textboxes on tabs in a tabcontrol unless I first click each tab. I am unable to explain why, which is the reason for the post. I have six tabs beginning with 'Description' which is the default tab displayed on the form. The Error, Analysis, CorrectiveAction, Test, and Config tabs won't give up their text without a fight. Everything else is always displayed.
 
Are all these controls created at design time? How are they being populated with data? If a control contains text then there's no reason that you shouldn't be able to access that text directly, regardless of the TabControl.
 
Back
Top