Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Correlate vbs and php

  1. Feb 18, 2017 #1
    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: Feb 18, 2017
  2. jcsd
  3. Feb 18, 2017 #2

    jack action

    User Avatar
    Science Advisor
    Gold Member

    You got StrComp for strcmp and UCase for strtoupper. You just need to do the test on osn.
     
  4. Feb 19, 2017 #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: Feb 19, 2017
  5. Feb 19, 2017 #4

    phinds

    User Avatar
    Gold Member
    2016 Award

    Please learn how to use the code tags
     
  6. Feb 19, 2017 #5
    Told you I didn't master the VBS. Better ? :)
     
  7. Feb 19, 2017 #6

    jack action

    User Avatar
    Science Advisor
    Gold Member

    How about this, loosing the PHP and using VBScript instead:

    Code (Text):
    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.
     
  8. Feb 19, 2017 #7
    I'll try it when I can, I'll let you know. Thank you :)
     
  9. Feb 19, 2017 #8

    jack action

    User Avatar
    Science Advisor
    Gold Member

    I took a second look and I found there is a Split function that does the same thing as explode in php.
     
  10. Feb 19, 2017 #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
     
  11. Feb 19, 2017 #10

    jack action

    User Avatar
    Science Advisor
    Gold Member

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

    Also, I don't think '===' is valid in VBScript, just use '=' (reference).
     
  12. Feb 20, 2017 #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
     
  13. Feb 20, 2017 #12

    jack action

    User Avatar
    Science Advisor
    Gold Member

    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.
     
  14. Feb 23, 2017 #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 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>
    ___________________________________________________________
     
  15. Feb 23, 2017 #14

    jack action

    User Avatar
    Science Advisor
    Gold Member

    Usually, it's better to use tab-separated values, instead of spaces, just for that specific problem.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Correlate vbs and php
  1. PHP Help ? (Replies: 16)

  2. Php or c++ ? (Replies: 40)

  3. Advise: PHP or Java (Replies: 9)

  4. Understanding PHP (Replies: 4)

  5. Php script problem (Replies: 12)

Loading...