Correlate VBS and PHP for Server Use

  • Context: PHP 
  • Thread starter Thread starter dunnome
  • Start date Start date
  • Tags Tags
    Php
Click For Summary

Discussion Overview

The discussion revolves around converting a PHP script into VBScript for processing names from a text file. Participants explore how to correctly assign first and last names based on capitalization and handle names with spaces.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant seeks help in translating a PHP script into VBScript, specifically for reading names from a file and determining their order based on capitalization.
  • Another participant suggests using StrComp for string comparison and UCase for converting to uppercase, indicating how these functions can replace PHP's strcmp and strtoupper.
  • A proposed VBScript structure is shared, but there is uncertainty about its correctness, with a participant questioning if they made any mistakes.
  • One participant emphasizes the importance of using proper code formatting and syntax in VBScript, particularly regarding array indexing.
  • Another participant mentions the existence of a Split function in VBScript, which can be used similarly to PHP's explode function.
  • There is a reported error regarding the use of brackets versus parentheses for array indexing, with clarification provided on the correct syntax.
  • A later post discusses the challenge of handling names with spaces, suggesting that using tab-separated values might be a better approach for this issue.

Areas of Agreement / Disagreement

Participants generally agree on the need to adapt the PHP logic to VBScript, but there are multiple views on the best way to handle names with spaces, and some uncertainty remains about the correctness of the proposed code snippets.

Contextual Notes

Participants express limitations in their understanding of VBScript syntax, particularly regarding array handling and string comparison, which may affect their ability to implement the proposed solutions effectively.

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

  • · Replies 75 ·
3
Replies
75
Views
7K
  • · Replies 7 ·
Replies
7
Views
6K
Replies
16
Views
3K