473,466 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

C#NET2008 Declare DateTime Variables

126 New Member
Hullo Good Guys,
I am using C#NET2008 for application
I need your help, Please help me.

I am encountering an interesting error to my surprise.
I am trying to declare DateTime variable and it’s not working.

The DateTime variables are supposed to be fill by Date selected from a Form called FrmPopUpCalender.

These coding belongs to FrmSalesEnquiry.cs

Error message:
Expected class, delegate, enum, interface, or struct
Expected class, delegate, enum, interface, or struct


Coding that generate the error message:
namespace CSharpWord
{
//define Date variable
private DateTime dteFromDate; < - - Error
private DateTime dteToDate; < - - Error

}
Jan 5 '11 #1

✓ answered by HaLo2FrEeEk

You're creating them outside the scope of a class. Variables can't be created outside of a class, you'd need something like this:

Expand|Select|Wrap|Line Numbers
  1. namespace CSharpWord
  2. {
  3.     public class someClass
  4.     {
  5.         private DateTime dteFromDate;
  6.         private DateTime dteToDate;
  7.         // Other code, methods, etc.
  8.     }
  9. }
Also, in the future, encapsulate any code that you post (longer than a single line) inside code tags:

[code]CODE GOES HERE[/code]

4 3773
HaLo2FrEeEk
404 Contributor
You're creating them outside the scope of a class. Variables can't be created outside of a class, you'd need something like this:

Expand|Select|Wrap|Line Numbers
  1. namespace CSharpWord
  2. {
  3.     public class someClass
  4.     {
  5.         private DateTime dteFromDate;
  6.         private DateTime dteToDate;
  7.         // Other code, methods, etc.
  8.     }
  9. }
Also, in the future, encapsulate any code that you post (longer than a single line) inside code tags:

[code]CODE GOES HERE[/code]
Jan 5 '11 #2
lenniekuah
126 New Member
Hi Halo2FrEeEK
Thank you for sharing your idea with me and also for pointing out my mistake. I have followed your instruction and my codings are working now.

Thank you very much. So Glad to meet you here.
Jan 5 '11 #3
Prasant jinaga
7 New Member
Hi,
Include Some class after namespace then declare the datetime variables.
namespace A
{
class B
{
// Declare variables over here
}
}


It will work...

Thanks,
Prasant
Jan 5 '11 #4
lenniekuah
126 New Member
Hi Prasant,
When you mention: DECLARE VARIABLE OVER HERE in English but not coding so it won't work unless it's logical coding
Feb 24 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: C.F. Scheidecker Antunes | last post by:
Hello all, I need to compare a datetime field in my database with the current time and return only the records that are 5 minutes old or older. Is there any way to do it? Any function to it? ...
6
by: David T. Ashley | last post by:
Hi, In my project, I typically declare and define variables in the .H file, i.e. DECMOD_MAIN UINT8 can_message_201_status_global #ifdef MODULE_MAIN = HAS_NEVER_BEEN_RECEIVED #endif ;
6
by: rick | last post by:
Noob problem. I prefer to keep all my scripts in an external '.js' file. I am currently loading the external '.js' file from the header. Problem is I would like to declare a global variable in the...
2
by: Fred Nelson | last post by:
Hi: Another C# newby question: How do I declare a null DateTime variable: DateTime myDate = null; I get the error:
5
by: Child | last post by:
I have a class object with a couple of datetime variables that are not required (for example the closing date for an event). I have been doing some research on usenet history to find that this is...
6
by: John A Grandy | last post by:
inside a procedure , i code Dim values(1) As Object .... various other lines of code ... ReDim values(2) As Object
4
by: Mika M | last post by:
I need to compare two DateTime variables named as t1 and t2 using VB.NET 2003. If t1 is any earlier time as t2, only then program should do something like... If (t1 < t2) Then...
9
by: johnlim20088 | last post by:
Hi, Hi, currently I developing an application in C# NET, let say i have a page call viewrecord.aspx, in this page, i have a global variables declared before the page_Load, so all function can...
3
by: sravik | last post by:
how and where to declare global variables in C#. Like Conection strings and some file paths etc.
3
by: Anil Gupte | last post by:
I am using the followig code: SqlConnection con = new SqlConnection(strcon); con.Open(); string strSelect = "Select PaidUntil from Users where username='" + un + "'"; SqlCommand cmd = new...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.