Results 1 to 8 of 8

Thread: Send string to another application when check in button is clicked

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2018
    Posts
    4

    Send string to another application when check in button is clicked

    Hi all,

    I have an application in Visual Studio 20013 called H2U(Hotel Management System). And another application called Interface in Visual Studio 2013. Interface is a send & receive network packets application.

    Now when the check in button is clicked in H2U, a result string should be sent to Interface. Eg: Interface should receive the result and says this in the log "receive request from IpTV". I have written the code in H2U to generate the result string when check in button is clicked. But I don't know how to send the result to Interface application. The Interface application has IP Address Column, where the H2U IP address will be linked to the Interface column. So how to transfer the result between these 2 application. Kindly Help me. The result string is as below in H2U :

    Code:
    Public Function PostToInterface(ByVal ReservNo As String) As String
            Dim SQL As String
            Dim cmd As SqlCommand
            Dim Con As New SqlConnection(ConnStr)
            Dim result As String
            Dim BDate As String = Format(Now(), "yyMMdd")
            Dim BTime As String = Format(Now(), "HHmmss")
    
     SelectSTR = "SELECT Reservation.ReservationNo, CONVERT(varchar, Reservation.ArrivalDate, 12) As ArrivalDate,       Reservation.GuestName, Reservation.VIPStatus, RoomNo.RoomNumber, Salutation.Salutation, "
            SelectSTR += "GroupMaster.GroupID, Language.Language From Reservation "
            SelectSTR += "LEFT OUTER JOIN RoomNo ON RoomNo.RoomID = Reservation.RoomID "
            SelectSTR += "LEFT OUTER JOIN Salutation ON Reservation.SalutationID = Salutation.SalutationID "
            SelectSTR += "LEFT OUTER JOIN GroupMaster ON Reservation.GroupID = GroupMaster.GroupID "
            SelectSTR += "LEFT OUTER JOIN Language ON Reservation.LanguageID = Language.LanguageID "
            SelectSTR += "WHERE Reservation.Status = 'Registered' "
            SelectSTR += "AND Reservation.ReservationNo = '" & ReservNo & "'"
            Con.Open()
            cmd = New SqlCommand(SelectSTR, Con)
            Dim dr As SqlDataReader = cmd.ExecuteReader()
            While dr.Read()
                result = "GI|RN" & dr("RoomNumber") & "|" & "G#" & dr("ReservationNo") & "|" & "GS" & "N" & "|" & "GF" & "" & "|" &              "GN" & dr("GuestName") & "|" & "GL" & dr("Language") & "|" & "GG" & dr("GroupID") & "|" & "GT" & dr("Salutation")                & "|" & "GV0" & "|" & "NP" & "N" & "|" & "GA" & dr("ArrivalDate") & "|" & "DA" & BDate & "|" & "TI" & BTime & "|" &                  "SF" & "" & "|"
            End While
            dr.Close()
            cmd.Dispose()
            Con.Close()
    
        //Now I must pass the result to Interface
        End Function

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Send string to another application when check in button is clicked

    Did you write the Interface program?
    If it was me, I would just have another socket in the Interface program where I could send a message to it from an external program.
    But there would also be the option of using SendMessage, which I haven't used so you would have to search for how to use that.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Send string to another application when check in button is clicked

    Quote Originally Posted by Valliammai26 View Post
    I have an application in Visual Studio 20013
    You specified 2002/2003 as you VS version in the thread title prefix.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Send string to another application when check in button is clicked

    You've made your code very hard to read. For one thing, there's no need to create a String and then append to it line by line. Only VB 2017 (and 2015 I think, but I'm not sure) support multiline String literals but earlier versions still support XML literals, e.g.
    vb.net Code:
    1. Dim sql = <sql>
    2.               SELECT *
    3.               FROM MyTable
    4.               WHERE MyColumn = @MyColumn
    5.           </sql>
    6. Dim command As New SqlCommand(sql.Value, connection)
    Secondly, this is ridiculous:
    vb.net Code:
    1. result = "GI|RN" & dr("RoomNumber") & "|" & "G#" & dr("ReservationNo") & "|" & "GS" & "N" & "|" & "GF" & "" & "|" &              "GN" & dr("GuestName") & "|" & "GL" & dr("Language") & "|" & "GG" & dr("GroupID") & "|" & "GT" & dr("Salutation")                & "|" & "GV0" & "|" & "NP" & "N" & "|" & "GA" & dr("ArrivalDate") & "|" & "DA" & BDate & "|" & "TI" & BTime & "|" &                  "SF" & "" & "|"
    I see it regularly but there is nothing more ridiculous in code than concatenating multiple literals, especially if any of them are empty. That can immediately be simplified to this:
    vb.net Code:
    1. result = "GI|RN" & dr("RoomNumber") & "|G#" & dr("ReservationNo") & "|GSN|GF|GN" & dr("GuestName") & "|GL" & dr("Language") & "|GG" & dr("GroupID") & "|GT" & dr("Salutation") & "|GV0|NPN|GA" & dr("ArrivalDate") & "|DA" & BDate & "|TI" & BTime & "|SF|"
    That is immediately easier to read and thus less error-prone. It can be further simplified using String.Format though:
    vb.net Code:
    1. result = String.Format("GI|RN{0}|G#{1}|GSN|GF|GN{2}|GL{3}|GG{4}|GT{5}|GV0|NPN|GA{6}|DA{7}|TI{8}|SF|",
    2.                        dr("RoomNumber"),
    3.                        dr("ReservationNo"),
    4.                        dr("GuestName"),
    5.                        dr("Language"),
    6.                        dr("GroupID"),
    7.                        dr("Salutation"),
    8.                        dr("ArrivalDate"),
    9.                        BDate,
    10.                        BTime)
    You can also use string interpolation in more recent versions, but that's not supported in VB 2013.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Send string to another application when check in button is clicked

    If you want to send data via TCP to an application that is already setup to receive it then you should create a TcpClient object, call its Connect method and go from there. It's not really clear but, if you're asking how to design the server application as well then you would use the TcpListener class.

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2018
    Posts
    4

    Re: Send string to another application when check in button is clicked

    Quote Originally Posted by passel View Post
    Did you write the Interface program?
    If it was me, I would just have another socket in the Interface program where I could send a message to it from an external program.
    But there would also be the option of using SendMessage, which I haven't used so you would have to search for how to use that.
    I have written the interface program already. Can u show some example of adding socket in the interface program to receive the string from an external program? I never have done that before

  7. #7
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Send string to another application when check in button is clicked

    I don't understand.
    ... another application called Interface in Visual Studio 2013. Interface is a send & receive network packets application. ...
    I have written the interface program already. Can u show some example of adding socket in the interface program to receive the string from an external program? I never have done that before
    If the application called Interface is a send & receive network packets application and you wrote it, how did you send & receive network packets without using a socket? The socket(s) may be managed by a class such as TCPClient or UDPClient, but it is still what I meant by adding a socket.

    I assumed if you were already sending and receiving network packets that you could just use the same or similar technique between the two programs.
    If the two programs run on the same computer, you can even use the "loopback" ipaddress (127.0.0.1) as the IP to send to. You just need to have a known port number to send to.
    You have two options, using TCP or UDP. I can barely keep my eyes open, so I can't search for examples or make one up right now. But if you search for udpclient and tcpclient you may find some information and examples.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Send string to another application when check in button is clicked

    If you follow the CodeBank link in my signature then you can find my Asynchronous TCP thread, which shows how to use a TcpListener and a TcpClient asynchronously. If you need to maintain a responsive UI then you'll need some form of asynchronicity, but if it's a Console app then you won't and you may not for a Windows service either.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width