VB Script Examples-II

VBScript General Examples


1) Read a value and find size of the value

Dim val: val=Inputbox("Enter value for val: ")
val_length =Len(val)
msgbox "Size of "&val&" is "&val_length


2) Read a value and find whether the value is numeric or not?

Dim val: val=Inputbox("Enter value for val: ")
val_type =IsNumeric(val)
If val_type = true Then
    msgbox "val is Numeric"
else
    msgbox "val is not Numeric"
End If

3)'Read a value and find whether the value is Date type data or not?


Dim val: val=Inputbox("Enter value for val: ")
val_type =IsDate(val)
If val_type = true Then
    msgbox "val is Date type data"
else
    msgbox "val is not date type"
End If


4)Read a value and Verify whether the value is 10-digit number or not and started with 9 0r 8.

'Then Display it is a valid mobile number

Dim val,val_Length, val_Numeric, val_Start
val=Inputbox("Enter value for val: ")
val_Length= Len(val)
val_Numeric=IsNumeric(val)
val_Start=Left(val,1)
If val_Length=10 and val_Numeric and val_Start=9 or val_Start=8 Then
    msgbox val&"  is a valid mobile number "
Else
    msgbox val&"  is not a valid mobile number "
End If

5) 'Read a mobile number and verify the series


'if it starts with 92478 or 92471 then display it is TataIndicom number
'if it starts with 98490 or 98480 then display it is Airtel number


Dim val, val_Length,val_Numeric,val_Series,val_Start
val=Inputbox("Enter value for val: ")
val_Length= Len(val)
val_Numeric=IsNumeric(val)
val_Start=Left(val,1)
val_Series=Left(val,5)
If val_Numeric=true Then

If val_Length=10 and val_Start=9  Then

    If val_Series = 92478 or val_Series=92471 Then
        msgbox "It is TataIndicom Number"
    ElseIf val_Series=98490 or val_Series = 98480 then
        msgbox "It is Airtel Number"
    End If

Else
    msgbox val&"  is not a valid mobile number "
End If
Else
    msgbox val& " is Invalid data"
End If

6) Read a Value and Verify weather the value is started with Alfa bytes or not? (First letter should be Alfa byte)

Dim val, val_Asc

val=Inputbox("enter a value")
val_Asc=Asc(val)
Msgbox val_Asc
If val_Asc>=65 and val_Asc<=90 or val_Asc>=97 and val_Asc<=122Then
    msgbox val&" is an Alphabet"
Else
    msgbox val&" is not an Alphabet"
End If

7) Read a value and Verify weather the value is Alfa bytes are not?

Dim str, valAsc, flag,i
Dim strlen, counter,valsingle
counter=0

str=Inputbox("enter a string value")

strlen= Len(str)
For i=1 to strlen step 1
        valsingle=Mid(str,i,1)
        valAsc=Asc(valsingle)
        If valAsc>=65 and valAsc<=90 or valAsc>=97 and valAsc<=122Then
                flag=1
                counter=counter+1
        Else
                flag=0
        End If
Next

msgbox "No.of characters  " &counter


If counter=strlen and flag=1Then

    msgbox str&" is an Alphabetic value"
Else
    msgbox str&" is not an Alphabetic value"
End If

 Visit:

1 comments:

i have a webtable how to findout first and second highest marks of a student using webtable methods

Post a Comment