By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,480 Members | 1,146 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,480 IT Pros & Developers. It's quick & easy.

Form won't play nice with rtb

P: n/a
I have a VB.NET program called "Calendar" that has a menu on the top that
opens up another form (like a pop-up box) on top of "Calendar". The pop-up
box form is called "Memos" which is a stand-alone (doesn't communicate with
first form) database form with 3 drop-down boxes, a "Close" box and a rtb.
I had this working (see "Saving RTB content to SQL Server" in the
microsoft.public.vb.database forum) and then a user started to complain
about application crashes. On investigation I found that I couldn't
recreate the issue reliably but noticed that the problem seemed to occur
when the user typed alot of information into the rtb control. So, I tried
to write error code around the code in my "SaveMessage" procedure, but the
funny thing is that the code doesn't error when it actually tries to save
the data (which I am doing in a referenced object I built), or when it goes
through the code to put the data in the rtb. If I step through the code
(without the error trapping) it makes it all the way to what I would expect
to be the end, and then I hit F8 at the last "Sub End" line thinking the
next thing I will see is the "Memos" form and instead I get an "unhandled
exception of type 'System.NullReferenceException'... Object reference not
set to an instance of an object." error and the line it is stopping on is
"Public Class Calendar" from the "Calendar" form!!! I can still see my
"Memos" form in the fore-ground and that is the form it should have dropped
me to.

I came up with the idea of having thedatabase object return a "1" or "0"
depending on whether the data saved to the database correctly, and that
seems to return the "0" when I put in the long string into the rtb, but even
if I insert code to deal with the error condition, I still get the "Object
reference" error at the end just like before.

All I can think of is that this has something to do with the rtb not dealing
with the data properly and somehow destroying the actual rtb control on the
form. When my code tries to view it or clear it, it is no longer there and
that would explain the message. It would also explain my database object
returning a "0" properly in this instance. I had the field in SQL Server
set to "binary 1000" and expanded that to 2000, but no effect.

I hope that is enough info for you to go on. There are so many little
things here I almost need to send you the code. Look below for code
snippets of how I am performing certain tasks.

I hope you can help me.

Schoo
Here is how I call "Memos" from "Calendar": =================
Private Sub MenuItem4_Click(ByVal....) Handles MenuItem4.Click
Dim memos as memos = New Memos
memos.show()
End Sub
=================
Here is the call to the database object: =================
Dim response as integer = oDBAccess.saveMessage(strCurMonth, strCurYear,
strCurType, rtb1)
=================
Here is the active code in the saveMessage function in the database object:

=================
Try
If GetRecsScalar("select count(*) from monthlymessages where
dtYear = " & dtYear & " and dtMonth = " & dtMonth & " and typeid=(select id
from type where type = '" & type & "')") > 0 Then
strSql = "update monthlymessages set message = @mess where
dtYear = " & dtYear & " and dtMonth = " & dtMonth & " and typeid=(select id
from type where type = '" & type & "')"
Else
strSql = "insert into monthlymessages select " & dtYear & ",
" & dtMonth & ", (select id from type where type = '" & type & "'), @mess"
End If

Dim rtf(999) As Byte
Dim s As New MemoryStream(rtf)
rtb.SaveFile(s, RichTextBoxStreamType.RichText)
Dim p(1) As SqlParameter
p(0) = New SqlParameter("@mess", SqlDbType.Binary, 1000)
p(0).Value = rtf

Microsoft.ApplicationBlocks.Data.SqlHelper.Execute NonQuery(oSettings.dbConn,
CommandType.Text, strSql, p)
Catch
intResponse = 0
End Try
Return intResponse
=================

Nov 21 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
Hi

From the code it seems that all is OK, can you provide a simple reproduce
sample.
You may try to SaveFile to the disk directory and use the same steps to see
if that will reproduce the problem which will help us to isolate the
problem.

Also you may try to increase of the count of the buffer.
e.g. the database field is 2000,
change the code below.
rrf to 1999
p(0) to 2000.

Dim rtf(999) As Byte
Dim s As New MemoryStream(rtf)
rtb.SaveFile(s, RichTextBoxStreamType.RichText)
Dim p(1) As SqlParameter
p(0) = New SqlParameter("@mess", SqlDbType.Binary, 1000)
p(0).Value = rtf

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #2

P: n/a
Hi

From the code it seems that all is OK, can you provide a simple reproduce
sample.
You may try to SaveFile to the disk directory and use the same steps to see
if that will reproduce the problem which will help us to isolate the
problem.

Also you may try to increase of the count of the buffer.
e.g. the database field is 2000,
change the code below.
rrf to 1999
p(0) to 2000.

Dim rtf(999) As Byte
Dim s As New MemoryStream(rtf)
rtb.SaveFile(s, RichTextBoxStreamType.RichText)
Dim p(1) As SqlParameter
p(0) = New SqlParameter("@mess", SqlDbType.Binary, 1000)
p(0).Value = rtf

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #3

P: n/a
[I have sent the referenced file to you directly via your email address.
Here is the message to go along with it:]

Peter,

Thank you for trying to help me with this. I made some changes to my
saveMessage and getMessage procedures (adding 1000 to the values there), and
while it seems to let me get a little further, it still crashes the
application just like before. I recognize that I know very little about
binary objects and rtb/rtf concepts. Is there a good explaination (web
site) that I can review to help me understand this better on msdn or
something? ... preferably something less technical that I can understand
quickly.

Anyway, I am going to forward the whole project for you to review, please
see the attached zip file. Here is an explaination of the attached file:

1) There is a file in the zip file called "OnCall.bak". This is a backup
of the SQL Database.
2) The form that accesses the "MonthlyMessages" table is called "Memos.vb".
Set that as the first form to run for your testing.
3) The "OnCallDB.DBAccess.vb" file contains the database access code used
by "Memos.vb"
4) Before running, modify the "OnCallDB.DBAccess.vb" file with your
database access settings. I am using SQL Server2000

The whole project works except for this feature and users are Beta testing
it now. As soon as this works we release company-wide! No pressure or
anything. :) I am leaving for the weekend and may not get back to you
until Monday. I look forward to hearing about what you are able to find and
tell me. Good luck.

Schoo :)

""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:mq**************@cpmsftngxa10.phx.gbl...
Hi

From the code it seems that all is OK, can you provide a simple reproduce
sample.
You may try to SaveFile to the disk directory and use the same steps to see if that will reproduce the problem which will help us to isolate the
problem.

Also you may try to increase of the count of the buffer.
e.g. the database field is 2000,
change the code below.
rrf to 1999
p(0) to 2000.

Dim rtf(999) As Byte
Dim s As New MemoryStream(rtf)
rtb.SaveFile(s, RichTextBoxStreamType.RichText)
Dim p(1) As SqlParameter
p(0) = New SqlParameter("@mess", SqlDbType.Binary, 1000)
p(0).Value = rtf

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #4

P: n/a
Peter,

I tried sending this to you at v-******@online.microsoft.com but it came
back. Please confirm your email or please provide another way I can get
this to you.

Schoo

""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:mq**************@cpmsftngxa10.phx.gbl...
Hi

From the code it seems that all is OK, can you provide a simple reproduce
sample.
You may try to SaveFile to the disk directory and use the same steps to see if that will reproduce the problem which will help us to isolate the
problem.

Also you may try to increase of the count of the buffer.
e.g. the database field is 2000,
change the code below.
rrf to 1999
p(0) to 2000.

Dim rtf(999) As Byte
Dim s As New MemoryStream(rtf)
rtb.SaveFile(s, RichTextBoxStreamType.RichText)
Dim p(1) As SqlParameter
p(0) = New SqlParameter("@mess", SqlDbType.Binary, 1000)
p(0).Value = rtf

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #5

P: n/a
Hi Scott,

You can reach Peter by email at the address you tried, just remove "online"
from it.

Brett Keown
Microsoft Support
br*****@online.microsoft.com

This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #6

P: n/a
Hi Scott,

As Brett said, you may reach me by removing the "online" from my email
address.
I am sorry for the inconvenience and I will be appreciate if you can resend
the email.
Thanks!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #7

P: n/a
OK, I have just resent the file to v-******@microsoft.com

BTW: if you know of any good articles explaining rtb controls or binary
objects, let me know.

Schoo
""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:bK*************@cpmsftngxa10.phx.gbl...
Hi Scott,

As Brett said, you may reach me by removing the "online" from my email
address.
I am sorry for the inconvenience and I will be appreciate if you can resend the email.
Thanks!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #8

P: n/a
Hi Scott,

I have received the attachment.
But there is no OnCallDB.DBAccess.vb in the zip file.
Can you resend the whole package to me?

Also I think you may also try to stored the whole richtextbox.rtf property
to a string and then add the string to the sqlserver.
You may use the System.Text.UnicodeEncoding class's GetBytes method to
encode that into a byte array.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #9

P: n/a
Hi Scott,

It is strange that I have tried your code but I can not reproduce the
problem, the project runs well on my side and it will save the data correct
without any exception.
The only one I think you may try to add it that since you have define the
size of the binary field in the sql server, we would better to detect the
length of the rtf file so that there will have no error.

I think you may try to get the property below.
rtb.rtf.length, we need to make sure it is less than the binary field, if
large we need to pop up a messagebox tell the enduser the rtb has too many
text.

So far I think we would better try to the code on another machine to see if
the problem persist.

Saving Files with the Windows Forms RichTextBox Control
http://msdn.microsoft.com/library/de...us/vbcon/html/
vbtsksavingfilewithwindowsformsrichtextboxcontrol. asp
Create a Graphical Editor Using RichTextBox and GDI+
http://msdn.microsoft.com/msdnmag/is...dvancedBasics/

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #10

P: n/a
Peter,

Thank you for your help on this. I have been reviewing the links that you
sent to me and wanted to update you on the progress.

The goal of this feature was to give the users a database-bound 'memo field'
box that they could type in as much as they wanted. Working with binary
objects is something I have not done before and there seems to be a lack of
good information on the internet on this topic. We need to release the
project 12/1/04 and so I am preparing for release. After discussing this at
length with my supervisors, we decided that the program will be released in
its 'crippled' form. Users will be warned of the problem and told that
while we can't prove it, we suspect the issue is with the length of the
contents. Several users in particular will not be pleased and we are
bracing for the negative calls. The decision to do this was made because of
the large number of backed-up project work I need to get done. I simply
have used up all my time trying to solve this and management is demanding me
to move-on.

I don't have time to write letters to Microsoft, but if you ever get a
chance, you may want to comment to them that this is an area they might want
to consider simplifying in future versions of .NET. I estimated to
management that I have spent 80+ hours on this single issue and to
completely solve it would be hard to determine but I requested another 40 to
start off with. This, of course, was not reasonable. We have released 10
projects in the past 2 years and this is our first project where we couldn't
fully fill the project requirements, so I suppose I can't complain.

Thank you for your help again. I will keep my eyes open on technical sites
and publications for articles on rtb topics.

Sincerely,

Schoo
""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:bK*************@cpmsftngxa10.phx.gbl...
Hi Scott,

As Brett said, you may reach me by removing the "online" from my email
address.
I am sorry for the inconvenience and I will be appreciate if you can resend the email.
Thanks!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #11

P: n/a
Hi

Thank you for your input.
However, because we can not reproduce the problem on my side, it is hard to
guess what had happened.
Have you tried my suggestion that test the rtftext's length before insert
into database?

If you have any good suggestion about our product, I think you may try to
visit the following Microsoft Product Feedback Web site:
"http://register.microsoft.com/mswish/suggestion.asp" and then complete and
submit the form.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #12

P: n/a
The program was released 12/1/04 and the users are not complaining. I think
the problem was that they had some tab stops in the rtb which seemed to mess
things up. It appears to work good now and I am still monitoring the app.
Thank you for your help. I learned alot about BLOB objects and will
continue to research that feature. Maybe in the future we can add some
formating features for the users in their rtb objects.

Thanks again and have a great holiday!

Schoo

""Peter Huang" [MSFT]" <v-******@online.microsoft.com> wrote in message
news:ym*************@cpmsftngxa10.phx.gbl...
Hi

Thank you for your input.
However, because we can not reproduce the problem on my side, it is hard to guess what had happened.
Have you tried my suggestion that test the rtftext's length before insert
into database?

If you have any good suggestion about our product, I think you may try to
visit the following Microsoft Product Feedback Web site:
"http://register.microsoft.com/mswish/suggestion.asp" and then complete and submit the form.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #13

P: n/a
Hi

Thank you Scott!
Merry Christmas!

Best regards,

Perter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.