.NET Framework Bookmark and Share   
 index > JScript for the .NET Framework > Convert Jscript to VBscript
 

Convert Jscript to VBscript

I'm hoping someone will be nice enough to help me.
I'm trying to covert this Jscript to vbscript.
I've posted the original here. I have an include with the functions and I'm trying to insert this into a vb .aspx page.
My try is below the jscript
while (!rst.EOF) { if ((rst.Fields("somevalue").Value ? 1 : 0) != istrue&& typename!= rst.Fields("_id").Value){ Response.Write("<option value=\"" + rst.Fields("_id").Value + "\" style=\"color: " + (rst.Fields("somevalue").Value ? "red" : "blue") + ";\">" + rst.Fields("name").Value + "</span></option>\r\n"); ++SelectedCount; } rst.MoveNext(); }
While (Not rst.EOF)
        If ((IIf(rst.Fields("somevalue").Value, 1, 0)) <> istrue And typename <> rst.Fields("_id").Value) Then
            Response.Write("<option value=\"" + rst.Fields("_id").Value + "\" style=\"color: " + (iif(rst.Fields("somevalue").Value,"red","blue")) + ";\">" + rst.Fields("name").Value + "</span></option>\r\n")
            SelectedCount = SelectedCount + 1
        End If
        rst.MoveNext()
    End While

aalish
Hi aalish,
As you're using an ASPX page on the server-side, I gather you're converting to VB.Net (different from vbscript).

I'm more familiar with C# (or JScript.Net) but I think I can help. Here are my assumptions:

1. The rst variable is previously set to open an ADODB.Recordset such that the fields "_id" and "name" are not null and do not contain HTML markup. (If it does contain valid markup, you would want to remove the call to HttpUtility.HtmlEncode() but keep the attribute encoding so as not to worry about embedded quotation marks).

2. That your original is missing an opening <span> tag, (as opposed to containing that markup).

3. That istrue and SelectedCount variables are previously defined as Integer.

4. That the typename variable is previously defined and that you can rename it. The VB IDE will auto-format this into the TypeName() function and that isn't what you want. I've used my_typename here.

I included a helper function, JsBool(), to simulate the JScript evaluation rules for a Boolean context. (Possibly "over-kill" for your actual needs). VB functions cannot be nested like JScript function so you'll want to put outside the Sub or Function block that contains your original snippet.

Best of luck,

Des


'...

        While Not rst.EOF
            If ((IIf(JsBool(rst.Fields("somevalue").Value), 1, 0)) <> istrue And my_typename <> rst.Fields("_id").Value) Then
                Response.Write("<option value=""" & HttpUtility.HtmlAttributeEncode(rst.Fields("_id").Value) & """ style=""color: " & IIf(JsBool(rst.Fields("somevalue").Value), "red", "blue") & ";""><span>" & HttpUtility.HtmlEncode(rst.Fields("name").Value) & "</span></option>" & vbCrLf)
                SelectedCount = SelectedCount + 1
            End If
            rst.MoveNext()
        End While

'...
'End Sub/Function


    Function JsBool(ByRef o As Object) As Boolean
        If o Is Nothing OrElse IsDBNull(o) OrElse String.IsNullOrEmpty(o.ToString()) OrElse o.ToString() = "0" OrElse o.ToString() = "NaN" Then Return False
        If IsNumeric(o) AndAlso CDbl(o) = 0 Then Return False
        If TypeOf o Is Boolean AndAlso CBool(o) = False Then Return False
        Return True
    End Function

Mr Deslock
Hi aalish,
As you're using an ASPX page on the server-side, I gather you're converting to VB.Net (different from vbscript).

I'm more familiar with C# (or JScript.Net) but I think I can help. Here are my assumptions:

1. The rst variable is previously set to open an ADODB.Recordset such that the fields "_id" and "name" are not null and do not contain HTML markup. (If it does contain valid markup, you would want to remove the call to HttpUtility.HtmlEncode() but keep the attribute encoding so as not to worry about embedded quotation marks).

2. That your original is missing an opening <span> tag, (as opposed to containing that markup).

3. That istrue and SelectedCount variables are previously defined as Integer.

4. That the typename variable is previously defined and that you can rename it. The VB IDE will auto-format this into the TypeName() function and that isn't what you want. I've used my_typename here.

I included a helper function, JsBool(), to simulate the JScript evaluation rules for a Boolean context. (Possibly "over-kill" for your actual needs). VB functions cannot be nested like JScript function so you'll want to put outside the Sub or Function block that contains your original snippet.

Best of luck,

Des


'...

        While Not rst.EOF
            If ((IIf(JsBool(rst.Fields("somevalue").Value), 1, 0)) <> istrue And my_typename <> rst.Fields("_id").Value) Then
                Response.Write("<option value=""" & HttpUtility.HtmlAttributeEncode(rst.Fields("_id").Value) & """ style=""color: " & IIf(JsBool(rst.Fields("somevalue").Value), "red", "blue") & ";""><span>" & HttpUtility.HtmlEncode(rst.Fields("name").Value) & "</span></option>" & vbCrLf)
                SelectedCount = SelectedCount + 1
            End If
            rst.MoveNext()
        End While

'...
'End Sub/Function


    Function JsBool(ByRef o As Object) As Boolean
        If o Is Nothing OrElse IsDBNull(o) OrElse String.IsNullOrEmpty(o.ToString()) OrElse o.ToString() = "0" OrElse o.ToString() = "NaN" Then Return False
        If IsNumeric(o) AndAlso CDbl(o) = 0 Then Return False
        If TypeOf o Is Boolean AndAlso CBool(o) = False Then Return False
        Return True
    End Function

Mr Deslock

You can use google to search for other answers

Custom Search

More Threads

• help with redirect to url when gridview row is double clicked
• documents.all and form.elements collection undefined
• Deleting empty folders with recursive JScript
• browser close and refresh event problem..
• Run js code in webpages from browser
• Calling C# methods from a javascript
• Javascript won't recognize my input control
• "Microsoft JScript runtime error: Object expected" --> Very Weird error >_<
• Permission Denied, Windows Vista
• javascript enabled or disabled