You must Sign In to post a response.
  • Category: ASP.NET

    VB code in classic ASP


    How to write vbscript code in a classic ASP pages? Ex: Dim str as String.
    and also how can I write Try Catch block in asp page?

  • #767882
    you can easily write a procedure in vbscript in asp and call it on button click or where ever you want
    checkout below sample for more details

    < html>
    < head>
    < %
    sub vbproc(num1,num2)
    end sub
    < /head>

    < body>
    < p>You can call a procedure like this:</p>
    < p>Result: < %call vbproc(3,4)%></p>
    < p>Or, like this:</p>
    < p>Result: <%vbproc 3,4%></p>
    < /body>
    < /html>
    //You can call a procedure like this:
    Result: 12
    Or, like this:
    Result: 12

    hope it helps

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #767931
    I am not sure you are looking for VBScript or VB Code.
    Because you have mentioned about the declaration in examples.

    But you can use or utilize the VBCode in ASP Page by calling the asp dll.

    Set Obj = Server.CreateObject("dllname")


  • #767932

    Refer this.. for using try catch in VB

    Private Sub populateCountries(ByVal cmb As ComboBox)
    Dim dsCountries As DataSet = GetcountryNamesUsingQuery()
    If dsCountries.Tables(0).Rows.Count > 0 Then
    cmb.DataSource = dsCountries.Tables(0).DefaultView
    End If
    cmb.SelectedIndex = -1
    Catch ex As Exception

    End Try
    End Sub

    Hope this give you an idea

    Never lose hope..You never know what tomorrow will bring

  • #767933
    Hi Sony,

    I guess you are answering for this question,


  • #767942
    Hai Pramod,
    As the ASP is server side scripting language which allows the programmer to write both the client and server side code in the same page. You can write the classic asp code as well as VB script code in the same page.
    The error can be handled using the Error Number and if the Error Number value is not 0, means there is some error in the page and you can display that error.

    If Err.Number <> 0 Then
    Response.Write (Err.Description)
    End If

    But you need to add the below line of code on the top of every page:

    On Error Resume Next

    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • Sign In to post your comments