# PHP Correlate vbs and php

1. Feb 18, 2017

### dunnome

Hello ! I have a php code that I'd like to use as a vbs one. But I don't know exacly how to do so. Could you help me please ?

Actually, my vbs script will read a file line by line, take the first word, put it in 'LastName' and after the space, take the "FirstName". But if you reverse the Last Name and the First Name, it'll be wrong. The purpose of it is that you can add numerous people in a server in one click, using a txt file

Here's a piece of my vbs script :
________________________________________________________________
space=" "

Do Until objFile.AtEndofStream

E1=InStr(Strline,space)
osn=Mid(Strline,1,E1-1)

E2=Len(StrLine)
oGivenName=Mid(Strline,E1+1,E2)

oUname = Left(oGivenName,1) & "." & osn
_______________________________________________________________

In the php script, the code will know whether the name is in capital letter or not and will assign the First Name and the Last name correctly :

____________________________________________________________________
<?php
$Name="John DOE";$temp = explode(" ", $nomprenom, 2); if (strcmp($temp[0], strtoupper($temp[0])) === 0) {$LastName = $temp[0];$FirstName= $temp[1]; } else {$LastName= $temp[1];$FirstName= $temp[0]; } /* In order to know if it works, I display them */ echo$LastName;
echo "<br>";
echo \$FirstName;

?>
__________________________________________________________________

I need to use that code in the vbs script. Can you help me do it please ? I don't really master the vbs language.

Thank you.

Last edited: Feb 18, 2017
2. Feb 18, 2017

### jack action

You got StrComp for strcmp and UCase for strtoupper. You just need to do the test on osn.

3. Feb 19, 2017

### dunnome

So it would be
________________________________________________
Dim name as String
temp = explode(" ", name, 2);
Dim LastName as String
Dim FirstName as String

Do Until objFile.AtEndofStream

if (StrComp(temp[0], UCase(temp[0])) === 0) Then
LastName = temp[0];
FirstName= temp[1];

else
LastName= temp[1];
FirstName= temp[0];

End If

osn=LastName

oGivenName=FirstName

oUname = Left(oGivenName,1) & "." & osn
___________________________________________________________

Or i'm mistaken somewhere ?

Last edited: Feb 19, 2017
4. Feb 19, 2017

### phinds

Please learn how to use the code tags

5. Feb 19, 2017

### dunnome

Told you I didn't master the VBS. Better ? :)

6. Feb 19, 2017

### jack action

Code (Text):
space=" "

Do Until objFile.AtEndofStream
E1 = InStr(Strline,space)
osn = Mid(Strline,1,E1-1)

E2 = Len(StrLine)

ogn = Mid(Strline,E1+1,E2)

If StrComp(osn, UCase(osn)) = 0 Then
oSurName = osn
oGivenName = ogn
Else
oSurName = ogn
oGivenName= osn
End If
Loop
P.S.: I'm no expert at VBScript, I'm just reusing your code.

7. Feb 19, 2017

### dunnome

I'll try it when I can, I'll let you know. Thank you :)

8. Feb 19, 2017

### jack action

I took a second look and I found there is a Split function that does the same thing as explode in php.

9. Feb 19, 2017

### dunnome

Well I wanted to try (with split instead of explode for now), and it says "Expected ')' Char 17" in that line "if (StrComp(temp[0], UCase(temp[0])) === 0) Then".
The thing is that I don't know where the error is :s

10. Feb 19, 2017

### jack action

Write array as temp(0) instead of temp[0].

Also, I don't think '===' is valid in VBScript, just use '=' (reference).

11. Feb 20, 2017

### dunnome

I didn't understand "Write array as temp(0) instead of temp[0]." What to you mean ? If I did I tried anyway but the same error is displayed

12. Feb 20, 2017

### jack action

From the examples at W3Schools, when you want to read the item of an array, you must use parenthesis to enclose the index of the item and not brackets as in PHP. The 'Char 17' is '[' in your statement, this should give you a clue to help you debug your code.

You should look at the references on W3chools and Microsoft and learn the proper syntax of VBScript.

13. Feb 23, 2017

### dunnome

Hello jack action. Here's some news :) I finally manage to finish the code, in case you need it someday (though I doubt), I give it to you. On the other hand, I can't find out how to do where there is a name with a space in it (ex : Lastname DE NAME), do you have any idea ? It's just a detail, it doesn't matter if you don't.
________________________________________________
Do Until objFile.AtEndofStream

temp = split(Strline," ", 2)
Dim Lastname 'as String
Dim Firstname 'as String

if StrComp(temp(0), Ucase(temp(0))) = 0 Then
Lastname= temp(0)
Firstname= temp(1)

else
Lastname= temp(1)
Firstname= temp(0)

End If

osn=Lastname

oGivenName=Firstname

oUname = Left(oGivenName,1) & "." & osn </code>
___________________________________________________________

14. Feb 23, 2017

### jack action

Usually, it's better to use tab-separated values, instead of spaces, just for that specific problem.