|
-
Jul 16th, 2004, 03:30 AM
#1
Thread Starter
Fanatic Member
Sending a variable Byref to a class
I want to be able to send a Richtextbox to one of my classes byref so that updates to the class rtb will update the actual rtb
Right now I have
VB Code:
Public Class InfLog
Private Buffer1, Buffer2 As String
Private Interval As Integer = 500
Private rtxtbox As RichTextBox
Public Sub New(ByVal Buffer1 As String, ByVal Buffer2 As String, ByRef rtb As RichTextBox)
Me.Buffer1 = Buffer1
Me.Buffer2 = Buffer2
Me.rtxtbox = rtb
End Sub
However when I make changes to rtxtBox nothing happens. Can someone please point me in the right direction?
If wishes were fishes we'd all cast nets.
-
Jul 16th, 2004, 04:56 AM
#2
Hyperactive Member
Dear Graff, I'm quite a newbie, so it's possible I fail completely, but I think you have to act on rtb directly.
Your ' Me.rtxtbox ' is private and I think it's not possible to refer it out of your class, so probably you need to complete your loop in this way, for example
rtb.text=Me.rtxtbox.text
At this time, I think, you will see the changes.
Problem is: you have to pass your variable from the constructor procedure, to that one will make the changes.
I have no good practice, anyway. Normally I pass control byref, but directly to the class public method I call and not in the constructor, where, in general, I only pass initializing parameter.
Below is an example of a class I use to redim form on my two screens.
VB Code:
Sub New()
End Sub
Public Function FnzRapportoTraSchermoEForm(ByRef F As Form) As Single
Dim orizz As Integer
Dim vert As Integer
Me.SubRilevaRisoluzione(F, orizz, vert)
Dim R As Single = CSng(orizz / F.Width)
Return R
End Function
Private Sub SubRilevaRisoluzione(ByRef IlForm As Form, ByRef Orizzontale As Integer, ByRef Verticale As Integer)
Dim desktopSize As Size
desktopSize = System.Windows.Forms.SystemInformation.PrimaryMonitorSize
'Dim AreaSchermo As System.Drawing.Rectangle = Screen.GetWorkingArea(IlForm)
Dim Punto As System.Drawing.Point
Punto.X = IlForm.Left + (IlForm.Width / 2)
Punto.Y = IlForm.Top + (IlForm.Height / 2)
Dim AreaSchermo As System.Drawing.Rectangle = Screen.GetWorkingArea(Punto)
Verticale = AreaSchermo.Height
Orizzontale = AreaSchermo.Width
'MessageBox.Show(Pluto.ToString & " " & paperino.ToString)
End Sub
Public Sub SubVariaSecondoRapporto(ByRef F As Form, ByVal Rapporto As Single)
Dim R As Single = CSng(Rapporto)
f.Scale(R)
Me.CambiaIFont(f, R)
'F.Refresh()
End Sub
Private Sub CambiaIFont(ByRef F As Form, ByVal R As Single)
Dim Ct As Control
Dim T As String
For Each Ct In F.Controls
If Not Ct.Controls Is Nothing Then
'Se qui, contiene controlli di secondo livello (figli)
Dim CtF As Control 'Devo ciclare sui suoi controlli figli
For Each CtF In Ct.Controls
Me.RidimensionaFontDelControllo(CtF, R)
Next
End If
' Qui si maneggiano i controlli di primo livello
Me.RidimensionaFontDelControllo(Ct, R)
Next
End Sub
Private Sub RidimensionaFontDelControllo(ByRef Ct As Control, ByVal R As Single)
Dim FSize As Single = Ct.Font.Size
Dim FStile As FontStyle = Ct.Font.Style
Dim FNome As String = Ct.Font.Name
Dim NuovoSize As Single = FSize * R
Dim NFont As New Font(FNome, NuovoSize, FStile)
Ct.Font = NFont
End Sub
End Class
Good job!
Live long and prosper (Mr. Spock)
-
Jul 16th, 2004, 05:38 AM
#3
Sleep mode
Even ByVal should result the same (in case you've done it right).
-
Jul 16th, 2004, 05:46 AM
#4
Hyperactive Member
Pirate is right, because we are speaking about a RichTextBox that is an object 'reference type' and not 'value type'.
We have to remember, that If we use a variable like a Double, or a String, we have to specify which kind of 'link' we need because it makes a difference.
Good morning to both, dear friends
Live long and prosper (Mr. Spock)
-
Jul 16th, 2004, 05:53 AM
#5
Sleep mode
RichTextBox is a Class , dude.
-
Jul 16th, 2004, 07:01 AM
#6
Hyperactive Member
What is the point?
You are underlying that Rtb is a class....perhaps because I said it is an object? If so, that's because when you work with something, it is an object (a class instanced....or instanciated...damned my english....help me! ). A form is a class, but when you try to refer it without an instance (an object) you have an error. You are perfectly right saying richtextbox is a class, but 'YourRtb', placed on your form, is an object derived from its class. It's possible I'm wrong, obviously, so I don't want to say 'that's true!'. But only 'I THINK IT'S TRUE'. If not, I will note my mistake and will become a little more experienced learning by that!
Anyway we are discussing about details that are not really the 'core' of the thread, also if interesting'.
Live long and prosper (Mr. Spock)
-
Jul 16th, 2004, 07:18 AM
#7
Hyperactive Member
Or...perhaps you wanted to say that class is reference type? In this case I agree 100%: Classes are reference types! 
Excuse me...I'm not very sure of my english and sometimes I miss also what should be obvious!
Live long and prosper (Mr. Spock)
-
Jul 16th, 2004, 07:45 AM
#8
Member
-
Jul 16th, 2004, 08:11 AM
#9
VB Code:
Public Class InfLog
Private Buffer1, Buffer2 As String
Private Interval As Integer = 500
Private rtxtbox As RichTextBox
Public Sub New(ByVal Buffer1 As String, ByVal Buffer2 As String, ByRef rtb As RichTextBox)
Me.Buffer1 = Buffer1
Me.Buffer2 = Buffer2
'you problem lies here:
'rtb is a reference to the rtb....
'when you say 'Me.rtxtbox = rtb' vb thinks you want to
'create a copy of the object rtb is pointing to and store it in
'Me.rtxtbox
Me.rtxtbox = rtb
End Sub
at this very moment, i cant think of away to copy a reference (pointer). Prolly because of lack of sleep....
Tips:
- Google is your friend! Search before posting!
- Name your thread appropriately... "I Need Help" doesn't cut it!
- Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
- Allways Include the Name and Line of the Exception (if one is occuring!)
- If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)
If you think I was helpful, rate my post  IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous
-
Jul 16th, 2004, 08:41 AM
#10
Sleep mode
Originally posted by alextyx
What is the point?
You are underlying that Rtb is a class....perhaps because I said it is an object?
I didn't mean to make any confusion but 'Object' is general word for class instances(RTB instance ...) and base datatypes(Int,String,Double..etc) which could be confusing also when talking about value types and reference types .Umm , there's much has to be said though , but I'm just a little lazy ...
-
Jul 16th, 2004, 09:03 AM
#11
Hyperactive Member
-
Jul 16th, 2004, 11:33 AM
#12
Thread Starter
Fanatic Member
Ok so the only solution we really know of is to take it out of the initialization and put it in my methods that will use it when called in the main program?
If wishes were fishes we'd all cast nets.
-
Jul 16th, 2004, 12:25 PM
#13
I think we've only been looking at the apples and calling the whole fuit salad bad...
How is this class being dimmed, instanciated, and used?
Personaly, I cannot see anything wrong with the constructor. I'm wondering if maybe it's wrong at the other end of things.
TG
-
Jul 16th, 2004, 01:07 PM
#14
Thread Starter
Fanatic Member
In the global area of the form main:
Dim iLog as Inflog
In Form_Load event:
iLog = New InfLog("B1.UBL","B2.UBL", rtbChat)
Then in the btnEnable_Click event:
tMain.enable = true 'this is a timer
tMain_Tick event:
iLog.refresh()
at which point the refresh method will parse a log, color code it determined by certain delimiters in the log and put it on the rtbChat control
I was hoping to avoid passing the rtbChat down 3 methods withing the InfLog class by just refrencing it in as a part of the class so instead of declaring it at the constructor I have to go
iLog.refresh(rtbChat)
refresh called the process method
Process(rtbChat)
then process calls the parseline method
ParseLine(rtbChat)
where finally alll the magic is done.
If wishes were fishes we'd all cast nets.
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
|