Solved

Convert VBC code to C#

Posted on 2013-02-04
4
220 Views
Last Modified: 2013-03-04
Hi
I have a small section of VBA code which I need to convert/rewrite in C#.
Basically the code specifies the count, name and location of images which are to be used in a gallery on a custom Excel Ribbon:

Sub getBSCGalleryItemImages(control As IRibbonControl, index As Integer, ByRef image)
    Set image = LoadPicture("//images/report_snapshot_" & index + 1 & ".jpg")
End Sub
Sub getBSCGalleryItemCount(control As IRibbonControl, ByRef count)
        count = 3
End Sub

Open in new window


Thanks for the help

Fergal
0
Comment
Question by:fjkilken
  • 2
  • 2
4 Comments
 
LVL 25

Expert Comment

by:SStory
ID: 38855182
It would be something like the following:
void getBSCGalleryItemImages(IRibbonControl control,int Index, ref image) {

    image = LoadPicture("//images/report_snapshot_" + int.parse(index + 1) + ".jpg");

}

void getBSCGalleryItemCount(IRibbonControl control, ref count) {

        count = 3;

}

Open in new window


Per your code I didn't know what type variable count was or Image, so those may have to be added.
0
 

Author Comment

by:fjkilken
ID: 38856096
doesn't look like that will work - "LoadPicture" method is not recognised
0
 
LVL 25

Accepted Solution

by:
SStory earned 500 total points
ID: 38856194
OK.
You will need a

using System.Drawing;

at the top of the module in C#


String path="//images/report_snapshot_" + int.parse(index + 1) + ".jpg";
Image image1 = Image.FromFile(path);

Image.FromFile()
can load an image from a file.
0
 

Author Comment

by:fjkilken
ID: 38856245
thanks,
let me take a look at incorporating that tomorrow
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

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

920 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

13 Experts available now in Live!

Get 1:1 Help Now