patternMinor
Converting Hindi Devanagari proprietary font to Unicode font
Viewed 0 times
hindiproprietaryunicodefontconvertingdevanagari
Problem
This working macro converts Hindi Devanagari proprietary font to Unicode font. It reads the conversion table from a tab delimited file, and converts one by one by finding all matches and then does some ligature shifting.
I don't know how efficient it is and how much time and resources it uses. Feel free to tell me if something like "bad coding style" comes to your notice, and alternative method of doing this.
Header
I'm using Windows8-32 bit, MS Office 2010, Word.
```
#If VBA7 Then
Public Declare PtrSafe Function MessageBoxU Lib "user32" Alias "MessageBoxW" _
(ByVal hwnd As LongPtr, _
ByVal lpText As LongPtr, _
ByVal lpCaption As LongPtr, _
ByVal wType As Long) As Long
'Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, _
Source As Any, _
ByVal Length As LongPtr)
'Private Declare PtrSafe Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, _
Source As Any, _
ByVal Length As Long)
#Else
Public Declare Function MessageBoxU Lib "user32" Alias "MessageBoxW" _
(ByVal hwnd As Long, _
ByVal lpText As Long, _
ByVal lpCaption As Long, _
ByVal wType As Long) As Long
'Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, _
Source As
I don't know how efficient it is and how much time and resources it uses. Feel free to tell me if something like "bad coding style" comes to your notice, and alternative method of doing this.
Header
#def part is not much used in this final macro, but used in debugging, so I retained it here. You can't run it without the conversion table file and without the text in the said font. I'm using Windows8-32 bit, MS Office 2010, Word.
```
#If VBA7 Then
Public Declare PtrSafe Function MessageBoxU Lib "user32" Alias "MessageBoxW" _
(ByVal hwnd As LongPtr, _
ByVal lpText As LongPtr, _
ByVal lpCaption As LongPtr, _
ByVal wType As Long) As Long
'Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, _
Source As Any, _
ByVal Length As LongPtr)
'Private Declare PtrSafe Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, _
Source As Any, _
ByVal Length As Long)
#Else
Public Declare Function MessageBoxU Lib "user32" Alias "MessageBoxW" _
(ByVal hwnd As Long, _
ByVal lpText As Long, _
ByVal lpCaption As Long, _
ByVal wType As Long) As Long
'Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, _
Source As
Solution
It's not clear why you would need to p/invoke the native
Remove all the dead/commented-out code if you're not using it - otherwise is obscures the intent of the code.
As far as I know,
What happens when you make a minor change to that procedure, you increment the minor version digit and update all call sites accordingly? That's ...madness!
A good reason to refactor/rename would be to make the procedure's name start with a verb:
This looks confusing:
Why would one be a constant and the other a variable? Avoid numeric suffixes in identifiers, they quickly make a maintenance nightmare.
Where's
You're not consistently using Hungarian notation, some of the prefixes you use seem completely arbitrary and meaningless. I like
The code could use some vertical whitespace between procedures and functions, it would feel less monolithic.
Functions
VBA has too many loop constructs;
MessageBoxU function, given you're not using it anywhere, correctly preferring the language's own MsgBox wrapper.Remove all the dead/commented-out code if you're not using it - otherwise is obscures the intent of the code.
As far as I know,
Universal_Converter_v1.0 is only a valid VBA identifier if you surround it with [SquareBrackets], because the dot is a special character that cannot legally be part of an identifier. Version numbers don't belong in names either, and Upper_Snake_Case looks very strange when everything in the language's standard libraries is in PascalCase.What happens when you make a minor change to that procedure, you increment the minor version digit and update all call sites accordingly? That's ...madness!
A good reason to refactor/rename would be to make the procedure's name start with a verb:
UniversalConverter looks more like a name for a class than one for a procedure; keep nouns for types, and use verbs for procedures.This looks confusing:
Dim arrIndexMax As Integer
Const arrIndexMax1 = 1024Why would one be a constant and the other a variable? Avoid numeric suffixes in identifiers, they quickly make a maintenance nightmare.
Where's
Option Explicit? Looks like you're using variables that aren't declared anywhere - that's another maintenance nightmare waiting to happen.You're not consistently using Hungarian notation, some of the prefixes you use seem completely arbitrary and meaningless. I like
lenXxx for a variable that's holding the length of a string because it tells the reader what the variable is used for, but strXxx and oRange (boy that one is funny! Say it 3 times out loud if you're not sure why!) have prefixes that stand for a type, and that's wrong.The code could use some vertical whitespace between procedures and functions, it would feel less monolithic.
Functions
Mid, Str, Chr, ChrW, Left and Right return a Variant, which incurs an implicit type conversion. Use the "stringly-typed" Mid$, Str$, Chr$, ChrW$, Left$ and Right$ versions instead, which return an actual String. It's not clear why you're only sometimes using them.VBA has too many loop constructs;
Do While...Loop is there only to please the fans of Do...Loop - a more succinct construct would be While...Wend.Code Snippets
Dim arrIndexMax As Integer
Const arrIndexMax1 = 1024Context
StackExchange Code Review Q#115718, answer score: 3
Revisions (0)
No revisions yet.