Solved

VB.Net code Just not working

Posted on 2014-04-06
11
249 Views
Last Modified: 2014-04-07
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

0
Comment
Question by:mickeyshelley1
  • 6
  • 4
11 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 39982063
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.
0
 

Author Comment

by:mickeyshelley1
ID: 39982071
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
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 39982077
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

0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 29

Expert Comment

by:Paul Jackson
ID: 39982079
try :

If  txtComEditNar.Text = String.Empty Then
0
 

Author Comment

by:mickeyshelley1
ID: 39982085
If txtComEditNar has no data then i get the word "false" if there is data the code runs correctly
0
 

Author Comment

by:mickeyshelley1
ID: 39982098
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

0
 

Author Comment

by:mickeyshelley1
ID: 39982105
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

0
 

Author Comment

by:mickeyshelley1
ID: 39982122
I've requested that this question be closed as follows:

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

for the following reason:

Solved
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39982114
First you are assigning the value on the right to the same variable on the left twice so the code snippet removes that second variable. I can not see this code assigning false to the text box. You should get the date and the text in the label.

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

Open in new window

0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 39982123
The code I posted was used to correct the problem. The points should be awarded.
0
 

Author Closing Comment

by:mickeyshelley1
ID: 39983683
that was the issue
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.net Move a class from Solution Items to a project 2 32
VB.NET 1 27
Help with converting xml file to excel using VB.NET 3 25
Error message when using PrintSocket.Send 7 18
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question