Questions to convoke VB6 functions for PHP

1

I need to pass some VB6 code to PHP, but I have a question about what this code does:

Private Function SomarValor(v As String) As Double
Dim x As Byte, resultado As Double
For x = 1 To Len(v)
resultado = resultado + CDbl(Mid(v, x, 1))
Next
SomarValor = resultado
End Function

This function SomarValor() receives values as 0202827610 , if anyone can help.

I have tried to look for the meaning of these internal functions as CDbl , Mid , but I could not understand.

    
asked by anonymous 16.06.2016 / 19:27

1 answer

3

The code receives a string 0202827610 is made a for that extracts a character from this string as mid () and has its value converted to double with CDbl () that finally adds the value.

One way to convert this code to PHP would be like this:

$str = '0202827610';

$arr = str_split($str);
$total = 0;
foreach($arr as $item){
    $total += $item;
}

echo $total;

Basically the str_plit() transform the string into an array and it is iterated and summed inside the foreach.

    
16.06.2016 / 19:53