Consulting

Results 1 to 5 of 5

Thread: Testing VBA Tags

  1. #1
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location

    Testing VBA Tags

    This is a test for Nate Oliver:

    [vba]Public Function sCase(ByRef strIn As String) As String
    Dim bArr() As Byte, i As Long, i2 As Long
    If strIn = vbNullString Then Exit Function
    Let bArr = strIn
    Select Case bArr(0)
    Case 97 To 122
    bArr(0) = bArr(0) - 32
    End Select
    For i = 2 To UBound(bArr) Step 2
    Select Case bArr(i)
    Case 105
    If Not i = UBound(bArr) - 1 Then
    Select Case bArr(i + 2)
    Case 32, 33, 39, 44, 46, 58, 59, 63, 148, 160
    If bArr(i - 2) = 32 Then _
    bArr(i) = bArr(i) - 32
    End Select
    ElseIf bArr(i - 2) = 32 Then _
    bArr(i) = bArr(i) - 32
    End If
    Case 33, 46, 58, 63
    For i2 = i + 2 To UBound(bArr) Step 2
    Select Case bArr(i2)
    Case 97 To 122
    bArr(i2) = bArr(i2) - 32
    i = i2: Exit For
    End Select
    Select Case bArr(i2)
    Case 32, 33, 46, 63, 160
    Case Else
    i = i2: Exit For
    End Select
    Next
    End Select
    Next
    sCase = bArr
    End Function
    Sub testTime()
    Debug.Print sCase(LCase$("hello? erm, i'M only testing, eh. indeed, " & _
    "i am inquisitve."))
    Debug.Print sCase(LCase$("how old?! 22 Years."))
    Debug.Print sCase(LCase$("how old?! twenty-two Years."))
    Debug.Print sCase(LCase$("hmmmm.... wOrking?!?! sam i am. yes-no? " & _
    "isn't i'm isn't."))
    Debug.Print sCase(LCase$("THE DAY WAS SUNNY AND I WORE A HAT.PETER WAS THERE "))
    Debug.Print sCase(LCase$("no WorRies, i'm ONLY testIng! yes-no?"))
    Debug.Print sCase(LCase$("mY fRiend & i"))
    Debug.Print sCase(LCase$("iiiiiiiiiiiiii"))
    Debug.Print sCase(LCase$("***T. toast %T i @"))
    Debug.Print sCase(LCase$("re: sentences."))
    Debug.Print sCase("hello? thought i'd test this for David McRitchie. NOTHING.")
    End Sub[/vba]
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  2. #2
    VBAX Regular NateO's Avatar
    Joined
    Jun 2004
    Location
    Minneapolis, MN
    Posts
    90
    Location

    Smile

    Hmmm, not bad actually, Ken.

    This could use a tab:
    					If bArr(i - 2) = 32 Then _ 
    					bArr(i) = bArr(i) - 32
    But otherwise not too bad...

    How about this:

    [vba]
    Sub Going_Postal()
    Dim ie As Object
    Set ie = CreateObject("InternetExplorer.Application")
    On Error GoTo errHandler
    With ie
    .navigate "http://www.canadapost.ca/personal/to...in/quick-e.asp"
    Do While .busy: DoEvents: Loop
    Do While .ReadyState <> 4: DoEvents: Loop
    With .document.Forms(1)
    'Stree Number
    .street_number.Value = "10132"
    'Stree Name
    .street_name.Value = "Imperial Street"
    'City
    .city.Value = "Chilliwack"
    'AB = Alberta, BC = British Columbia, MB = Manitoba, NB = New Brunswick, _
    NL = Newfoundland and Labrador, NS = Nova Scotia, NT = Northwest Territories, _
    NU = Nunavut, ON = Ontario, PE = Prince Edward Island, QC = Quebec, _
    SK = Saskatchewan, YT = Yukon
    .prov.Value = "BC"
    .submit
    End With
    Do While Not CBool(InStrB(1, .document.URL, _
    "cp_search_response-e.asp"))
    DoEvents
    Loop
    Do While .busy: DoEvents: Loop
    Do While .ReadyState <> 4: DoEvents: Loop
    MsgBox .document.all.tags("table").Item(11).Rows(1).Cells(7).innerText
    End With
    errHandler:
    ie.Quit: Set ie = Nothing
    End Sub[/vba]
    I've uploaded the orginal...

    Edit: On Ken's original post, the whole Select Case block needs a tab, the way I write 'em...
    Regards,
    Nate Oliver

  3. #3
    VBAX Regular NateO's Avatar
    Joined
    Jun 2004
    Location
    Minneapolis, MN
    Posts
    90
    Location

    Unhappy

    That's pretty sketchy... This is my concern, I actually am the original author of this code, yet it now looks like I have no clue what I am doing...
    Regards,
    Nate Oliver

  4. #4
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Well... I hear you there. I write my Case statements the same way you do, but I'll live with that minor deal. The second example... well... yeah, it doesn't look all that great, I'll give you that.

    FYI, we do still support the default Code tags as well:

    msgbox "See what I mean?"
    I like the VBA tags, and they'll work well for most coders, but if you have something that doesn't work, edit and try them out.

    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  5. #5
    VBAX Regular NateO's Avatar
    Joined
    Jun 2004
    Location
    Minneapolis, MN
    Posts
    90
    Location

    Thumbs up

    Will do, Ken.

    Thanks for your consideration.
    Regards,
    Nate Oliver

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •