467,076 Members | 997 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,076 developers. It's quick & easy.

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
  • viewed: 1410
Share:
4 Replies
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Anil Sahai | last post: by
2 posts views Thread by janice_2k | last post: by
2 posts views Thread by frossberg | last post: by
97 posts views Thread by Master Programmer | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.