Last post Jan 04, 2010 04:54 PM by ryguy7272
Dec 22, 2009 07:40 PM|ryguy7272|LINK
I am fiddling with the code here:
I had a couple errors when I copied/pasted it into my project. I dimmed a couple variables, now the squiggle lines are gone, but I'm not sure how to call the functions in the project? Do I use a Lable or a TextBox? How do i make this work?
Dec 22, 2009 11:09 PM|gravyty|LINK
Maybe you should post your query in the message board at the bottom of the page at given url ... just a thought
Dec 22, 2009 11:10 PM|net.hitesh|LINK
Read FAQ part below the article,all problems are discussed there
Dec 23, 2009 09:18 AM|atconway|LINK
Well there are a couple of issues with the code on that link:
1st off, that code looks to be old ASP code and it has not been fully converted to VB.NET. Since there is no direct conversion path, you are going to have to do more than just further define a few lines of code to get it working. It appears someone did
actually convert the IsHoliday() and AddBusinessDay() Functions to C# at the bottom of the page in the posts. Here is a direct link to that post:
http://www.codeproject.com/KB/asp/BusinessDates.aspx?msg=3075454#xx3075454xx From there you could easily convert the C# to VB.NET. Use the following link for information on converters:
Here is a forum for ASP code that you could use if you need help with converting any lines:
ASP, VB Script Forums:
To actually call those methods once they were fully converted to .NET, all you would have to do is write code such as the following below:
Dim IsJulyFouthHoliday As Boolean = False
IsJulyFouthHoliday = IsHoliday(Date.Parse("07/04/2009"))
This is assuming the method 'IsHoliday' is in the same class or accessible by the calling code above. Obviously if it was in its own .dll or separate class, you may have to instantiate the class before accessing that method.
I would start with the (2) methods in the link above I provided that have already been converted to C#, and use a converter to get them to VB.NET. Then if you need the remaining methods converted, use the ASP, VBScript forums to help with that.
Hope this helps!
Dec 28, 2009 01:24 PM|ryguy7272|LINK
Thanks atconway! This pretty much makes sense. I converted the C# here:
To VB, using this:
Seems to work fine. I cpopied/pasted that code to this:
In my Default.aspx, I have this:
<%@ Page AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<form id="form1" runat="server">
I still don't know how to call the funtion. Do I add a TextBox, do I add some other Control? How do I run the code? That's my question.
Jan 04, 2010 12:21 AM|ryguy7272|LINK
Thanks everyone! Still didn't get it working; I'll just keep trying.
Jan 04, 2010 03:21 PM|atconway|LINK
No problem; I have the barebones code below that you could use an example to take in a date from the user and check it against the 'IsHoliday' function. Your question asks how you would use the code you converted. That will be based on your reuqirements.
In my sample code I have the user enter a date and then press a button. The button in turn calls a wired up server side event (via the 'Handles btnCheckDate.Click' reference) named 'btnCheckDate_Click'. This event makes a call to the 'IsHoliday' method to
determine if the date entered is a holiday. The result is examined and a label is updated.
No the code I provided in stricly the basics; exception handling, data validation, etc. would need to be added in a real scenario. Here is the code for the .aspx page:
<html xmlns="http://www.w3.org/1999/xhtml" >
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Please Enter a Date to see if it is a holiday in MM/DD/YYYY format: "></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Width="100px"></asp:TextBox>
<asp:Button ID="btnCheckDate" runat="server" Text="Check Date" />
<asp:Label ID="lblMessages" runat="server" Text=""></asp:Label>
...and here is the code behind:
Public Partial Class WebForm1
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Protected Sub btnCheckDate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnCheckDate.Click
Dim IsDateAHoliday As Boolean = False
'Call the 'IsHoliday' method to determine if the date entered is a holiday throughout the year:
IsDateAHoliday = IsHolidayrequirements(Date.Parse(strictlyMe.TextBox1.Text.Trim()))
'Display a message to the user based on the return value
If IsDateAHoliday Then
Me.lblMessages.Text = "The date you entered is a Holiday!"
Me.lblMessages.Text = "The date you entered is NOT a Holiday."
If you are really new to .NET, you can get to the code behind by double clicking a control like the button in design mode, right clicking the HTML and selecting 'View Code', or simply double clicking the code file in solution explorer that is associated
with the .aspx page you are working with (for vb.net it would be WebForm1.aspx.vb for example).
If you are indeed new to .NET, I also recommend reading some tutorials and videos on ASP.NET and server side development. A good link for ASP.NET videos is below:
General ASP.NET Videos:
Jan 04, 2010 04:54 PM|ryguy7272|LINK
Thanks again atconway! The HTML worked fine and your code looks fine, but I still couldn't get it working. I'm pretty busy with other things right now. I'll have to come back to this some other time. I'm pretty sure i'll need something like this sometime
soon. I'll revisit this someday.