473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Exceptionhandling in statemachine

Hi,
I'm going to create one of the classic checks in Web-development : THE
DATE CHECKING !

I have made some kind of statemachine for datechecking, but I don't
know where to return the 0 (zero) value, for date-checking succeeded :

void function TestDate() {
i = 1;
dd = parseInt(document.forms(0).txtDateringDay.value);
yy = parseInt(document.forms(0).txtDateringYear.value);
mm = parseInt(document.forms(0).txtDateringMonth.value) ;
while (i > 0)
switch (i) {
case 1 :
if (dd < 1 || dd > 31) {
errmsg = "Day value is not accepted";
i = -1;
}
else {
i++;
}
break;
case 2 :
if (mm < 1 || mm > 12) {
errmsg = "Month value is not accepted";
i = -1;
}
else {
i++;
}
break;
case 3 :
//----HERE is the problem, I think :
try{
CurrDate = new date(mm,dd,yy);
}
catch (e) {
errmsg = "Date format is not accepted";
i = -1;
{
break;

}
}
}
if (i < 0) {
alert("Error : " + errmsg);
}
else {
alert("Date is accepted!");
}
}
Thanks,

Joergen Jensen
Jul 20 '05 #1
1 1130
jo********@yahoo.dk (Joergen Vig) writes:
I'm going to create one of the classic checks in Web-development : THE
DATE CHECKING !
Why? :)
I have made some kind of statemachine for datechecking,
Is this for a programming course, because I can't see any other reason
for doing a state machine for three things that has to happen in sequence.
Normal program flow wil handle that.
but I don't know where to return the 0 (zero) value, for
date-checking succeeded :
There us a much simpler way using the built in Date object.
void function TestDate() {
i = 1;
dd = parseInt(document.forms(0).txtDateringDay.value);
You should give parseInt a second argument of 10, otherwise, a user
writing "012" will be surpriced to find it meaning 10 (interpreted as
octal).

Are you sure you want an input of "12 bulliwug" to count as 12?
yy = parseInt(document.forms(0).txtDateringYear.value);
mm = parseInt(document.forms(0).txtDateringMonth.value) ;
Here you just do:
---
var d = new Date(yy,mm-1,dd);
if (d.getMonth()+1 != mm || d.getDate() != dd) {
alert("Date does not exist");
return 1;
}

It also handles illegal dates like 31th of february.
//----HERE is the problem, I think :
try{
CurrDate = new date(mm,dd,yy);


Date is with a capital D.

It never throws an exception. And it counts months from 0=January to
11=December.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Patrick | last post by:
Does somebody knwo a good example/theorie about statemachines?
1
by: René | last post by:
Hey, I'm trying to throw an exception through to SOAP- protocol. Like this: throw new SoapException("message", SoapException.ServerFaultCode); When I catch the exception in my application:
1
by: heikekrieg | last post by:
Hi, i have the problem that a background WorkerThread is calling Objects remote (.NET remoting). Now if the conection is closed my Thread gets an exception. But the Exception should be...
4
by: muz dogru | last post by:
I have made own Exception classes, which extend from Exception. When I throw a new MyException("my error message"), then catch the error and print the message, it's all fine within an application....
2
by: HockeyFan | last post by:
Does anyone have a good genereal exceptionhandling class that can be preferably used with web apps as well as windows apps, but in the least, to be able to work well in web apps. I'm fairly new to...
5
by: BenCoo | last post by:
Hi, In my ASP.NET application I do some exceptionhandling and redirect the exception with Session("Exception") to an Errorpage.aspx. When I put the error in a label I get the following : ...
0
by: hoganlai2006 | last post by:
Recently I have come across with a problem with enum. I have defined an enum as follows: private void btnViewNumber_Click(object sender, EventArgs e) { if...
2
by: =?Utf-8?B?UG9sbHkgQW5uYQ==?= | last post by:
Hi, I have been successfully using the EHAB & Logging Application Block. Now however I get the error below and looking on line I was told that I have not set references to all the dlls. I have...
0
by: =?Utf-8?B?UG9sbHkgQW5uYQ==?= | last post by:
Hi, I have previously used EL v 3.1 Exception Handling application block successfully. I thought I would now try to do the same with EL v 4.0. My first experiment was to replace an exception....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
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,...

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.