hello brothers,
I have this VBScript program:

Set WSHShell = Wscript.CreateObject("WScript.Shell")       
Set FSO = Wscript.CreateObject("Scripting.FileSystemObject") 
Set EnvVar = wshShell.Environment("Process")
tBestand= EnvVar("USERPROFILE") & "\Desktop\Items Numbers.txt"
Set Bestand = fso.createtextfile(tBestand,2)
For x = 1048639472 To 1048640474
Bestand.WriteLine("Item Number is=" & (x))
Next
Bestand.close
WScript.quit

The Output is: (about 1002 lines).
Item Number is=1048639472
.
.
.
Item Number is=1048640474
My question is I don't want the output in sequence, I want the output like this function in php language (I found it online):

function check($id){
$id = trim($id);
if(!is_numeric($id)) return false;
if(strlen($id) !== 10) return false;
$type = substr ( $id, 0, 1 );
if($type != 2 && $type != 1 ) return false;
for( $i = 0 ; $i<10 ; $i++ ) {
//echo "  $id <b>"."</b> -";
if ( $i % 2 == 0){
$ZFOdd = str_pad ( ( substr($id, $i, 1) * 2 ), 2, "0", STR_PAD_LEFT );
$sum += substr ( $ZFOdd, 0, 1 ) + substr ( $ZFOdd, 1, 1 );
}else{
$sum += substr ( $id, $i, 1 );
}
}
//echo $sum;
return $sum%10 ? false : $type;

is it possible to convert this code php language to vbscript, because i want to add it to my above vbscript program.
thanks in advance.

Dani AI

Generated

— short, practical answer: the PHP routine can be translated to VBScript. The version below preserves the same checks (trim, numeric, length 10, first digit 1 or 2) and the same left‑to‑right doubling/summing logic used in the PHP example. It returns the leading digit (1 or 2) when the value passes, otherwise it returns False.

Function CheckID(idStr)
  idStr = Trim(CStr(idStr))
  If Not IsNumeric(idStr) Then
    CheckID = False
    Exit Function
  End If
  If Len(idStr) <> 10 Then
    CheckID = False
    Exit Function
  End If

  Dim firstDigit
  firstDigit = CInt(Left(idStr, 1))
  If firstDigit <> 1 And firstDigit <> 2 Then
    CheckID = False
    Exit Function
  End If

  Dim total, i, d, p
  total = 0
  For i = 1 To 10                 ' Mid is 1-based in VBScript
    d = CInt(Mid(idStr, i, 1))
    If ((i - 1) Mod 2) = 0 Then   ' matches PHP's 0-based parity
      p = d * 2
      total = total + (p \ 10) + (p Mod 10)   ' sum digits of product
    Else
      total = total + d
    End If
  Next

  If (total Mod 10) = 0 Then
    CheckID = firstDigit
  Else
    CheckID = False
  End If
End Function

To avoid sequential output there are two practical approaches:

  • Shuffle the whole range (Fisher–Yates), then iterate the shuffled array and call CheckID(...) before writing each line. A compact shuffle routine:

    Sub ShuffleArray(arr)
    Dim i, j, tmp
    Randomize
    For i = UBound(arr) To 1 Step -1
      j = Int((i + 1) * Rnd)
      tmp = arr(j)
      arr(j) = arr(i)
      arr(i) = tmp
    Next
    End Sub
  • For very large ranges, sample randomly (generate candidates with Int((end-start+1)*Rnd)+start) and validate until the required number of valid items is collected; keep a Dictionary of seen values to avoid duplicates.

Notes/cautions: Mid() is 1‑based, so parity is adjusted with (i-1). VBScript numeric ops use floating types; use CInt/CLng where integer semantics are needed. Building a huge array uses memory — prefer sampling for large ranges. Also, consider renaming the thread to a descriptive title (as and suggested) so others can find the solution more easily.

Recommended Answers

All 2 Replies

"Please help" is not subject of this topic!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.