Link to home
Start Free TrialLog in
Avatar of mickeyshelley1
mickeyshelley1Flag for United States of America

asked on

VB.Net code Just not working

I cant seem to get this code straight i know the sendkeys seem to be a problem but even when I comment them out the code still ignore the first if statement

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Dim cmdinfo As String
        cmdinfo = CAD.txtUnit.Text & " " & "ADV EST" & " " & CAD.txtLocation.Text & " " & "COMMAND"
        If IsDBNull(txtComEditNar) = True Then
            txtComEditNar.Text = DateTime.Now.ToString("MM/dd/yyyy-HH:mm") & " [" & UCase(CAD.lblOperator.Text) & "]:" & vbCrLf
            txtComEditNar.Text = txtComEditNar.Text = DateTime.Now.ToString("MM/dd/yyyy-HH:mm") & " [" & UCase(CAD.lblOperator.Text) & "]:" & vbCrLf & " " & cmdinfo
            txtComEditNar.Focus()    'Goes to the appropriate control
            SendKeys "{f2}"         'Switches from navigation to text entry mode _
            SendKeys "{end}"      'Goes to the end of the field


            Exit Sub

        Else

            Dim nicholas As String
            nicholas = txtComEditNar.Text
            txtComEditNar.Text = nicholas & vbCrLf & DateTime.Now.ToString("MM/dd/yyyy-HH:mm") & " " & " [" & UCase(Environ$("Username")) & "] " & vbCrLf & " " & cmdinfo


            txtComEditNar.Focus()    'Goes to the appropriate control
            SendKeys "{f2}"         'Switches from navigation to text entry mode
            SendKeys "{end}"     'Goes to the end of the field
        End If
    End Sub
End Class

Open in new window

Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi mickeyshelley1;

Is the object type of txtComEditNar a database value? IsDBNull can not test to see if an object is Nothing. DBNull and Nothing are two different types.


From Microsoft documentation:
IsDBNull returns True if the data type of Expression evaluates to the DBNull type; otherwise, IsDBNull returns False.

The System.DBNull value indicates that the Object represents missing or nonexistent data. DBNull is not the same as Nothing, which indicates that a variable has not yet been initialized. DBNull is also not the same as a zero-length string (""), which is sometimes referred to as a null string.
Avatar of mickeyshelley1

ASKER

txtComEditNar  is a multi line textbox that may or may not contain text, i also tried  txtComEditNar .text ="" but it didnt seem to make a difference
Hi mickeyshelley1;

Change your If state to this and give it a try.

If String.IsNullOrEmpty(txtComEditNar.Text) Then
    ' ...
Else
    ' ...
End If

Open in new window

try :

If  txtComEditNar.Text = String.Empty Then
If txtComEditNar has no data then i get the word "false" if there is data the code runs correctly
The problem seems to be in this line
 txtComEditNar.Text = txtComEditNar.Text = DateTime.Now.ToString("MM/dd/yyyy-HH:mm") & " [" & UCase(CAD.lblOperator.Text) & "]:" & vbCrLf & " " & cmdinfo

Open in new window

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Dim cmdinfo As String
        Dim nicholas As String
        nicholas = txtComEditNar.Text
        cmdinfo = CAD.txtUnit.Text & " " & "ADV EST" & " " & CAD.txtLocation.Text & " " & "COMMAND"
        If String.IsNullOrEmpty(txtComEditNar.Text) = True Then

            txtComEditNar.Text = DateTime.Now.ToString("MM/dd/yyyy-HH:mm") & " [" & UCase(CAD.lblOperator.Text) & "]:" & vbCrLf
            txtComEditNar.Text = nicholas & DateTime.Now.ToString("MM/dd/yyyy-HH:mm") & " " & " [" & UCase(Environ$("Username")) & "] " & vbCrLf & " " & cmdinfo
            MsgBox(cmdinfo)


            Exit Sub

        Else

            txtComEditNar.Text = nicholas & vbCrLf & vbCrLf & DateTime.Now.ToString("MM/dd/yyyy-HH:mm") & " " & " [" & UCase(Environ$("Username")) & "] " & vbCrLf & " " & cmdinfo


        End If
    End Sub

Open in new window

I've requested that this question be closed as follows:

Accepted answer: 0 points for mickeyshelley1's comment #a39982105

for the following reason:

Solved
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The code I posted was used to correct the problem. The points should be awarded.
that was the issue