?
Solved

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

Posted on 2009-06-29
3
Medium Priority
?
711 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 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