By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,365 Members | 3,095 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,365 IT Pros & Developers. It's quick & easy.

VB.NET: Receive string from the module and use it to the form

P: n/a
Hi

Does anyone know how to stay connected to the server and at the same time i
can pass the string to and from the module to the form.....

What I want:

I put the connection at the module.....

1)I can pass the string from the form to the module...
(Because there is send and receiveInfo method from the server so i put both
methods to the module)
2)I receive that string from the module and pass it to the form...
3)The form will show that string to the textbox...

But now step 3 can't work...
It receive nothing from the module..

Any idea how to use correct it..... or i implement wrongly...

Now i can only display the contents at the Start of a new form through the
module as MessageBox when i receive from the server...

But can't display it to the textbox in the form because can't pass the
string from the module to the form...

Thanks
--------------------------------------------------------------------
My Codes:

In the previous form....

Private Sub btnNextActivity_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNextActivity.Click

Dim s As String
Dim dd As New form2
dd.Show()

Connect()
Name = "Apple"
s = "<Fruit Type=" & """" & Name & """" & "></Fruit>"
send(s)
receiveInfo()
Me.Hide()
End Sub
-------------------------------------------------------------------

In the Module....

Public Name As String

Public Sub send(ByVal s As String)

Dim ascii As Encoding = Encoding.ASCII
Dim networkStream As NetworkStream

Try
networkStream = tcpC.GetStream()
Dim sendBytes As Byte()
sendBytes = ascii.GetBytes(s)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Catch ex As Exception
Console.WriteLine("Sorry. This NetWorkStream is not connect to the server.")
End Try
End Sub
----------------------------------------------------------------------------
--
Public Sub receiveInfo()

Dim ascii As Encoding = Encoding.ASCII
Dim networkStream As NetworkStream

Try
networkStream = tcpC.GetStream()
Dim bytes(tcpC.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpC.ReceiveBufferSize))
Dim ret As String = ascii.GetString(bytes)
MessageBox.Show(ret)

Catch
Console.WriteLine("Sorry. This NetWorkStream is not connect to the server.")
End Try
End Sub

--
toytoy - forum member
http://www.visual-basic-data-mining.net/forum
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi,

Try something like this.

In the module

Public function receiveInfo() as string

Dim ascii As Encoding = Encoding.ASCII
Dim networkStream As NetworkStream

Try
networkStream = tcpC.GetStream()
Dim bytes(tcpC.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpC.ReceiveBufferSize))
Dim ret As String = ascii.GetString(bytes)
return ret

Catch
Console.WriteLine("Sorry. This NetWorkStream is not connect to the server.")
return "An error has occured"
End Try
End Sub

In the form

Private Sub btnNextActivity_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNextActivity.Click

Dim s As String
Dim dd As New form2
dd.Show()

Connect()
Name = "Apple"
s = "<Fruit Type=" & """" & Name & """" & "></Fruit>"
send(s)
frm.textbox1.text = receiveInfo()
Me.Hide()
End Sub

Ken
----------------------------
"http://www.visual-basic-data-mining.net/forum" <si******@gmail.com> wrote
in message news:ur**************@TK2MSFTNGP12.phx.gbl...
Hi

Does anyone know how to stay connected to the server and at the same time i
can pass the string to and from the module to the form.....

What I want:

I put the connection at the module.....

1)I can pass the string from the form to the module...
(Because there is send and receiveInfo method from the server so i put both
methods to the module)
2)I receive that string from the module and pass it to the form...
3)The form will show that string to the textbox...

But now step 3 can't work...
It receive nothing from the module..

Any idea how to use correct it..... or i implement wrongly...

Now i can only display the contents at the Start of a new form through the
module as MessageBox when i receive from the server...

But can't display it to the textbox in the form because can't pass the
string from the module to the form...

Thanks
--------------------------------------------------------------------
My Codes:

In the previous form....

Private Sub btnNextActivity_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNextActivity.Click

Dim s As String
Dim dd As New form2
dd.Show()

Connect()
Name = "Apple"
s = "<Fruit Type=" & """" & Name & """" & "></Fruit>"
send(s)
receiveInfo()
Me.Hide()
End Sub
-------------------------------------------------------------------

In the Module....

Public Name As String

Public Sub send(ByVal s As String)

Dim ascii As Encoding = Encoding.ASCII
Dim networkStream As NetworkStream

Try
networkStream = tcpC.GetStream()
Dim sendBytes As Byte()
sendBytes = ascii.GetBytes(s)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Catch ex As Exception
Console.WriteLine("Sorry. This NetWorkStream is not connect to the server.")
End Try
End Sub
----------------------------------------------------------------------------
--
Public Sub receiveInfo()

Dim ascii As Encoding = Encoding.ASCII
Dim networkStream As NetworkStream

Try
networkStream = tcpC.GetStream()
Dim bytes(tcpC.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpC.ReceiveBufferSize))
Dim ret As String = ascii.GetString(bytes)
MessageBox.Show(ret)

Catch
Console.WriteLine("Sorry. This NetWorkStream is not connect to the server.")
End Try
End Sub

--
toytoy - forum member
http://www.visual-basic-data-mining.net/forum

Nov 21 '05 #2

P: n/a
oh......I will try it..

another problem is that the frm.textbox1.text is in another form...

that means it is not declared yet..

now to declare it from another form..

Thanks..

--
toytoy - forum member
http://www.visual-basic-data-mining.net/forum
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:Os**************@TK2MSFTNGP10.phx.gbl...
Hi,

Try something like this.

In the module

Public function receiveInfo() as string

Dim ascii As Encoding = Encoding.ASCII
Dim networkStream As NetworkStream

Try
networkStream = tcpC.GetStream()
Dim bytes(tcpC.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpC.ReceiveBufferSize))
Dim ret As String = ascii.GetString(bytes)
return ret

Catch
Console.WriteLine("Sorry. This NetWorkStream is not connect to the server.") return "An error has occured"
End Try
End Sub

In the form

Private Sub btnNextActivity_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNextActivity.Click

Dim s As String
Dim dd As New form2
dd.Show()

Connect()
Name = "Apple"
s = "<Fruit Type=" & """" & Name & """" & "></Fruit>"
send(s)
frm.textbox1.text = receiveInfo()
Me.Hide()
End Sub

Ken
----------------------------
"http://www.visual-basic-data-mining.net/forum" <si******@gmail.com> wrote
in message news:ur**************@TK2MSFTNGP12.phx.gbl...
Hi

Does anyone know how to stay connected to the server and at the same time i can pass the string to and from the module to the form.....

What I want:

I put the connection at the module.....

1)I can pass the string from the form to the module...
(Because there is send and receiveInfo method from the server so i put both methods to the module)
2)I receive that string from the module and pass it to the form...
3)The form will show that string to the textbox...

But now step 3 can't work...
It receive nothing from the module..

Any idea how to use correct it..... or i implement wrongly...

Now i can only display the contents at the Start of a new form through the
module as MessageBox when i receive from the server...

But can't display it to the textbox in the form because can't pass the
string from the module to the form...

Thanks
--------------------------------------------------------------------
My Codes:

In the previous form....

Private Sub btnNextActivity_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNextActivity.Click

Dim s As String
Dim dd As New form2
dd.Show()

Connect()
Name = "Apple"
s = "<Fruit Type=" & """" & Name & """" & "></Fruit>"
send(s)
receiveInfo()
Me.Hide()
End Sub
-------------------------------------------------------------------

In the Module....

Public Name As String

Public Sub send(ByVal s As String)

Dim ascii As Encoding = Encoding.ASCII
Dim networkStream As NetworkStream

Try
networkStream = tcpC.GetStream()
Dim sendBytes As Byte()
sendBytes = ascii.GetBytes(s)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Catch ex As Exception
Console.WriteLine("Sorry. This NetWorkStream is not connect to the server.") End Try
End Sub
-------------------------------------------------------------------------- -- --
Public Sub receiveInfo()

Dim ascii As Encoding = Encoding.ASCII
Dim networkStream As NetworkStream

Try
networkStream = tcpC.GetStream()
Dim bytes(tcpC.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpC.ReceiveBufferSize))
Dim ret As String = ascii.GetString(bytes)
MessageBox.Show(ret)

Catch
Console.WriteLine("Sorry. This NetWorkStream is not connect to the server.") End Try
End Sub

--
toytoy - forum member
http://www.visual-basic-data-mining.net/forum

Nov 21 '05 #3

P: n/a
For the answer that you send me can works...

what about my previous question that i post...

how to solve it..

Thanks a lot..

--
toytoy - forum member
http://www.visual-basic-data-mining.net/forum
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:Os**************@TK2MSFTNGP10.phx.gbl...
Hi,

Try something like this.

In the module

Public function receiveInfo() as string

Dim ascii As Encoding = Encoding.ASCII
Dim networkStream As NetworkStream

Try
networkStream = tcpC.GetStream()
Dim bytes(tcpC.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpC.ReceiveBufferSize))
Dim ret As String = ascii.GetString(bytes)
return ret

Catch
Console.WriteLine("Sorry. This NetWorkStream is not connect to the server.") return "An error has occured"
End Try
End Sub

In the form

Private Sub btnNextActivity_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNextActivity.Click

Dim s As String
Dim dd As New form2
dd.Show()

Connect()
Name = "Apple"
s = "<Fruit Type=" & """" & Name & """" & "></Fruit>"
send(s)
frm.textbox1.text = receiveInfo()
Me.Hide()
End Sub

Ken
----------------------------
"http://www.visual-basic-data-mining.net/forum" <si******@gmail.com> wrote
in message news:ur**************@TK2MSFTNGP12.phx.gbl...
Hi

Does anyone know how to stay connected to the server and at the same time i can pass the string to and from the module to the form.....

What I want:

I put the connection at the module.....

1)I can pass the string from the form to the module...
(Because there is send and receiveInfo method from the server so i put both methods to the module)
2)I receive that string from the module and pass it to the form...
3)The form will show that string to the textbox...

But now step 3 can't work...
It receive nothing from the module..

Any idea how to use correct it..... or i implement wrongly...

Now i can only display the contents at the Start of a new form through the
module as MessageBox when i receive from the server...

But can't display it to the textbox in the form because can't pass the
string from the module to the form...

Thanks
--------------------------------------------------------------------
My Codes:

In the previous form....

Private Sub btnNextActivity_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNextActivity.Click

Dim s As String
Dim dd As New form2
dd.Show()

Connect()
Name = "Apple"
s = "<Fruit Type=" & """" & Name & """" & "></Fruit>"
send(s)
receiveInfo()
Me.Hide()
End Sub
-------------------------------------------------------------------

In the Module....

Public Name As String

Public Sub send(ByVal s As String)

Dim ascii As Encoding = Encoding.ASCII
Dim networkStream As NetworkStream

Try
networkStream = tcpC.GetStream()
Dim sendBytes As Byte()
sendBytes = ascii.GetBytes(s)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Catch ex As Exception
Console.WriteLine("Sorry. This NetWorkStream is not connect to the server.") End Try
End Sub
-------------------------------------------------------------------------- -- --
Public Sub receiveInfo()

Dim ascii As Encoding = Encoding.ASCII
Dim networkStream As NetworkStream

Try
networkStream = tcpC.GetStream()
Dim bytes(tcpC.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpC.ReceiveBufferSize))
Dim ret As String = ascii.GetString(bytes)
MessageBox.Show(ret)

Catch
Console.WriteLine("Sorry. This NetWorkStream is not connect to the server.") End Try
End Sub

--
toytoy - forum member
http://www.visual-basic-data-mining.net/forum

Nov 21 '05 #4

P: n/a
That means if that textbox is within the same form, it can display after i
receive it..

But if the textbox is in another form after i receive, it cannot work.

--
toytoy - forum member
http://www.visual-basic-data-mining.net/forum
"http://www.visual-basic-data-mining.net/forum" <si******@gmail.com> wrote
in message news:%2****************@TK2MSFTNGP14.phx.gbl...
For the answer that you send me can works...

what about my previous question that i post...

how to solve it..

Thanks a lot..

--
toytoy - forum member
http://www.visual-basic-data-mining.net/forum
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:Os**************@TK2MSFTNGP10.phx.gbl...
Hi,

Try something like this.

In the module

Public function receiveInfo() as string

Dim ascii As Encoding = Encoding.ASCII
Dim networkStream As NetworkStream

Try
networkStream = tcpC.GetStream()
Dim bytes(tcpC.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpC.ReceiveBufferSize))
Dim ret As String = ascii.GetString(bytes)
return ret

Catch
Console.WriteLine("Sorry. This NetWorkStream is not connect to the server.")
return "An error has occured"
End Try
End Sub

In the form

Private Sub btnNextActivity_Click(ByVal sender As System.Object, ByVal e

As
System.EventArgs) Handles btnNextActivity.Click

Dim s As String
Dim dd As New form2
dd.Show()

Connect()
Name = "Apple"
s = "<Fruit Type=" & """" & Name & """" & "></Fruit>"
send(s)
frm.textbox1.text = receiveInfo()
Me.Hide()
End Sub

Ken
----------------------------
"http://www.visual-basic-data-mining.net/forum" <si******@gmail.com> wrote in message news:ur**************@TK2MSFTNGP12.phx.gbl...
Hi

Does anyone know how to stay connected to the server and at the same time i
can pass the string to and from the module to the form.....

What I want:

I put the connection at the module.....

1)I can pass the string from the form to the module...
(Because there is send and receiveInfo method from the server so i put

both
methods to the module)
2)I receive that string from the module and pass it to the form...
3)The form will show that string to the textbox...

But now step 3 can't work...
It receive nothing from the module..

Any idea how to use correct it..... or i implement wrongly...

Now i can only display the contents at the Start of a new form through

the module as MessageBox when i receive from the server...

But can't display it to the textbox in the form because can't pass the
string from the module to the form...

Thanks
--------------------------------------------------------------------
My Codes:

In the previous form....

Private Sub btnNextActivity_Click(ByVal sender As System.Object, ByVal e

As
System.EventArgs) Handles btnNextActivity.Click

Dim s As String
Dim dd As New form2
dd.Show()

Connect()
Name = "Apple"
s = "<Fruit Type=" & """" & Name & """" & "></Fruit>"
send(s)
receiveInfo()
Me.Hide()
End Sub
-------------------------------------------------------------------

In the Module....

Public Name As String

Public Sub send(ByVal s As String)

Dim ascii As Encoding = Encoding.ASCII
Dim networkStream As NetworkStream

Try
networkStream = tcpC.GetStream()
Dim sendBytes As Byte()
sendBytes = ascii.GetBytes(s)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Catch ex As Exception
Console.WriteLine("Sorry. This NetWorkStream is not connect to the

server.")
End Try
End Sub


--------------------------------------------------------------------------
--
--
Public Sub receiveInfo()

Dim ascii As Encoding = Encoding.ASCII
Dim networkStream As NetworkStream

Try
networkStream = tcpC.GetStream()
Dim bytes(tcpC.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpC.ReceiveBufferSize))
Dim ret As String = ascii.GetString(bytes)
MessageBox.Show(ret)

Catch
Console.WriteLine("Sorry. This NetWorkStream is not connect to the

server.")
End Try
End Sub

--
toytoy - forum member
http://www.visual-basic-data-mining.net/forum


Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.