Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-06-29
3
Medium Priority
?
717 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
[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
3 Comments
 
LVL 12

Accepted Solution

by:
wht1986 earned 150 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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.   …
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

609 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