473,411 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

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

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
4 2706
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
2
by: Chad | last post by:
I'm in an intro to VB.net class. I'm haveing trouble with this assignment, if anyone could help me please let me know. thanks! Coding Assignment 7-Chapter 8 OOP-CSCI-171 Intro to VB.NET ...
7
by: | last post by:
Hello, I would like to do the following from a asp.net button click: <form method="POST" action="https://www.1234.com/trans_center/gateway/direct.cgi"> <input type="hidden" name="Merchant"...
5
by: Peter Proost | last post by:
Hi I got this piece of c# code which runs ok but now I translated it to vb.net (see bottom of post for both pieces) and it keeps erroring out at pi.SetValue(testForm, newValue, x) with this error:...
1
by: Marek Murin | last post by:
Hi all, I have created vb.net user control that has to be used by vb6 form. Everything goes well with putting the vb.net user control on the VB6 form until I want to receive any event from my...
0
by: shamirza | last post by:
· When was .NET announced? Bill Gates delivered a keynote at Forum 2000, held June 22, 2000, outlining the .NET 'vision'. The July 2000 PDC had a number of sessions on .NET technology, and...
0
by: shamirza | last post by:
· What is view state and use of it? The current property settings of an ASP.NET page and those of any ASP.NET server controls contained within the page. ASP.NET can detect when a form is requested...
3
by: al-s | last post by:
I have a working VB.NET 2005 (.NET2.0) solution that works. When I translate the code modules, form modules to C# I get all sorts of build errors, much of which are related to scoping of methods....
10
by: Jan Vinten | last post by:
Hi all, I got into some trouble trying to bind to a specific IP address. Code: Private mobjClient As TcpClient mobjClient = New TcpClient(IPAddress.Parse("10.16.104.87").ToString, 8892)
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.