K
Keith G Hicks
I created a dll in vb.net to calclulate the height of a block fo text as
follows:
Imports System.Drawing
Imports System.Math
Public Class DlnpFntCalcs
Public Function GetTextHeight(ByVal sNoticeText As String, ByVal
sFontName As String, ByVal dFontSize As Double, ByVal dClipWidth As Double)
As Double
Dim gr As Graphics = Graphics.FromHwnd(IntPtr.Zero)
Dim dFactor As Double = gr.DpiX / 100 '0.96 '0.96
'Pixel/HundredsOfInch
Dim fnt As New Font(sFontName, dFontSize, FontStyle.Regular,
GraphicsUnit.Point)
Dim size As SizeF = gr.MeasureString(sNoticeText, fnt, dClipWidth *
dFactor, StringFormat.GenericTypographic)
Return Round((size.Height / dFactor) / 100, 2)
End Function
End Class
I'm not registering it. It's currently being called by a vb.net exe I also
created and everything runs fine so far.
However, I also need to call the above function from an ms access routine.
From hunting around online I know that I need to do something with com. All
of this is very very new to me. I am not familiar with much of this area of
programming. I found this:
http://dsmyth.blogspot.com/2006/03/calling-managed-code-from-vba-using.html
which was a little helpful but a lot of the terminology is new to me and the
examples are very vague. I found a couple other things that helped me out a
bit but I still feel pretty far from the goal. I have no idea what to do to
the above to be able to call it from vba. I should mention that I would
rather not have to register the dll. I'm not doign that now for the current
setup and it's just fine. I don't have much say in this part of it. I'm ok
with hard coding the dll's path in the vba code.
Any help would be greatly apprciated.
Thanks,
Keith
follows:
Imports System.Drawing
Imports System.Math
Public Class DlnpFntCalcs
Public Function GetTextHeight(ByVal sNoticeText As String, ByVal
sFontName As String, ByVal dFontSize As Double, ByVal dClipWidth As Double)
As Double
Dim gr As Graphics = Graphics.FromHwnd(IntPtr.Zero)
Dim dFactor As Double = gr.DpiX / 100 '0.96 '0.96
'Pixel/HundredsOfInch
Dim fnt As New Font(sFontName, dFontSize, FontStyle.Regular,
GraphicsUnit.Point)
Dim size As SizeF = gr.MeasureString(sNoticeText, fnt, dClipWidth *
dFactor, StringFormat.GenericTypographic)
Return Round((size.Height / dFactor) / 100, 2)
End Function
End Class
I'm not registering it. It's currently being called by a vb.net exe I also
created and everything runs fine so far.
However, I also need to call the above function from an ms access routine.
From hunting around online I know that I need to do something with com. All
of this is very very new to me. I am not familiar with much of this area of
programming. I found this:
http://dsmyth.blogspot.com/2006/03/calling-managed-code-from-vba-using.html
which was a little helpful but a lot of the terminology is new to me and the
examples are very vague. I found a couple other things that helped me out a
bit but I still feel pretty far from the goal. I have no idea what to do to
the above to be able to call it from vba. I should mention that I would
rather not have to register the dll. I'm not doign that now for the current
setup and it's just fine. I don't have much say in this part of it. I'm ok
with hard coding the dll's path in the vba code.
Any help would be greatly apprciated.
Thanks,
Keith