Click here to Skip to main content
14,085,361 members
Rate this:
 
Please Sign up or sign in to 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web05 | 2.8.190518.1 | Last Updated 13 Dec 2017
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100