Solved

New Bitmap (Filename as String)  - Why is this not a string?

Posted on 2009-06-29
3
703 Views
Last Modified: 2012-08-14
I'm writing my first shared com add-in for excel in VB.Net and my experience is primarily with VBA so I'm learning.   The add-in adds a ribbon, the ribbon has a bunch of custom png images used for button images.  

Why does Return New Bitmap(My.Resources.AcctgUline16) return a bitmap

and

Dim sImage as String = "My.Resources." & control.id & "16"
Return  New Bitmap(sImage)

does not?

From VS 2008 the Intellisense says Bitmap(filename as string)
Working Code:

   Public Function GetImage(ByVal control As Office.IRibbonControl) As Bitmap

        'control.id = AcctgUline

        Return New Bitmap(My.Resources.AcctgUline16)

    End Function
 
 

Does not work:

    Public Function GetImage(ByVal control As Office.IRibbonControl) As Bitmap

        'control.id = AcctgUline

        Dim sImage As String = "My.Resources." & control.Id & "16"

        'sImage = My.Resources.AcctgUline16

        Return New Bitmap(sImage)

    End Function

Open in new window

0
Comment
Question by:slindberg
3 Comments
 
LVL 12

Accepted Solution

by:
wht1986 earned 50 total points
ID: 24741135
Bitmap has an overloaded constructor, one of which accepts a parameter of a bitmap and another a string to a file on the filesystem

when you use My.Resources.AcctgUline16, you are actually supplying a bitmap

using the string  "My.Resources." & control.id & "16"
the code is attempting to find a file named "My.Resources.AcctgUline16" on the file system
0
 
LVL 39

Expert Comment

by:abel
ID: 24741140
For 50p? Must be easy....

Microsoft Intellisense also says "Image original", which is your first line. The second example, with sImage does not because you do not give the path to the image. Instead, you give a string representing a line in your code, which doesn't mean anything to the constructor. Give it a path, like Bitmap("c:/temp/myimage.jpg") for instance.
0
 

Author Comment

by:slindberg
ID: 24741204
After your post and finding the post below I modified my code and it works.  Thanks

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_21774267.html?sfQueryTermInfo=1+resourc+variabl+vb.net#a16192685

    Public Function GetImage(ByVal control As Office.IRibbonControl) As Bitmap

        Dim resMan As New ResourceManager("mpmRibbons.Resources", Me.GetType.Assembly)

        Dim sImage As String = control.Id & "16"
 

        Return New Bitmap(CType(resMan.GetObject(sImage), System.Drawing.Image))
 

    End Function

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now