Showing posts with label instance. Show all posts
Showing posts with label instance. Show all posts

Saturday, March 31, 2012

Subracting days from datetime?

I thought I could subract days from a DateTime instance by passing a negative number into the AddDays method. That doesn't seem to work however. Do I have the syntax right below
(its in c#)
DateTime maxDate = DateTime.Now;
maxDate.AddDays(-1);
// results in no days subtracted, still shows current day. arrrgh.
Does this work?

DateTime maxDate = DateTime.Now;

maxDate.Subtract( new TimeSpan( 24, 0, 0) );
Try: maxDate = maxDate.AddDays(-1);

Thursday, March 22, 2012

Supress error/warning of winapi in class?

I have this error:
Warning 1 Access of shared member, constant member, enum member or nested
type through an instance; qualifying expression will not be evaluated...
This because i have a call in a win32 dll:
Public Declare Ansi Function TheCall Lib "MyDll.DLL" Alias "TheCall" (ByVal
szKey As String) As Int32
Option Explict or Strict don't do anything here.
I'm looking for a solution hopefully placed in the class itself if possible.
The call is executed through the dimensioned class var.
'you are referencing a static method from an instance rather than its class.
use ClassName.MethodName (class referenece), not myObj.MethodName (instance
reference)
-- bruce (sqlwork.com)
"Edwin Knoppert" <news@.hellobasic.com> wrote in message
news:439eef25$0$2339$ba620dc5@.text.nova.planet.nl...
>I have this error:
> Warning 1 Access of shared member, constant member, enum member or nested
> type through an instance; qualifying expression will not be evaluated...
> This because i have a call in a win32 dll:
> Public Declare Ansi Function TheCall Lib "MyDll.DLL" Alias "TheCall"
> (ByVal szKey As String) As Int32
> Option Explict or Strict don't do anything here.
> I'm looking for a solution hopefully placed in the class itself if
> possible.
> The call is executed through the dimensioned class var.
> '
>
Hey, thanks, thought the declares where not public, brain-dead of course.
It says: PUBLIC :)
To bad i couldn't reuse my WITH statement with these calls.
I swapped it for the dimmed object but MS does not like that :)
Thanks,
"Bruce Barker" <brubar_nospamplease_@.safeco.com> schreef in bericht
news:eMrI3rAAGHA.1268@.TK2MSFTNGP11.phx.gbl...
> you are referencing a static method from an instance rather than its
> class. use ClassName.MethodName (class referenece), not myObj.MethodName
> (instance reference)
> -- bruce (sqlwork.com)
>
> "Edwin Knoppert" <news@.hellobasic.com> wrote in message
> news:439eef25$0$2339$ba620dc5@.text.nova.planet.nl...
>

Tuesday, March 13, 2012

Suspect error using RichTextBox Class in server code

Using the 1.1 framework. We are using a newly created instance of a
RichTextBox Class in our server code to manipulate RTF that is stored
in the database. To clarify, we are not using or attempting to use
this class in the aspx page that calls the code, nor is the 'using
System.Windows.Forms' referenced in any of the aspx pages. The first
client using this software has been experiencing an error that we
cannot reproduce in-house. The error occurs intermittently anywhere
after 2-4 days of use, so it is not something reproducible on demand.
The fix is to restart IIS and on a couple of occasions a restart of
the server was necessary. The error is being trapped in code and
returned as string to the user which displays on the aspx page so it
is not an unhandled exception with a dump of the stack trace. The
error message is 'Error creating window handle". Once one user
receives this error all users receive the same error when trying to
perform the same operation. I am not 100% sure that the RichTextBox
code is what is causing the error but based on the message involved it
is my best guess. Here is a code snipit that shows how we are using
the RichTextBox.

string strFreeRTF = drRow["FRTF"].ToString().Trim();
string strTempRTF = drRow["TMPLTRTF"].ToString().Trim();
RichTextBox rtfFree = new RichTextBox();
rtfFree.Rtf = strFreeRTF; //prevents null reference
RichTextBox rtfTemp = new RichTextBox();
rtfTemp.Rtf = strTempRTF;
if(rtfTemp.Text.Length > 0)
{
rtfFree.AppendText("\r\n");
rtfTemp.SelectAll();
rtfTemp.Copy();
rtfFree.Paste();
}
if(strCodedCharting.Length > 0)
{
rtfFree.AppendText("\r\n");
rtfFree.AppendText(strCodedCharting);
}

if(drChart["SUMMARY"].ToString() != "")
{
if(rtfFree.Text.Length > 0)
{
rtfFree.AppendText("\r\n");
}
rtfFree.AppendText(drRow["SMRYTXT"].ToString());
}
if(rtfFree.Text != "")
strRet = rtfFree.Rtf;
return strRet;

The code performs what it is designed to do but obviously we need to
track down why the error occurs.

Does anyone have information that might assist with troubleshooting
this problem. Thanksusing winform controls are not supported by aspx pages. they require a
window handle to perform correctly, and system services like iis and
asp.net, do not have permission to create a window handle as they need
access to the desktop.

you might get away with it if the console is alway logged on the server, and
you gave permission. you still run the risk, that if the control pop's up a
dialog box (say for en error), your asp.net thread will be blocked until
some goes to the console and responds to the dialogbox.

this is very poor design, and you should look at replacing the rtf control
as soon as possible.

-- bruce (sqlwork.com)

"Eric" <msdnsupport@.nospammediserve.com> wrote in message
news:3fc3df27.1150041703@.news.devexpress.com...
> Using the 1.1 framework. We are using a newly created instance of a
> RichTextBox Class in our server code to manipulate RTF that is stored
> in the database. To clarify, we are not using or attempting to use
> this class in the aspx page that calls the code, nor is the 'using
> System.Windows.Forms' referenced in any of the aspx pages. The first
> client using this software has been experiencing an error that we
> cannot reproduce in-house. The error occurs intermittently anywhere
> after 2-4 days of use, so it is not something reproducible on demand.
> The fix is to restart IIS and on a couple of occasions a restart of
> the server was necessary. The error is being trapped in code and
> returned as string to the user which displays on the aspx page so it
> is not an unhandled exception with a dump of the stack trace. The
> error message is 'Error creating window handle". Once one user
> receives this error all users receive the same error when trying to
> perform the same operation. I am not 100% sure that the RichTextBox
> code is what is causing the error but based on the message involved it
> is my best guess. Here is a code snipit that shows how we are using
> the RichTextBox.
>
> string strFreeRTF = drRow["FRTF"].ToString().Trim();
> string strTempRTF = drRow["TMPLTRTF"].ToString().Trim();
> RichTextBox rtfFree = new RichTextBox();
> rtfFree.Rtf = strFreeRTF; //prevents null reference
> RichTextBox rtfTemp = new RichTextBox();
> rtfTemp.Rtf = strTempRTF;
> if(rtfTemp.Text.Length > 0)
> {
> rtfFree.AppendText("\r\n");
> rtfTemp.SelectAll();
> rtfTemp.Copy();
> rtfFree.Paste();
> }
> if(strCodedCharting.Length > 0)
> {
> rtfFree.AppendText("\r\n");
> rtfFree.AppendText(strCodedCharting);
> }
> if(drChart["SUMMARY"].ToString() != "")
> {
> if(rtfFree.Text.Length > 0)
> {
> rtfFree.AppendText("\r\n");
> }
> rtfFree.AppendText(drRow["SMRYTXT"].ToString());
> }
> if(rtfFree.Text != "")
> strRet = rtfFree.Rtf;
> return strRet;
> The code performs what it is designed to do but obviously we need to
> track down why the error occurs.
> Does anyone have information that might assist with troubleshooting
> this problem. Thanks