Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Does anybody can help me to convert this tiny line of C Code to VB ?
this code was from :
Screen Brightness Control for Laptops and Tablets[^]

What I have tried:

Original Code in C:
//Form1_Shown:
if (Array.FindIndex(arguments, item => item.Contains("%") ) > -1)

//startup_brightness:
string sPercent = arguments[Array.FindIndex(arguments, item => item.Contains("%"))];


And these is my attempt to convert to VB:
//Form1_Shown: 
If Array.FindIndex(arguments, (Function(item) item.Contains("%"))) > -1 Then

//startup_brightness:
Dim sPercent As String = arguments(Array.FindIndex(arguments, Function(item) item.Contains("%")))


And my attempt just returning an error :
System.ArgumentNullException: 'Value cannot be null.'


Any help would be Wonderful! :)

Cheers,
Joe
Posted
Updated 13-Dec-17 5:19am
v3
Comments
F-ES Sitecore 12-Dec-17 14:06pm    
The problem is the data\variables you're using, not the code. You need to use the debugger to find out what is evaluating to null.
InfinityJoe 13-Dec-17 11:20am    
Hi Mate, thanks for your advice, really appreciate it! :)

Cheers,
Joe
Dave Kreskowiak 12-Dec-17 15:51pm    
That's not C, that's C# code. You can use any of the online conversion tools to convert between C# and VB.NET. Just Google for "Convert C# to VB.NET" to find them.
InfinityJoe 13-Dec-17 11:27am    
Hi Mate, thanks for your advice, really appreciate it!, and yes forgot to put "#" on the title last time, but actually i've already added C# for this thread tagline at beginning, btw just fix the title today :)

Cheers,
Joe
Richard Deeming 13-Dec-17 10:47am    
The code you're starting from is flawed - it should cache the value returned from FindIndex, rather than calling the method twice.

int index = Array.FindIndex(arguments, item => item.Contains("%"));
if (index >= 0)
{
    string sPercent = arguments[index];
    ...
}


The ArgumentNullException would suggest that the arguments array has not been initialized.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900