PHP Correlate VBS and PHP for Server Use

  • Thread starter Thread starter dunnome
  • Start date Start date
  • Tags Tags
    Php
AI Thread Summary
The discussion centers on converting a PHP script to VBScript for processing names from a text file. The user seeks assistance in ensuring that the script correctly identifies and assigns last names and first names, especially when dealing with capitalization. Key points include the need to replace PHP functions with their VBScript equivalents, such as using `Split` instead of `explode`, and correcting syntax issues like using parentheses for array indexing. The user also encounters challenges with names containing spaces and is advised to consider using tab-separated values to avoid confusion. Overall, the conversation emphasizes the transition from PHP to VBScript while addressing specific coding hurdles.
dunnome
Messages
7
Reaction score
0
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

Strline=objFile.ReadLine
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:
Technology news on Phys.org
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

Strline=objFile.ReadLine

osn=LastName

oGivenName=FirstName

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

Or I'm mistaken somewhere ?
 
Last edited:
Please learn how to use the code tags
 
Told you I didn't master the VBS. Better ? :)
 
How about this, loosing the PHP and using VBScript instead:

Code:
space=" "

Do Until objFile.AtEndofStream
    Strline = objFile.ReadLine
    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.
 
I'll try it when I can, I'll let you know. Thank you :)
 
I took a second look and I found there is a Split function that does the same thing as explode in php.
 
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
Write array as temp(0) instead of temp[0].

Also, I don't think '===' is valid in VBScript, just use '=' (reference).
 
  • #11
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
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
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

Strline=objFile.ReadLine

temp = split(Strline," ", 2)
Dim Lastname 'as String
Dim Firstname 'as Stringif 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
dunnome said:
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 ?
Usually, it's better to use tab-separated values, instead of spaces, just for that specific problem.
 

Similar threads

Back
Top