c#-to-vb.net

.NET Serial Port Woes. Converting C# Code to VB

◇◆丶佛笑我妖孽 提交于 2019-12-11 08:08:41
问题 I'm having trouble with the SerialPort function intermittently crashing while data logging for several days. It's been a hard problem to debug and I would like to try Zach Saw's fix which he talks about here and provides code for in C# My question is, to do this, do I need to rewrite the entire use of the Serial Port in my code? If I use the System.IO.Ports.SerialPort module, is there a way to just do a DLLImport of SetCommState to set fAbortOnError to false, or do I need to abandon the

how to group by over anonymous type with vb.net linq to object

风流意气都作罢 提交于 2019-12-11 04:54:00
问题 I'm trying to write a linq to object query in vb.net, here is the c# version of what I'm trying to achieve (I'm running this in linqpad): void Main() { var items = GetArray( new {a="a",b="a",c=1} , new {a="a",b="a",c=2} , new {a="a",b="b",c=1} ); ( from i in items group i by new {i.a, i.b} into g let p = new{ k = g, v = g.Sum((i)=>i.c)} where p.v > 1 select p ).Dump(); } // because vb.net doesn't support anonymous type array initializer, it will ease the translation T[] GetArray<T>(params T[]

exchange code for token facebook-c#-sdk

流过昼夜 提交于 2019-12-10 20:56:49
问题 I am using The Facebook-C#-Sdk v5.0.3 to create a non-canvas webforms app in vb.net and i am having trouble exchanging the returned facebook code for the access_token. Does anyone have an example (C# or vb.net) that I can look at? Thanks awesome Stackoverflow community! 回答1: Try this: var app = new FacebookClient(FacebookContext.Current.AppId, FacebookContext.Current.AppSecret); var accessToken = app.AccessToken or this: var app = new FacebookClient(new Authorizer().Session.AccessToken); var

Overriding Events in VB

我只是一个虾纸丫 提交于 2019-12-10 17:16:01
问题 Is there a way to translate this code in VB? Most of it is easy, but I can't figure out a way to override the event handler. public class MTObservableCollection<T> : ObservableCollection<T> { public MTObservableCollection() { _DispatcherPriority = DispatcherPriority.DataBind; } public MTObservableCollection(DispatcherPriority dispatcherPriority) { _DispatcherPriority = dispatcherPriority; } private DispatcherPriority _DispatcherPriority; public override event

Why use System.Threading.Interlocked.Decrement instead of minus?

百般思念 提交于 2019-12-10 13:03:21
问题 I converted some c# code to vb.net and the converter.telerik.com turned this: i--; into this: System.Math.Max(System.Threading.Interlocked.Decrement(i), i + 1) Whats up with all the fancy-ness? 回答1: Michał Piaskowski's comment triggered the following explanation: The semantics of i-- in C# are to return the current value of i (i.e., the value before the decrement occurs) and then decrement i by one. So, we need to convert that to VB. We can not use i -= 1 because this does not return the

Protected Set in VB.Net for a property defined in an interface

三世轮回 提交于 2019-12-10 05:16:53
问题 We have an interface, which can be grossly simplified as: public interface IPersistable<T> { T Id { get; } } Most places that implement the interface want to have it so that there is a protected or private set on that property, i.e, in C#: public class Foo : IPersistable<int> { public int Id { get; protected set; } } However, I can't get any sample VB.Net code to compile that follows the same pattern, whilst still implementing the interface, so: Public Class Foo Implements IPersistable(Of

VB.NET equivalent to C#'s using directive

独自空忆成欢 提交于 2019-12-08 17:33:50
问题 I am converting some code from C# to VB.NET, and I need to know what the equivalent is for C#'s using directive. Update: Sorry, but so far I haven't gotten my answer. Here is a C# example: using moOutlook = Microsoft.Office.Interop.Outlook; using moExcel = Microsoft.Office.Interop.Excel; namespace ReportGen { class Reports 回答1: You're looking for the Imports statement. Place any import statements that you need at the very top of your code file, just like the using directive in C#: Imports

parser to convert .net dictionary or list to VBA's equivalent dictionary or collection

安稳与你 提交于 2019-12-08 04:32:31
问题 i have to pass the .net dictionary or list type of object to VBA. but when i am passing the .net dictionary at VBA side i am not able to see the elements of dictionary on .net side. My code in C# Dictionary<string,object> dict = new Dictionary<string,object>(); dict.Add("First", "1"); dict.Add("Second", "2"); dict.Add("third", "3"); dict.Add("Forth", "4"); i am calling the VBA macro from C# as Application.Run("MyVBAMacro", dict); in VBA side My Macro is public Sub MyVBAMacro(var as variant)

CInt does not round Double value consistently - how can I remove the fractional part?

徘徊边缘 提交于 2019-12-06 21:12:33
问题 I've stumbled upon an issue with CInt and converting a double to an integer. The issue is the following: CInt(10.5) 'Result is 10 CInt(10.51) 'Result it 11, but I expected 10... I got used to C# style conversion where (int) 10.51 is 10. As pointed out in the question about Integer.Parse vs CInt, the result is just rounded in some fashion. However, all I need is to get only integer part and throw away the fractional one. How can I achieve such type of conversion in VB.NET? After some research

Multiassignment in VB like in C-Style languages

依然范特西╮ 提交于 2019-12-06 18:50:51
问题 Is there a way to perform this in VB.NET like in the C-Style languages: struct Thickness { double _Left; double _Right; double _Top; double _Bottom; public Thickness(double uniformLength) { this._Left = this._Right = this._Top = this._Bottom = uniformLength; } } 回答1: Expanding on Mark's correct answer This type of assignment style is not possible in VB.Net. The C# version of the code works because in C# assignment is an expression which produces a value. This is why it can be chained in this