locked
need a vb script RRS feed

  • Question

  • In vbscript (Visual Basic Scripting language, as one might find or use in an Event on a Surveyagree),

    suppose you have a string variable that has an integer put into it by a user

    (let’s say 4-6 digits in length, although you can send a solution for 5 digits first and then expand it to handle 4-6 digits if you prefer to do it in chunks). 

    I want to find the product of those digits (except if a digit is zero in which case subtract 1 from the product without the 0), and

    Convert that product to a string,

    Add leading zeros if that string is < 4 characters in length, and

    Compare that string to another string input by the user. 

    For example, if the first number entered were “256”, the second number they entered would be compared to “0060”;

    “45023” à “0119” (4 x 5 x 2 x 3 -1);

    And so on. 

    • Moved by Bill_Stewart Monday, July 13, 2015 3:40 PM This is not "do my homework for me" forum
    Wednesday, June 10, 2015 4:19 PM

Answers

All replies

  • What's provoking the question? Is this a homework or class assignment?

    If yes, then be aware that this isn't a homework question forum.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, June 10, 2015 4:40 PM
  • That's funny.

    Sorry we don't do web sites here. Post in the IIS forum for help.

    In PowerShell this is very easy to do.


    \_(ツ)_/

    Wednesday, June 10, 2015 5:10 PM
  • This is a work assignment and I've never done any vb scripting
    Wednesday, June 10, 2015 5:19 PM
  • It sounds like you need to do some studying. You can start here:

    https://msdn.microsoft.com/en-us/library/t0aew7h6.aspx


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by Bill_Stewart Monday, July 13, 2015 3:39 PM
    Wednesday, June 10, 2015 5:38 PM
  • Takes only a minute in PowerShell

    $s='45023'
    $s.ToCharArray()|
        ForEach-Object  -begin {$px=1;$t=0}  -end {$px+$t}   -process {
              $x=[int](-48 + $_)
              if($x -eq 0){$t=-1;$x=1}
              $px=$px * $x
         }

    And you can insert any number of digits you like.

    You can also use this as a map to doing it in VBScript.


    \_(ツ)_/


    • Edited by jrv Wednesday, June 10, 2015 5:43 PM
    Wednesday, June 10, 2015 5:42 PM