PDA

View Full Version : Testing VBA Tags



Ken Puls
01-07-2006, 10:54 AM
This is a test for Nate Oliver:

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

NateO
01-07-2006, 11:05 AM
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:


Sub Going_Postal()
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
On Error GoTo errHandler
With ie
.navigate "http://www.canadapost.ca/personal/tools/pcl/bin/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
I've uploaded the orginal...

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

NateO
01-07-2006, 11:06 AM
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... :(

Ken Puls
01-07-2006, 02:05 PM
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.

:)

NateO
01-07-2006, 02:19 PM
Will do, Ken. :friends:

Thanks for your consideration. :)