Albert D. Kallal
Registered User.
- Local time
- Today, 10:25
- Joined
- Jun 11, 2009
- Messages
- 25
Ok, so let's put all the steps together as to what you need for this to work.
First up, you need the code module (and 2 .dll's) from the sample PDF merge utility I posted here.
Assuming you have the above?
Ok, then let's from scratch create a .net .dll for use from VBA.
As noted, the .net world has near un-limited features, and often such features are built into .net.
And when they are not? Well, there is a gazillion NuGet libaries you can add to .net.
(this is how the PDF merge sample was made - I used iTextSharp - a common well known PDF library for .net).
Ok, so, let's do somthing simple. We will in an Access form, display a image. Then use .net to rotate the image.
In fact, you can Google, or even GPT how to do this in vb.net.
The .net code looks like this to rotate a given image (file).
So, really, just a few lines of vb.net.
So, now let's create a .net .dll for use from Access.
So, assuming one has Visual Studio installed (the free community edition works just fine for this.
So, the first step is to create a new project in VS. We want to create a SUPER simple project, and the correct program is to create a .net class project.
Perhaps only trick is to make sure you choose/create the correct kind of project. One "challenge" in .net is that over the years, .net has become the ultimate Swiss army knife - and there are BOATLOADS of projects too choose from. This is what happens when a company keeps throwing money at a particular platform - it just grows and grows!!! It would be un-kind of me to state that VS now has too many project types, ranging from web, to desktop to Android development, and much more!!!
So, we need to choose + create a .net framework (not .net standard, or what was/is called .net core).
So, in create new project, choose this project type:
Ok, so now we have this:
And then we now have this:
(but, let' right click on the class, and rename it, like this:
Now, add a reference to System.Drawring to use the image stuff in .net.
Hence this:
Ok, so let's add a simple method (sub) to this code, based on that vb.net code to rotate that image.
So, our class becomes this:
So, you can adopt the above cookie cutter design over and over.
You need to add (as per above), the following:
Imports System.Runtime.InteropServices
And this just before the class:
<ClassInterface(ClassInterfaceType.AutoDual)>
And only one more step, and we have our .net dll.
In the project settings, under assembly, check the box "Make assembly COM-Visible"
this one:
If you build this project, and want to use regasm? Then I suggest you force the project to x86, or x64 if using x64 bit Access/office.
However, as noted, with our .net loader, we don't need (nor care) to use regasm.
So, I'll reply a bit later as to what the VBA code looks like, but really, after anyone done the above, you are now on the road to freely building .dll'ss for use with Access. And EVEN if you don't want to use my .net loader, the above will work just fine using regasm.exe, and setting a reference from VBA .....
R
Albert
First up, you need the code module (and 2 .dll's) from the sample PDF merge utility I posted here.
Assuming you have the above?
Ok, then let's from scratch create a .net .dll for use from VBA.
As noted, the .net world has near un-limited features, and often such features are built into .net.
And when they are not? Well, there is a gazillion NuGet libaries you can add to .net.
(this is how the PDF merge sample was made - I used iTextSharp - a common well known PDF library for .net).
Ok, so, let's do somthing simple. We will in an Access form, display a image. Then use .net to rotate the image.
In fact, you can Google, or even GPT how to do this in vb.net.
The .net code looks like this to rotate a given image (file).
Code:
' Load the image from file
Dim imagePath As String = "C:\path\to\your\image.jpg"
Dim img As Image = Image.FromFile(imagePath)
' Rotate the image 90 degrees clockwise
img.RotateFlip(RotateFlipType.Rotate90FlipNone)
' Save the rotated image to a new file
Dim outputPath As String = "C:\path\to\your\rotated_image.jpg"
img.Save(outputPath, ImageFormat.Jpeg)
' Clean up
img.Dispose()
So, really, just a few lines of vb.net.
So, now let's create a .net .dll for use from Access.
So, assuming one has Visual Studio installed (the free community edition works just fine for this.
So, the first step is to create a new project in VS. We want to create a SUPER simple project, and the correct program is to create a .net class project.
Perhaps only trick is to make sure you choose/create the correct kind of project. One "challenge" in .net is that over the years, .net has become the ultimate Swiss army knife - and there are BOATLOADS of projects too choose from. This is what happens when a company keeps throwing money at a particular platform - it just grows and grows!!! It would be un-kind of me to state that VS now has too many project types, ranging from web, to desktop to Android development, and much more!!!
So, we need to choose + create a .net framework (not .net standard, or what was/is called .net core).
So, in create new project, choose this project type:
Ok, so now we have this:
And then we now have this:
(but, let' right click on the class, and rename it, like this:
Now, add a reference to System.Drawring to use the image stuff in .net.
Hence this:
Ok, so let's add a simple method (sub) to this code, based on that vb.net code to rotate that image.
So, our class becomes this:
Code:
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Runtime.InteropServices
<ClassInterface(ClassInterfaceType.AutoDual)>
Public Class clsRotate
Public Sub RotatePic(imagePath As String, intRoate As Integer)
' Load the image from file
Dim img As Image = Image.FromFile(imagePath)
' Rotate the image 90 degrees clockwise
Select Case intRoate
Case 1
img.RotateFlip(RotateFlipType.Rotate90FlipNone)
Case 2
img.RotateFlip(RotateFlipType.Rotate180FlipNone)
Case 3
img.RotateFlip(RotateFlipType.Rotate270FlipNone)
End Select
' Save the rotated image
img.Save(imagePath, ImageFormat.Jpeg)
' Clean up
img.Dispose()
End Sub
End Class
So, you can adopt the above cookie cutter design over and over.
You need to add (as per above), the following:
Imports System.Runtime.InteropServices
And this just before the class:
<ClassInterface(ClassInterfaceType.AutoDual)>
And only one more step, and we have our .net dll.
In the project settings, under assembly, check the box "Make assembly COM-Visible"
this one:
If you build this project, and want to use regasm? Then I suggest you force the project to x86, or x64 if using x64 bit Access/office.
However, as noted, with our .net loader, we don't need (nor care) to use regasm.
So, I'll reply a bit later as to what the VBA code looks like, but really, after anyone done the above, you are now on the road to freely building .dll'ss for use with Access. And EVEN if you don't want to use my .net loader, the above will work just fine using regasm.exe, and setting a reference from VBA .....
R
Albert