Correlate VBS and PHP for Server Use

  • PHP
  • Thread starter dunnome
  • Start date
  • Tags
    Php
In summary, the code will read a file line by line, take the first word, put it in LastName and after the space, take the FirstName. However, if the LastName and the FirstName are reversed, it will be wrong.
  • #1
dunnome
7
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
  • #3
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:
  • #4
Please learn how to use the code tags
 
  • #5
Told you I didn't master the VBS. Better ? :)
 
  • #6
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.
 
  • #7
I'll try it when I can, I'll let you know. Thank you :)
 
  • #8
I took a second look and I found there is a Split function that does the same thing as explode in php.
 
  • #9
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.
 

Related to Correlate VBS and PHP for Server Use

1. What is the difference between VBS and PHP?

VBS (Visual Basic Script) and PHP (Hypertext Preprocessor) are both programming languages commonly used for server-side scripting. The main difference between the two is that VBS is primarily used on Windows platforms, while PHP can be used on both Windows and Linux servers. VBS is also often used for smaller and simpler tasks, while PHP is more commonly used for larger and more complex projects.

2. How do VBS and PHP work together for server use?

VBS and PHP can work together in a complementary way for server use. VBS can be used for basic tasks such as file manipulation and system administration, while PHP can be used for more advanced web development tasks such as creating dynamic web pages and managing databases. VBS and PHP can also be integrated together using various methods, such as calling VBS scripts within PHP code.

3. Can VBS and PHP be used together on any server?

Yes, VBS and PHP can be used together on any server that supports both languages. This includes most Windows servers and many Linux servers. However, it is important to note that some hosting providers may only support one of the languages, so it is always best to check with your hosting provider before attempting to use both languages together.

4. What are the benefits of using VBS and PHP together for server use?

Using VBS and PHP together for server use allows for a wider range of functionality and tasks to be performed. VBS is known for its simplicity and speed, while PHP is known for its versatility and power. By combining the two languages, developers can take advantage of the strengths of each to create efficient and effective server-side applications.

5. Are there any disadvantages to using VBS and PHP together for server use?

One potential disadvantage of using VBS and PHP together is the need for some knowledge of both languages. This may require additional learning and training for developers who are not familiar with both languages. Additionally, since VBS and PHP are two separate languages, there may be some compatibility issues when trying to integrate them together, which could potentially lead to errors and bugs.

Similar threads

  • Programming and Computer Science
3
Replies
75
Views
4K
Replies
16
Views
2K
  • Programming and Computer Science
Replies
7
Views
5K
Back
Top