[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1648
  • Last Modified:

Convert javascript to vb.net

I need to convert the following to vb.net
<SCRIPT LANGUAGE="JavaScript"><!--
function y2k(number)    { return (number < 1000) ? number + 1900 : number; }

function makeArray() {
    this[0] = makeArray.arguments.length;
    for (i = 0; i<makeArray.arguments.length; i++)
        this[i+1] = makeArray.arguments[i];
}

var daysofweek   = new makeArray('Sunday',
                                 'Monday',
                                 'Tuesday',
                                 'Wednesday',
                                 'Thursday',
                                 'Friday',
                                 'Saturday');

var monthsofyear = new makeArray('January',
                                 'February',
                                 'March',
                                 'April',
                                 'May',
                                 'June',
                                 'July',
                                 'August',
                                 'September',
                                 'October',
                                 'November',
                                 'December');

var chinese      = new makeArray('Rat',
                                 'Ox',
                                 'Tiger',
                                 'Hare',
                                 'Dragon',
                                 'Snake',
                                 'Horse',
                                 'Sheep',
                                 'Monkey',
                                 'Fowl',
                                 'Dog',
                                 'Pig');

var branches     = new makeArray('Zi',
                                 'Chou',
                                 'Yin',
                                 'Mao',
                                 'Chen',
                                 'Si',
                                 'Wu',
                                 'Wei',
                                 'Shen',
                                 'You',
                                 'Xu',
                                 'Hai');

var stems        = new makeArray('Jia',
                                 'Yi',
                                 'Bing',
                                 'Ding',
                                 'Wu',
                                 'Ji',
                                 'Geng',
                                 'Xin',
                                 'Ren',
                                 'Gui');

var chinesenewyear = new makeArray(1.31,2.19,2.08,1.29,2.16,2.04,1.25,2.13,2.02,1.22,
                                   2.10,1.30,2.18,2.06,1.26,2.14,2.03,1.23,2.11,2.01,
                                   2.20,2.08,1.28,2.16,2.05,1.25,2.13,2.02,1.23,2.10,
                                   1.30,2.17,2.06,1.26,2.14,2.04,1.24,2.11,1.31,2.19,
                                   2.08,1.27,2.15,2.05,1.25,2.13,2.02,1.22,2.10,1.29,
                                   2.17,2.06,1.27,2.14,2.03,1.24,2.12,1.31,2.18,2.08,
                                   1.28,2.15,2.05,1.25,2.13,2.02,1.21,2.09,1.30,2.17,
                                   2.06,1.27,2.15,2.03,1.23,2.11,1.31,2.18,2.07,1.28,
                                   2.16,2.05,1.25,2.13,2.02,2.20,2.09,1.29,2.17,2.06,
                                   1.27,2.15,2.04,1.23,2.10,1.31,2.19,2.07,1.28,2.16);


function DayOfWeek(day,month,year) {
    var a = Math.floor((14 - month)/12);
    var y = year - a;
    var m = month + 12*a - 2;
    var d = (day + y + Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400) + Math.floor((31*m)/12)) % 7;
    return d+1;
}

function Nths(day) {
    if (day == 1 || day == 21 || day == 31) return 'st';
    if (day == 2 || day == 22) return 'nd';
    if (day == 3 || day == 23) return 'rd';
    return 'th';
}

function FullDate(day,month,year) {
    return daysofweek[DayOfWeek(day,month,year)] +' '+ day + Nths(day) +' '+ monthsofyear[month] +' '+ year;
}

function Chinese(day,month,year) {
    if ((year > 1900) && (year < 1999)) {
        var newYear = chinesenewyear[year - 1899];
        var newMonth = Math.floor(newYear);
        var newDay = Math.round((newYear*100)-(newMonth*100));

        if ((month > newMonth) || ((month == newMonth) && (day >= newDay))) {
            // this year
            var chineseBranch = (year-3)%12;
            var chineseStem = (year-3)%10;

            var nextYear = chinesenewyear[year - 1899 + 1];
            var nextMonth = Math.floor(nextYear);
            var nextDay = Math.round((nextYear*100)-(nextMonth*100));

            var lastDay = nextDay - 1;
            if (lastDay == 0) {
                lastMonth = nextMonth - 1;
                lastDay = 31;
            }
            else lastMonth = nextMonth;
           
            chineseyearrange = FullDate(newDay,newMonth,year) + ' - ' +
                               FullDate(lastDay,lastMonth,year+1);
        }
        else {
            // last year
            var chineseBranch = (year-4)%12;
            var chineseStem = (year-4)%10;

            var oldYear = chinesenewyear[year - 1899 - 1];
            var oldMonth = Math.floor(oldYear);
            var oldDay = Math.round((oldYear*100)-(oldMonth*100));

            var lastDay = newDay - 1;
            if (lastDay == 0) {
                lastMonth = newMonth - 1;
                lastDay = 31;
            }
            else lastMonth = newMonth;
           
            chineseyearrange = FullDate(oldDay,oldMonth,year-1) + ' ' +
                               FullDate(lastDay,lastMonth,year);
        }
    }
    else {
        var chineseBranch = (year-3)%12;
        var chineseStem = (year-3)%10;
    }

    if (chineseBranch == 0)
        chineseBranch = 12;

    if (chineseStem == 0)
        chineseStem = 10;

    chineseyearname = '(' + stems[chineseStem] + '-' + branches[chineseBranch] + ')';

    return chinese[chineseBranch];
}

if (location.search.length == 0) {
    var year = parent.year - 0;
    var month = parent.month - 0;
    var day = parent.day - 0;
}
else {
    var day   = location.search.substring(5,7) - 0;
    var month = location.search.substring(14,16) - 0;
    var year  = location.search.substring(22) - 0;
}

var today = new Date();
var thisYear = y2k(today.getYear());
var thisMonth = today.getMonth()+1;
var thisDay = today.getDate();
//--></SCRIPT>
0
mathieu_cupryk
Asked:
mathieu_cupryk
1 Solution
 
nfashawCommented:
I suggest putting an advertisement on a local bulletin board, contacting a local university, using a service like craigslist.com or rentacoder.com and hire someone to do the work for you.

There are also plenty of resources available to learn VB.NET yourself.
0
 
jazzIIIloveCommented:
VB is not compatible with Firefox Mozilla, I recommend using the above javascript directly, not converting it.
0
 
me655321Commented:
Not sure what all you needed from that. Some of those functions are built into VB.Net. I assumed you just wanted the function to get the animal name? Here is a vb.net version of that...
(Add a textbox named Textbox1 and a datetimepicker named DateTimePicker1)
Dim chinese As String() = New String() {"Rat", _
    "Ox", _
    "Tiger", _
    "Hare", _
    "Dragon", _
    "Snake", _
    "Horse", _
    "Sheep", _
    "Monkey", _
    "Fowl", _
    "Dog", _
    "Pig"}

    Dim branches As String() = New String() {"Zi", _
    "Chou", _
    "Yin", _
    "Mao", _
    "Chen", _
    "Si", _
    "Wu", _
    "Wei", _
    "Shen", _
    "You", _
    "Xu", _
    "Hai"}

    Dim stems As String() = New String() {"Jia", _
    "Yi", _
    "Bing", _
    "Ding", _
    "Wu", _
    "Ji", _
    "Geng", _
    "Xin", _
    "Ren", _
    "Gui"}

    Dim chinesenewyear As Single() = New Single() {1.31, 2.19, 2.08, 1.29, 2.16, 2.04, 1.25, 2.13, 2.02, 1.22, _
                                       2.1, 1.3, 2.18, 2.06, 1.26, 2.14, 2.03, 1.23, 2.11, 2.01, _
                                       2.2, 2.08, 1.28, 2.16, 2.05, 1.25, 2.13, 2.02, 1.23, 2.1, _
                                       1.3, 2.17, 2.06, 1.26, 2.14, 2.04, 1.24, 2.11, 1.31, 2.19, _
                                       2.08, 1.27, 2.15, 2.05, 1.25, 2.13, 2.02, 1.22, 2.1, 1.29, _
                                       2.17, 2.06, 1.27, 2.14, 2.03, 1.24, 2.12, 1.31, 2.18, 2.08, _
                                       1.28, 2.15, 2.05, 1.25, 2.13, 2.02, 1.21, 2.09, 1.3, 2.17, _
                                       2.06, 1.27, 2.15, 2.03, 1.23, 2.11, 1.31, 2.18, 2.07, 1.28, _
                                       2.16, 2.05, 1.25, 2.13, 2.02, 2.2, 2.09, 1.29, 2.17, 2.06, _
                                       1.27, 2.15, 2.04, 1.23, 2.1, 1.31, 2.19, 2.07, 1.28, 2.16}
    Function getChinese(ByVal day As Integer, ByVal month As Integer, ByVal year As Integer)
        Dim newYear As Single
        Dim newMonth As Integer
        Dim newDay As Integer
        Dim chineseBranch = (year - 3) Mod 12
        Dim chineseStem = (year - 3) Mod 10

        If ((year > 1900) And (year < 1999)) Then
            newYear = chinesenewyear(year - 1899)
            newMonth = Math.Floor(newYear)
            newDay = Math.Round((newYear * 100) - (newMonth * 100))

            If ((month > newMonth) Or ((month = newMonth) And (day >= newDay))) Then
                ' this year
                chineseBranch = (year - 3) Mod 12
            Else
                ' last year
                chineseBranch = (year - 4) Mod 12
            End If

        Else
            chineseBranch = (year - 3) Mod 12
        End If

        If (chineseBranch = 0) Then
            chineseBranch = 12
        End If
        Return chinese(chineseBranch - 1)
    End Function

    Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
        TextBox1.Text = getChinese(DateTimePicker1.Value.Day, DateTimePicker1.Value.Month, DateTimePicker1.Value.Year)
    End Sub

Open in new window

0
 
mathieu_cuprykAuthor Commented:
k
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now