Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB Script in Wine doesn't return values for RND function

I'm trying to run below vbscript in Linux using Wine, but it doesn't work. Other vbscript functions are working as expected.

Wine Version : wine-5.0.3 (Ubuntu 5.0.3-3) Command : wine cscript ./test_rnd.vbs

VBS:

   On Error Resume Next
WScript.Echo "Before Rnd"

Rnd -1

WScript.Echo "After Rnd"

If Err.Number <> 0 Then
  WScript.Echo "Error : " & Err.Number & ": " & Err.Description
End If

OutPut using Wine:

enter image description here

This script is working fine in Windows.

Do i need to install any other wine dependency ? if you have any alternative solution to execute VBS in Linux please mention.

like image 530
Ara Avatar asked Mar 19 '26 10:03

Ara


2 Answers

The Rnd() function is dependent on seeds generated by the Randomize statement which generates seeds via the OS System Timer, a Windows OS feature. While Linux will have something similar, VBScript's code base will not know how to call it and will depend on Wine to provide an implementation that mimics the Windows System Timer.

As the error you are receiving is

Object doesn’t support this action

I’m afraid you’re out of luck until Wine provides an implementation.

like image 106
user692942 Avatar answered Mar 22 '26 01:03

user692942


Although it does not appear Wine supports VBScript's Rnd function, what about your own implementation of a "random" function with something like this?

Function RndNum(MaxValue)
    RndNum = (((Hour(Now) + 1) * (Minute(Now) + 1) * (Second(Now) + 1) * Right(Timer, 5)) Mod MaxValue)
End Function

How to manually generate random numbers

Edit:

The above code did not generate random numbers when ran in a loop, as the timestamp is not precise enough.

enter image description here

Updating the function to use an external Seed does work, however I would not not vouch for how unique these would be, I'm assuming this would not be for Cryptography...

Function RndNum(Seed, MaxValue)
    RndNum = (((Hour(Now) + 1) * (Minute(Now) + 1) * (Second(Now) + 1) * Right((Seed * Right(Timer, 5)), 8)) Mod MaxValue) 
End Function

Do
    counter = counter + 1
    Numbers = Numbers & RndNum(counter,1000) & ", "
Loop While counter < 10

MsgBox Numbers

enter image description here

like image 27
Moir Avatar answered Mar 22 '26 01:03

Moir