Byval when it should be giving me Reference??
Byval when it should be giving me Reference??
Byval when it should be giving me Reference??
Byval when it should be giving me Reference??
Byval when it should be giving me Reference??
Byval when it should be giving me Reference?? Byval when it should be giving me Reference?? Byval when it should be giving me Reference?? Byval when it should be giving me Reference?? Byval when it should be giving me Reference?? Byval when it should be giving me Reference?? Byval when it should be giving me Reference?? Byval when it should be giving me Reference??
Byval when it should be giving me Reference?? Byval when it should be giving me Reference??
Byval when it should be giving me Reference??
Go Back  Xtreme Visual Basic Talk > > > Byval when it should be giving me Reference??


Reply
 
Thread Tools Display Modes
  #1  
Old 02-20-2009, 11:47 AM
piggybank1974's Avatar
piggybank1974 piggybank1974 is offline
Ultimate Contributor
 
Join Date: Mar 2002
Location: weston-super-mare(UK)
Posts: 1,795
Question Byval when it should be giving me Reference??


I have this weird problem as I said in the title I think the part of the code that is not working is doing its job by value so when it goes out of scope (end of the method) its not available (just disappears).

The PrivateUsers (I’ve uploaded the file) Namespace (Users, PrivateUser) are only used in one form the PrivateChat form and are accessed from the below code.

Code:
Dim mPrivateUsers As PrivateUsers.Users Private ReadOnly Property PrivateUsers() As PrivateUsers.Users Get If mPrivateUsers Is Nothing Then mPrivateUsers = New PrivateUsers.Users End If Return mPrivateUsers End Get End Property Public ReadOnly Property Users() As PrivateUsers.Users Get Return PrivateUsers End Get End Property

The actual form is defined/displayed only in two parts:

Below is when you want to talk to a user.

Code:
If e.ClickedItem.Text.Contains("Private Chat") = True Then Dim mWindowIndex As Int32 = FindFreePrivateChat() mFrmPrivateChat(mWindowIndex) = New PrivateChat(Me.TreeList1, mWindowIndex, mChild, UserID, UserName) mClientServerSocket.Send(New Message10("S$P^M%", -1, UserID, UserName, mWindowIndex.ToString, mChild.UserID & "~" & mChild.UserName)) mFrmPrivateChat(mWindowIndex).Show() mFrmPrivateChat(mWindowIndex).Users.Add(-1, IIf(mChild.Parent.GroupIndex = 0, True, False), mChild.UserID, mChild.UserName, mChild.DisplayText) End If

Or here when a user wants to talk to you.

Code:
Case "I$P^M%" ' SentMessage.Item(0) = mWindowIndex Dim mWindowIndex As Int32 = Int32.Parse(SentMessage.Item(0)) ' '' Extra(0) = UserID ' '' Extra(1) = UserName Dim Extra() As String = SentMessage.Extra.Split("~") Dim mArrayPos As Int32 = FindFreePrivateChat() PrivateShowDialog(mArrayPos) Dim mChild As TreeListChildren = Me.TreeList1.FindChild(Extra(1)) If mChild IsNot Nothing Then mFrmPrivateChat(mArrayPos).Users.Add(mWindowIndex, IIf(mChild.Parent.GroupIndex = 0, True, False), Int32.Parse(SentMessage.UserID), SentMessage.UserName, mChild.DisplayText) End If mClientServerSocket.Send(New Message10("M$P^I%", -1, UserID, UserName, mArrayPos, mWindowIndex & "~" & SentMessage.UserID & "~" & SentMessage.UserName))

The problem is with the above part of the code from "I$P^M%" it adds the user fine to the mFrmPrivateChat window, I checked this by debugging it but when it goes out of scope(the form is displyed by the way) and I type some text there are no users in the private chat window they have disappeared.

Below is what I use to send the message object to the server, at this point Users.Count should be 1, but its zero.

Code:
Dim mMessage10 As New Message10("P$P^M%", -1, UserID, UserName, String.Empty, mWindowIndex & "~" & Me.RTBMessage.Font.Name & "~" & Int32.Parse(Me.RTBMessage.Font.SizeInPoints).ToString & "~" & mHTML) For A As Int32 = 0 To Users.Count - 1 Dim mPrivateUser As PrivateUsers.PrivateUser = Users.Item(A) If mPrivateUser IsNot Nothing Then If Not mPrivateUser.WindowIndex = -1 Then mMessage10.Add(mPrivateUser.WindowIndex & "~" & mPrivateUser.UserID & "~" & mPrivateUser.UserName) End If End If Next A mClientServerSocket.Send(mMessage10)

As I said I’m assuming its doing it by value and not by reference although I just cannot see how.
Attached Files
File Type: vb PrivateUsers.vb (3.5 KB, 0 views)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Byval when it should be giving me Reference??
Byval when it should be giving me Reference??
Byval when it should be giving me Reference?? Byval when it should be giving me Reference??
Byval when it should be giving me Reference??
Byval when it should be giving me Reference??
Byval when it should be giving me Reference?? Byval when it should be giving me Reference?? Byval when it should be giving me Reference?? Byval when it should be giving me Reference?? Byval when it should be giving me Reference?? Byval when it should be giving me Reference?? Byval when it should be giving me Reference??
Byval when it should be giving me Reference??
Byval when it should be giving me Reference??
 
Byval when it should be giving me Reference??
Byval when it should be giving me Reference??
 
-->