|
-
Jan 16th, 2005, 01:18 PM
#1
Thread Starter
Hyperactive Member
Passing a RTB as a Paramater
I have a Function in a module called Functions
The function is:
VB Code:
Public Sub AddChat(ByRef RichTextBox As System.Windows.Forms.RichTextBox, ByVal ParamArray Text() As Object) With RichTextBox
.SelectionStart = 99999999
.SelectionLength = 0
.SelectionColor = Color.White
.SelectedText = "[" & TimeOfDay & "] "
.SelectionLength = 0
End With
For I As Byte = LBound(Text) To UBound(Text) Step 2
With RichTextBox
.SelectionStart = 99999999
.SelectionLength = 0
.SelectionColor = Text(I)
.SelectedText = Text(I + 1) & Microsoft.VisualBasic.Left(vbCrLf, -2 * CLng((I + 1) = UBound(Text)))
.SelectionStart = 99999999
End With
Next
End Function
When i try and use this procedure, i can't reference my Rich Text Box
This is where i call it:
VB Code:
Public Function Connect(ByVal server As String, ByVal port As Integer) As Boolean
Dim hostEntry As IPHostEntry = Nothing
hostEntry = Dns.Resolve(server)
Dim address As IPAddress
For Each address In hostEntry.AddressList
Dim endPoint As New IPEndPoint(address, port)
Dim tempSocket As New Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
Try
tempSocket.Connect(endPoint)
Catch Err As SocketException
AddChat(rtbChat, Color.Red, "Error #: " & Err.ErrorCode & ", " & Err.Message)
End Try
If tempSocket.Connected Then
Socket = tempSocket
MsgBox("Connected")
Exit For
End If
Next address
Return True
End Function
RichTextBox is underlined in blue, with the error "Name 'rtbChat' is not declared.
Why do i get this? Any help would be GREATLY apreciated
P.S. Are my functions ok?
Last edited by BaDDBLooD; Jan 16th, 2005 at 04:09 PM.
-
Jan 16th, 2005, 02:18 PM
#2
Re: Passing a RTB as a Paramater
try passing the richtextbox ' ByRef ' not ByVal , eg:
VB Code:
Public Function AddChat([COLOR=Red]ByRef[/COLOR] RichTextBox As System.Windows.Forms.RichTextBox, ByVal ParamArray Text() As Object) As Object
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Jan 16th, 2005, 02:20 PM
#3
Thread Starter
Hyperactive Member
Re: Passing a RTB as a Paramater
yeah, i already tried that. STill nothing
-
Jan 16th, 2005, 03:27 PM
#4
Thread Starter
Hyperactive Member
Re: Passing a RTB as a Paramater
The function works if you use it in the Class frmMain
But i can't seem to Reference the RTB of frmMain when calling it in a different class.
-
Jan 16th, 2005, 05:12 PM
#5
Re: Passing a RTB as a Paramater
you need to pass a reference to your main form ( the form with the Richtextbox ) to your other class when creating it , eg:
VB Code:
'/// The Class
Public Class Class1
Private frm1 As Form1
Public Sub New(ByVal frm As Form)
frm1 = DirectCast(frm, Form1)
End Sub
Public Sub test(ByVal s As String)
'/// put the string ' s ' in to Form1's Richtextbox
frm1.RichTextBox1.AppendText(s)
End Sub
End Class
to use ( As a Test in this case ) ...
VB Code:
'/// the Form that holds the richtextbox
Private cls As Class1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
cls = New Class1(Me) '/// Me being this form
cls.test("some text")
End Sub
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Jan 16th, 2005, 05:30 PM
#6
Thread Starter
Hyperactive Member
Re: Passing a RTB as a Paramater
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|