473,473 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Visual C to Visual Basic Converstion Help...

MRD
Hi All, I found a useful bit of code on msdn in VC but need it in VB.
I've started the conversion but can't quite finish. The code puts a
custom Icon on a toolbar (In my case the Word Add-in "Standard" bar.

I don't know how to handle the "resource manager" line especially the
"this.GetType()". What the heck is "This?" (and don't start the "who's
on first routine please :-)

Also, what is the reference for clipboard objects?

Also, I'm applying the tool to a command bar button, not a menu pop-up
but I'm assuming the code is analogous and I only have to switch types.

Thanks in advance,
Mark

=========
The original code
=========
private void AddSubButton(Office.CommandBarPopup cb, string buttonName)
{
try
{
object missing = Missing.Value;
Office.CommandBarButton customButton;
customButton = (Office.CommandBarButton) cb.Controls.Add(
Office.MsoControlType.msoControlButton,
missing, missing, missing, missing);
customButton.Style =
Office.MsoButtonStyle.msoButtonIconAndCaption;
ResourceManager rm = new ResourceManager(
"CustomFaces.IconResource", this.GetType().Assembly);
System.Drawing.Icon res;
res = (Icon) rm.GetObject(buttonName);
Bitmap bmp;
bmp=res.ToBitmap();
Clipboard.SetDataObject(bmp,true);
customButton.FaceId = 0;
customButton.Caption=buttonName;
customButton.PasteFace();
}
catch (Exception exc)
{
MessageBox.Show(exc.Message,"Adding Sub");
}

}

========
MY Interpretation in VB
========
Function AddSubButton(ByVal cb As CommandBarButton, ByVal buttonname As
String)

Dim missing As Object = missing.Value
Dim customButton As CommandBarButton
Dim bmp As Bitmap
Dim res As Icon
Dim rm As New ResourceManager("CustomFaces.IconResource",
rm.GetType().Assembly)
Try
customButton = cb.Controls.Add(MsoControlType.msoControlButton, _
missing, missing, missing, missing)
customButton.Style = MsoButtonStyle.msoButtonIconAndCaption
res = rm.GetObject(buttonname)
bmp = res.ToBitmap()
Clipboard.SetDataObject(bmp, True)
customButton.FaceId = 0
customButton.Caption = buttonname
customButton.PasteFace()
Catch
msgbox("Adding Button",MsgBoxStyle.OKOnly)
End Try
End Function

May 11 '06 #1
4 1558
I believe this in C# is equivalent to Me in VB.

May 11 '06 #2
Our Instant VB C# to VB converter produces the following: (Note that
MessageBox.Show is still fine in VB)

Private Sub AddSubButton(ByVal cb As Office.CommandBarPopup, ByVal
buttonName As String)
Try
Dim missing As Object = Missing.Value
Dim customButton As Office.CommandBarButton
customButton =
CType(cb.Controls.Add(Office.MsoControlType.msoCon trolButton, missing,
missing, missing, missing), Office.CommandBarButton)
customButton.Style = Office.MsoButtonStyle.msoButtonIconAndCaption
Dim rm As ResourceManager = New
ResourceManager("CustomFaces.IconResource", Me.GetType().Assembly)
Dim res As System.Drawing.Icon
res = CType(rm.GetObject(buttonName), Icon)
Dim bmp As Bitmap
bmp=res.ToBitmap()
Clipboard.SetDataObject(bmp,True)
customButton.FaceId = 0
customButton.Caption=buttonName
customButton.PasteFace()
Catch exc As Exception
MessageBox.Show(exc.Message,"Adding Sub")
End Try

End Sub

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter

"MRD" wrote:
Hi All, I found a useful bit of code on msdn in VC but need it in VB.
I've started the conversion but can't quite finish. The code puts a
custom Icon on a toolbar (In my case the Word Add-in "Standard" bar.

I don't know how to handle the "resource manager" line especially the
"this.GetType()". What the heck is "This?" (and don't start the "who's
on first routine please :-)

Also, what is the reference for clipboard objects?

Also, I'm applying the tool to a command bar button, not a menu pop-up
but I'm assuming the code is analogous and I only have to switch types.

Thanks in advance,
Mark

=========
The original code
=========
private void AddSubButton(Office.CommandBarPopup cb, string buttonName)
{
try
{
object missing = Missing.Value;
Office.CommandBarButton customButton;
customButton = (Office.CommandBarButton) cb.Controls.Add(
Office.MsoControlType.msoControlButton,
missing, missing, missing, missing);
customButton.Style =
Office.MsoButtonStyle.msoButtonIconAndCaption;
ResourceManager rm = new ResourceManager(
"CustomFaces.IconResource", this.GetType().Assembly);
System.Drawing.Icon res;
res = (Icon) rm.GetObject(buttonName);
Bitmap bmp;
bmp=res.ToBitmap();
Clipboard.SetDataObject(bmp,true);
customButton.FaceId = 0;
customButton.Caption=buttonName;
customButton.PasteFace();
}
catch (Exception exc)
{
MessageBox.Show(exc.Message,"Adding Sub");
}

}

========
MY Interpretation in VB
========
Function AddSubButton(ByVal cb As CommandBarButton, ByVal buttonname As
String)

Dim missing As Object = missing.Value
Dim customButton As CommandBarButton
Dim bmp As Bitmap
Dim res As Icon
Dim rm As New ResourceManager("CustomFaces.IconResource",
rm.GetType().Assembly)
Try
customButton = cb.Controls.Add(MsoControlType.msoControlButton, _
missing, missing, missing, missing)
customButton.Style = MsoButtonStyle.msoButtonIconAndCaption
res = rm.GetObject(buttonname)
bmp = res.ToBitmap()
Clipboard.SetDataObject(bmp, True)
customButton.FaceId = 0
customButton.Caption = buttonname
customButton.PasteFace()
Catch
msgbox("Adding Button",MsgBoxStyle.OKOnly)
End Try
End Function

May 11 '06 #3
The "this" keyword in C# referes to "this" instance of the object

this.GetType() returns the System.Type of the current object.

It is the same as the "Me" keyword in VB.NET.

Me.GetType() returns the System.Type of the current object.

"MRD" wrote:
Hi All, I found a useful bit of code on msdn in VC but need it in VB.
I've started the conversion but can't quite finish. The code puts a
custom Icon on a toolbar (In my case the Word Add-in "Standard" bar.

I don't know how to handle the "resource manager" line especially the
"this.GetType()". What the heck is "This?" (and don't start the "who's
on first routine please :-)

Also, what is the reference for clipboard objects?

Also, I'm applying the tool to a command bar button, not a menu pop-up
but I'm assuming the code is analogous and I only have to switch types.

Thanks in advance,
Mark

=========
The original code
=========
private void AddSubButton(Office.CommandBarPopup cb, string buttonName)
{
try
{
object missing = Missing.Value;
Office.CommandBarButton customButton;
customButton = (Office.CommandBarButton) cb.Controls.Add(
Office.MsoControlType.msoControlButton,
missing, missing, missing, missing);
customButton.Style =
Office.MsoButtonStyle.msoButtonIconAndCaption;
ResourceManager rm = new ResourceManager(
"CustomFaces.IconResource", this.GetType().Assembly);
System.Drawing.Icon res;
res = (Icon) rm.GetObject(buttonName);
Bitmap bmp;
bmp=res.ToBitmap();
Clipboard.SetDataObject(bmp,true);
customButton.FaceId = 0;
customButton.Caption=buttonName;
customButton.PasteFace();
}
catch (Exception exc)
{
MessageBox.Show(exc.Message,"Adding Sub");
}

}

========
MY Interpretation in VB
========
Function AddSubButton(ByVal cb As CommandBarButton, ByVal buttonname As
String)

Dim missing As Object = missing.Value
Dim customButton As CommandBarButton
Dim bmp As Bitmap
Dim res As Icon
Dim rm As New ResourceManager("CustomFaces.IconResource",
rm.GetType().Assembly)
Try
customButton = cb.Controls.Add(MsoControlType.msoControlButton, _
missing, missing, missing, missing)
customButton.Style = MsoButtonStyle.msoButtonIconAndCaption
res = rm.GetObject(buttonname)
bmp = res.ToBitmap()
Clipboard.SetDataObject(bmp, True)
customButton.FaceId = 0
customButton.Caption = buttonname
customButton.PasteFace()
Catch
msgbox("Adding Button",MsgBoxStyle.OKOnly)
End Try
End Function

May 12 '06 #4
MRD
Thanks all. I've got the conversion all set - I think - now I can't
debug... *sigh*

May 12 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AK | last post by:
I don't want any part of the previous discussion on Visual Basic versus Visual Basic.Net. My query is about using Visual Basic for Applications; and whether it is better to use Visual Basic 6 or...
2
by: Anil Sahai | last post by:
I installed Visual Studio Version 6.0 with Visual Basic and Visual C++ etc. When I tried to invoke Help in Visual BASIC, it said that I should install MSDN. I installed MSDN using the MSDN library...
2
by: janice_2k | last post by:
Dear Sir/Mdm, I am writing this on behalf of my company. We bought the Visual Studio .NET Enterprise version but currently we need to use Visual Basic 6 for a small development. We are not able to...
2
by: Ralph | last post by:
I used to have Visual Basic .net std. 2003 installed on WinXP SP1A. But I found it too hard to upgrade WinXP to SP2. Now, I do have WinXP SP2 installed, but I am having problems installing...
2
by: frossberg | last post by:
Hello! I tried to install the Visual Basic.NET Resource Kit (http://msdn.microsoft.com/vbasic/vbrkit/) but obviously something went very wrong and now it sems impossible both to repair and to...
5
by: Microsoft | last post by:
Hi, I have Visual Basic .net 2003 (Standard Edition) & SQL Server 2000 Developer Edition. When trying to create a connection in the server explorer from the .net IDE I get a number of problems;...
97
by: Master Programmer | last post by:
An friend insider told me that VB is to be killled off within 18 months. I guess this makes sence now that C# is here. I believe it and am actualy surprised they ever even included it in VS 2003 in...
1
by: FlyingBuckner | last post by:
All right be kind, this is my first question on a forum. I need help on selecting the right software to purchase. I have a database set up using Access, 6 users. It is split into Tables and...
6
by: Salman | last post by:
I would like to know how I can distribute the application that I create with Visual C++ express edition. I checked the menu options to find a deploy option similar to the one found on the Visual...
4
by: Chris Asaipillai | last post by:
Hi there My compay has a number of Visual Basic 6 applications which are front endeed onto either SQL Server or Microsoft Access databases. Now we are in process of planning to re-write these...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.