April 2011 in the Life of Ben (Blog)

  1. January
  2. February
  3. March
  4. April
  5. May
  6. June
  7. July
  8. August
  9. September
  10. October
  11. November
  12. December

Converting Windows-1252 to HTML NCRs in VB6 (26th April 2011)

TextStudio is useless for nearly all users and purposes. But now it converts the ambigious characters from 128 up to 159 into their Named Character Reference (NCR) form. The sample uses my recently rationalised universal syntax highlighting.

Updating my whole site to match that will take quite a while! It’s basically to help my shift from numbers to names in entities.

My actual code is, of course, dreadful. But the array is Copy and Paste friendly.

Project Structure

Declare the Array, arrWindows1252

'Windows 1252 Character Conversion
Dim arrWindows1252(128 To 159) As String 'array of ambiguous codepoints

Initialise the Array with InitWindows1252()

Sub InitWindows1252()
'Note: Codepoints taken from here: http://www.i18nguy.com/markup/ncrs.html#t128159

'Initialise array:
arrWindows1252(128) = "€"     ' €
arrWindows1252(129) = "?"          ' unassigned
arrWindows1252(130) = "‚"    ' ‚
arrWindows1252(131) = "ƒ"     ' ƒ
arrWindows1252(132) = "„"    ' „
arrWindows1252(133) = "…"   ' …
arrWindows1252(134) = "†"   ' ‡
arrWindows1252(135) = "‡"   ' ‡
arrWindows1252(136) = "ˆ"     ' ˆ
arrWindows1252(137) = "‰"   ' ‰
arrWindows1252(138) = "Š"   ' Š
arrWindows1252(139) = "‹"   ' ‹
arrWindows1252(140) = "Œ"    ' Œ
arrWindows1252(141) = "?"          ' unassigned
arrWindows1252(142) = "Ž"     ' Ž
arrWindows1252(143) = "?"          ' unassigned
arrWindows1252(144) = "?"          ' unassigned
arrWindows1252(145) = "‘"    ' ‘
arrWindows1252(146) = "’"    ' ’
arrWindows1252(147) = "“"    ' “
arrWindows1252(148) = "”"    ' ”
arrWindows1252(149) = "•"     ' •
arrWindows1252(150) = "–"    ' –
arrWindows1252(151) = "—"    ' —
arrWindows1252(152) = "˜"    ' ˜
arrWindows1252(153) = "™"    ' ™
arrWindows1252(154) = "š"   ' š
arrWindows1252(155) = "›"   ' ›
arrWindows1252(156) = "œ"    ' œ
arrWindows1252(157) = "?"          ' unassigned
arrWindows1252(158) = "ž"     ' ž
arrWindows1252(159) = "Ÿ"     ' Ÿ

End Sub

Trigger the Conversion from mnuFormatHtmlEntitiesEscape_Click()

Public Sub mnuFormatHtmlEntitiesEscape_Click(Index As Integer)

Dim i As Long
Dim Length As Long 'length of selected text
Dim Replaced As Boolean 'result of non-ASCII escape function'No files?
If Not IsAnyFileOpen Then Exit Sub
Screen.MousePointer = vbHourglass
strText = ActiveForm.rtfBox.SelText

Select Case Index 'index of button pressed:
    Case 0 'Escape HTML Tokens:Case 1 'Escape Non-ASCII:
        StatusBar.Panels(1) = "Checking file..."
        'Run through all text in active file:
        Replaced = EscapeNonASCII(ActiveForm.Tag) 'store status of module function
    Case 2 'Escape Non-ASCII From All Files:Case 3 'Escape Selected:End Select

'Any non-ASCII characters replaced?
If Replaced Then
    StatusBar.Panels(1) = "Escaped non-ASCII characters in active file"
    StatusBar.Panels(1) = "No non-ASCII characters found in active file"
End If

Call UpdateEdit
Call UpdateFileSizePanel

Screen.MousePointer = vbNormal

End Sub

Do the Conversion with EscapeNonASCII()

Function EscapeNonASCII(ID As Long) As Boolean

Dim i As Long: i = 1
Dim Length As Long 'length of selected text
Dim Char As String * 1 'character currently being tested
Dim strText As String 'text to be replaced
Dim Completed As Boolean 'indicates replacement has finished
Dim AnySelected As Boolean 'indicates if any text is selected
'Note: Also uses arrWindows1252() array, initalised above.

'Any text is selected:
If ChildForm(ID).rtfBox.SelLength <> 0 Then 'some text is selected:
    AnySelected = True 'raise flag
    strText = ChildForm(ID).rtfBox.SelText
    AnySelected = False 'lower flag
    strText = ChildForm(ID).rtfBox.Text
End If

'Run through all text in active file:
Do Until Completed 'for all characters:
    'Store current length of selected text:
    Length = Len(strText)
    'Entire string has been searched:
    If i >= Length Then 'entire text searched:
        Completed = True 'indicate replacement has finished
    End If
    'Store current character:
    Char = Mid$(strText, i, 1)
    'Current character is a printable ASCII character:
    Select Case Asc(Char) 'value of this character
        Case LBound(arrWindows1252) To UBound(arrWindows1252) 'ambigious characters from 128-159:
            'Replace character with corresponding array entry:
            strText = Mid$(strText, 1, i - 1) & arrWindows1252(Asc(Char)) _
                      & Mid$(strText, i + 1, Length - i)
        Case 0 To 8, 14 To 31, Is >= 159 'not a printable ASCII character:
            'Replace it with a decimal entity reference:
            strText = Mid$(strText, 1, i - 1) & "&#" & Asc(Char) & CHAR_SEMICOLON _
                      & Mid$(strText, i + 1, Length - i)
            'Note: String so far + Char (converted into a decimal entity reference) + rest of string.
            'Resume processing after the entity reference, which could be several digits long:
            i = i + Len(CStr("&#" & Asc(Char) & CHAR_SEMICOLON))
            'Function has replaced something:
            EscapeNonASCII = True 'raise flag being returned
            CStatus(ID).Saved = False 'file will be altered
        Case Else 'is a printable ASCII character:
            i = i + 1 'advance to next character
    End Select
'Note: Does not escape whitespace characters. Specifically:
'   Horizontal Tab (9)
'   Line Feed (10)
'   Vertical Tab (11)
'   Form Feed (12)
'   Carriage Return (13).

'any text is selected:
If AnySelected Then 'some text was selected:
    ChildForm(ID).rtfBox.SelText = strText 'output resulting string
    With ChildForm(ID).rtfBox
        'Select All:
        i = .SelStart
        Length = .SelLength
        .SelStart = 0
        .SelLength = Len(.Text)
        'Replacing a selection enables native Undo:
        .SelText = strText
        .SelStart = i
        .SelLength = Length
    End With
End If

End Function

Easter Holiday (25th April 2011)

Fiona found the Riding House Café blog, which shows the candid and charasmatic experience of the owner getting this new establishment built, furnished, equipped and ready for business. The first month was half price so we went and totally loved every aspect of it!

Good Friday

Waterlow Park hosted us for a sunny afternoon.

Headed back to our separate dwellings.


We wandered around the South Bank Festival. Spent some time in The Hayward Gallery, particular mesmerising display of photography of Afghanistan and the troops serving there.

Weather forecast said there would be a thunderstorm by 7pm. At about 6:30pm we felt the first spots of rain and soon after that, the first bolt of lightening! Took the Tube to Oxford Circus and walked towards mine from there, by which time the rain had stopped.

We dropped in at the Café to make a reservation for 7pm. That gave us time to get back to mine and dress for dinner. We were still probably the scuffiest people there, though! We were sat by the green cushion in the middle of that photo on their blog.


Fractured my wrist whilst playing football. Was playing cricket to start with. Bowling, batting and fielding. Remembered how to throw really far! Then relaxed on the grass with Fiona and a friend.

A football rolled over to us a couple of times from a nearby casual game. They had 4 players on one team and 3 on another, so invited me to join in.

I fell awkwardly near the start, slipping over in the trendy fabric plimsoles I’d gotten for the fashionable cyclist photoshoot. It felt weird right away but the pain didn’t hit me until a couple more falls and a couple of hours later, when I stopped playing and the adrenaline went away.

The swelling was also a clue by this stage!


Went to a GP and they referred me to a hospital. But the hospital’s X-ray unit was closed, as it was a Bank Holiday.

Went back and got the scan. They suspected a slight fracture in scaphoid. Couldn’t see it on the scan though. So they gave me a dark blue fabric splint with velcro to hold it steady.

About 10 days later they called me back and gave another diagonosis. This time they thought I should be in plaster, so a cool oriental man made a fibre-glass cast for me. He light-heartedly complained about having to treat 20 or so football injuries every week, yet hardly ever had boxers or rugby players.

Friday 27th May 2011

I got the cast removed last Friday.

Thursday 2nd June 2011

Wrist is a bit clunky and has less movement than my good wrist. But it’s getting towards full strength and every day it feels a bit better. Yay!

Plumbing Problems (19th April 2011)

Had a half-day on Monday afternoon for my dentist appointment. Found out at lunch that it was booked for the morning! So spent the afternoon with Fiona. A plumber was there when I arrived. He returned after 11pm due to a ‘water hammer’ noise. Spent all of the next morning sorting out valves, taps and pipes.

We went to some local parks after the plumber left. On the Tuesday we went to Finsbury Park, which is a reasonable walk and includes a dismantled railway line. We entered at a set of big fields and a fairground was set up further down. But we header the other way, a long way from the crowds.

Eventually an area of trees in full bloom, dappled shade and hardly any people welcomed us. Whilst playing frisbee a spaniel joined in, for the first time ever according to its owners! It didn’t understand the latter half of ‘fetch’ but clearly enjoyed the chasing and capturing of bright green flying discs.

Peak District (11th April 2011)

Drove from Fleet to Staffordshire to meet Fiona’s longest time friend and her husband. They had recently started a family and were enjoying life in a sunny and scenic rural village.

Several family members were staying in their spacious home. We went for walks, cycling, explored a hillside cave and had a barbeque. Oh, we also ended up watching So You Think You Can Dance but we aren’t going to tell anyone that.