开发者

Adding text to RichTextBox from a module

开发者 https://www.devze.com 2022-12-13 17:57 出处:网络
In an attempt to clean up my code, I have tried to put all my functions and subroutines in a module. One of these subroutines开发者_JAVA百科 populated a grid of RichTextBoxes with data from a MS Acces

In an attempt to clean up my code, I have tried to put all my functions and subroutines in a module. One of these subroutines开发者_JAVA百科 populated a grid of RichTextBoxes with data from a MS Access database. It worked when the subroutine was in the form that it was being used on, but not in my Module. Is there any specific reason for this? I noticed while trying to use a RichTextBox in the code it said I needed to define it, so I went ahead and added this to the top of my Module:

Dim mon1 As New RichTextBox
Dim mon2 As New RichTextBox
Dim mon3 As New RichTextBox
Dim mon4 As New RichTextBox
Dim mon5 As New RichTextBox

It didn't actually put any text into the RichTextBoxes on my form and the subroutine did not throw back an error. I tried changing it from Dim to Public and it does the same thing.

Can anyone shed some light on this? Thanks.


You simply need to reference it, in your module, as Form1.RichTextBox1 (obviously replace those placeholders with the actual name properties of your form and richtextbox controls).

This is assuming you are referring to VB.NET.

Declaring a new RichTextBox control in your module is not going help you reference those you have already placed on your form with the Visual Studio editor or declared in the code of your form.

Is there any specific reason for this?

The reason the subroutine doesn't work in your module is simply that the RichTextBox variables are not visible in that scope.

0

精彩评论

暂无评论...
验证码 换一张
取 消