473,657 Members | 2,492 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Updating a textbox from another class

Art
Hi,

I have a main form for my project. It uses a routine in another class to do
work on a file -- line by line. I'd like to have a text box on my form
display the lines, say every 5,000 -- so I can tell the progress. From what
LITTLE I know it looks like I'd have to pass the form to the class so that
the class can refer back to the form and update the textbox. It seems to me
that there must be a better way to handle this. Can anyone tell me the right
way to do this?

Art
Nov 21 '05 #1
4 3536
Art,
Besides passing the entire form object to the class, you could just
pass the TextBox control to the class. Another way you can do it is by
using a delegate function. Here is a quick example:

Public Class Updater

Delegate Sub MyCallbackRouti ne(ByVal Buffer As String)

Public Sub MyRoutine(Optio nal ByVal Callback As
MyCallbackRouti ne = Nothing)

If Not (Callback Is Nothing) Then
Callback("This message gets sent to the delegate
function.")
End If

End Sub

End Class

Now on your form that calls the class, you would create a function that
follows the same parameter syntax of the delegate:

Private Sub UpdateTextBox(B yVal Buffer As String)

TextBox1.Text = Buffer

End Sub

And in the event/function that calls the method in your class, you
would do this:

Private Sub btnStart_Click( ByVal sender As System.Object, ByVal e
As System.EventArg s) Handles btnStart.Click

' Declare and Instantiate the class object.
Dim oUpdate As New Updater

' Declare and Instantiate the delegate.
Dim oCallback As New Updater.MyCallb ackRoutine(Addr essOf
UpdateTextBox)

' Call the method within the class and pass the delegate
object.
oUpdate.MyRouti ne(oCallback)

End Sub

If you step through the code, you will see that the "oUpdate.MyRout ine"
function will call the "UpdateText Box" method because you are passing
in the delegate object that contains the address of that function.

I hope this helps (and I hope I explained it correctly).
Regards,
David R. Jenkins

Nov 21 '05 #2
Use an event to alert the form of the status, that separates the processing
from the class instance

'For example, in your form:

Dim WithEvents m_prc As ProcessData = New ProcessData
Private Sub m_prc_Status(By Val counter As Integer) Handles m_prc.Status

TextBox1.Text = counter.ToStrin g

End Sub

Private Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.Click

m_prc.Execute()

End Sub

' In the class definition:

Public Class ProcessData

Public Event Status(ByVal counter As Integer)

Public Sub Execute()

For i As Integer = 0 To 5000000

If i Mod 5000 = 0 Then

RaiseEvent Status(i)

End If

Next

End Sub

End Class

"Art" <Ar*@discussion s.microsoft.com > wrote in message
news:2B******** *************** ***********@mic rosoft.com...
Hi,

I have a main form for my project. It uses a routine in another class to
do
work on a file -- line by line. I'd like to have a text box on my form
display the lines, say every 5,000 -- so I can tell the progress. From
what
LITTLE I know it looks like I'd have to pass the form to the class so that
the class can refer back to the form and update the textbox. It seems to
me
that there must be a better way to handle this. Can anyone tell me the
right
way to do this?

Art

Nov 21 '05 #3
Art
David,

Thank you very much. I've had no experience using Delegates so this should
be interesting!

Art
Nov 21 '05 #4
Art
Jim,

Thanks for the help. I'm still kind of new at this and even though I have
generated events before, I'm not yet at home with all of this.

Art
Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
3113
by: Tim | last post by:
Hi A while ago I got some help in writing a mock console. The idea was to write a VB app that contained a textbox, then run a process from within the app and redirect the stdout to the textbox. My problem was that textboxes have maximum length limits, so I had to write a function to erase some of the text when it started getting full. That appears to work, but I am experiencing odd behaviour when the textbox text gets long. When it got to...
5
2853
by: CCLeasing | last post by:
Hello, I have searched google but can not find a straight forward answer to my problem. Hopefuly someone will be kind enough to offer their expertise. Please forgive if this seems a bit convoluted but this is probabally a reflection of my not clear understanding of the mechanics behind what i'm trying to achieve. Please bear with it I really could do with your help. I have a simple windows form. There are two controls on the form that I...
4
3213
by: Peted | last post by:
Hello i have a textbox on a form1. I want to pass the name of that textbox as a paramter to another class (not a form class) and once gotten this paramter i want to update the textbox on form1 and display text data as data is retrieved via this other class. can anyone point or provide some sample code of how this would be done
2
3309
by: =?Utf-8?B?VmFuZXNzYQ==?= | last post by:
Hi All! I am with a situation where I am not getting the right updating to the form's fields. The situation is the following one: I have one combobox and one textbox. I am using the CurrentChanged event of the BindingSource of the combobox to update the textbox. When selecting an item in the combobox or when selecting a row in the grid, it is updating the textbox correctly. The problem is when I apply a filter in the grid, and then...
0
8316
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8833
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8737
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8509
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8610
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7345
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6174
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2735
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.