Solved

CreateObject("Some.Application")

Posted on 2014-01-13
5
252 Views
Last Modified: 2014-01-29
What is the equivalent code of CreateObject in C# ?

Dim obj as Object
obj = CreateObject("Some.Application")
0
Comment
Question by:VBdotnet2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 19

Expert Comment

by:Ken Butters
ID: 39777918
The equivalent would be to import the correct reference library, and then a line of code something like this:

someapplicationLib.someapplicationClass = new someapplicationLib.someapplicationClass();
0
 

Author Comment

by:VBdotnet2005
ID: 39777929
I want to convert this to C#.  Link
Public Sub resizeimG(ByVal Source As String)
        Dim jpeg
        jpeg = CreateObject("Persits.Jpeg")
        If Path.GetExtension(sourcefile) = ".jpg" Then
            Dim fn As New FileInfo(sourcefile)
            If fn.Length > 75000 Then
                jpeg.Open(sourcefile)
                If jpeg.width > 600 Then
                    jpeg.PreserveAspectRatio = True
                    jpeg.Width = 600
                    jpeg.Save(sourcefile)
                    jpeg = Nothing
                End If
            End If
        End If
    End Sub
0
 
LVL 40
ID: 39777998
Unfortunately, I do not have the time to translate the code, but I can give you a fast rundown.

Do not use CreateObject or any equivalent, because it uses an external software and is dependent on the file extensions associations on the computer on which it is run. The software that will be launched will be different from one computer to another, and you cannot assume that it will have a PreserveAspectRatio property for instance. On my computer, it would launch Paint Shop Pro, that does not have the behavior expected from the code.

the FileInfo part is OK, it gives information about the file size.

For everything else, use a Bitmap object to get the size and an resize the image, using the information given at http://tech.pro/tutorial/620/csharp-tutorial-image-editing-saving-cropping-and-resizing
0
 
LVL 19

Accepted Solution

by:
Ken Butters earned 500 total points
ID: 39779396
Looks to me like what you want to use here is the image class. (System.Drawing.Image)

What your routine looks like it is doing is reading JPG files and resizing them to a max of 600.

Here is a reference for image class:

http://msdn.microsoft.com/en-us/library/System.Drawing.Image_methods(v=vs.110).aspx


Something like this should do the trick.

(Note... I did not test this...this is just to use as a guide.)

Image newImage = Image.FromFile("SampImag.jpg");

if (image.width > 600) {
   resizePct = 600 / (float) image.width;
   image.width = 600;
   image.height = image.height * resizePct;
}
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39806683
If you still have that COM component installed on your machine then you can continue to use CreateObject in VB.NET.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question