Software Testing Social Network

Free Software Testing Tutorial and Quality Assurance Portal

Home Ask
Category:

Resolved Question

Please write a vb script program for the following?
1 .Write a Function for Reverse String.? Str="QuickTestprofessional" Without Using Inbuilt Function.

2 .Write a Function to replace the "|Testing|" as "Welcome to QTP" in the below said Text file and
need to save as Test1.txt

Filename : Test.Txt
Welcome to Mercury QuickTest Professional
the advanced solution |Testing|for functional test
and regression test |Testing|automation.
This next-generation |Testing|automated testing solution
deploys the concept of |Testing|keyword-driven testing to
enhance test creation |Testing| and maintenance.
Keyword-driven testing separates |Testing| much of the programming
work from the actual test steps |Testing| so that test steps can be
developed earlier and can often |Testing| be maintained with
only minor updates, even when |Testing| the application or
testing needs change |Testing| significantly.

3. Write a Script to get a input as age, and validate the age 0 - 18(Minor),18 - 55(Major) and Above 55 as "Sr.Citizen

Best Answer -

  • 1)
    Function myReverse(inputString As String) As String
    Dim i as Long

    For i = 1 to Len(inputString)

    myReverse = Mid(inputString,i,1) & myReverse

    Next i

    End Function

    2) I don't know if Split and Join are supported in VB, they are in VBA.

    replacedString = Join(Split(inputString, "|Testing|"), "Welcome to QTP")

    • 2010-04-11 06:12
    • 0 Rate this answer as good
    • 0 Rate this answer as bad
    • Report as abusive/illegal
  • 0 Interesting!
  • Hits: 137
  • Closed on: 2010-04-11 06:12
  • You answered this Question

Other Answers:

  • You shouldn't ask for help with homework here, what's the point of passing the class if you don't learn anything?

    I don't know VBScript, but I use Visual Basic 6, and most of it is pretty much identical (except for the fact that VBScript is a scripting language).

    #1.

    'Use it like this: myString = MyReverse("Hello, world!")
    Private Function MyReverse(ByRef Expression As String) As String
    Dim strRet As String, lonLen As Long
    Dim l As Long

    lonLen = Len(Expression)
    If lonLen = 0 Then Exit Function
    strRet = Space$(lonLen)

    For l = lonLen To 1 Step -1
    Mid$(strRet, l, 1) = Mid$(Expression, (lonLen - l) + 1, 1)
    Next l

    MyReverse = strRet
    End Function


    #2.

    'Use like this:
    'ReplaceInFile("Test.txt", "Test1.txt", "|Testing|", "Welcome to QTP")
    Private Sub ReplaceInFile(ByRef FilePath As String, _
    ByRef Destination As String, _
    ByRef Find As String, _
    ByRef ReplaceWith As String, _
    Optional ByVal CompareMethod As VbCompareMethod = vbBinaryCompare)

    On Error GoTo ErrorHandler

    Dim intHandle As Integer, strData As String

    'Easy way, but slow for large files.
    Open FilePath For Input As intHandle
    strData = Input$(LOF(intHandle), intHandle)
    Close intHandle
    intHandle = 0

    'Replace the data.
    strData = Replace(strData, Find, ReplaceWith, , , CompareMethod)
    intHandle = FreeFile

    'Kill destination file if it already exists.
    On Error Resume Next
    Kill Destination
    On Error GoTo ErrorHandler

    Open Destination For Append As intHandle
    Print #intHandle, strData;
    'Not sure if the ; at the end will raise error in VBScript.
    'But in Visual Basic, it prevents a new line at the end of file.
    'Remove it if needed.
    Close intHandle
    intHandle = FreeFile

    Exit Sub
    ErrorHandler:
    If intHandle <> 0 Then Close intHandle
    Exit Sub
    End Sub


    3. I'll let you do #3.

    • 2010-04-11 06:12
    • 0 Rate this answer as good
    • 0 Rate this answer as bad
    • Report as abusive/illegal