mIRC Home    About    Download    Register    News    Help

Print Thread
.vbs script & COMs #226916 19/10/10 01:55 PM
Joined: Apr 2010
Posts: 959
F
FroggieDaFrog Offline OP
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 959
I have a .vbs script, and am able to run it from mIRC, but I actually WANT mIRC to wait until the .vbs script is done processing.
Code:
alias pstat {
  var %s = 1
  if ($com(Pstats)) { .comclose PStats }

  .comopen Pstats wscript.shell
  .comclose PStats $com(Pstats,run,1,bstr*,test\pstat.vbs,uint,0,bool,true)
  window -nh @MI-WebGet
  filter -fwc $qt("test\pstats2.txt") @MI-WebGet *
  goto end

  :error | reseterror | %s = $null
  if ($com(PStats)) { .comclose PStats }

  :end | return %s
}
Once the pstats.vbs has started running, mIRC continues on. Is there a way to get mIRC to pause/freeze/wait until the .vbs file is finished?

Edit Starts Here:
After doing a little more trial&error/testing, I realised Something: The command tree calling the Pstats waits, yet MIRC as a whole doesn't. I can still type, send text, etc while the .vbs processes, yet once it's finished, it returns %s(Unintended Threading? I might explore this some more)

Last edited by FroggieDaFrog; 19/10/10 02:12 PM.

I am SReject
My Stuff
Re: .vbs script & COMs [Re: FroggieDaFrog] #226921 19/10/10 02:35 PM
Joined: May 2007
Posts: 37
C
Chessnut Offline
Ameglian cow
Offline
Ameglian cow
C
Joined: May 2007
Posts: 37
Your best bet to get around this problem is to do something similar to the following:

Code:
alias workaround {
  if ($com(a)) .comclose a
  .comopen a MSScriptControl.ScriptControl
  noop $com(a,Language,4,bstr,VBScript)
  noop $com(a,ExecuteStatement,1,bstr, $&
    x = "abc" $crlf $& 
    y = "def" $crlf $& 
    z = x & y)
  noop $com(a,Eval,1,bstr,z)
  var %result = $com(a).result
  .comclose a
  return %result
}


Where the ExecuteStatement string is the code to be run, and the Eval string is the variable that you wish to return the contents of to mIRC.

Last edited by Chessnut; 19/10/10 02:35 PM.
Re: .vbs script & COMs [Re: Chessnut] #226922 19/10/10 02:50 PM
Joined: Apr 2010
Posts: 959
F
FroggieDaFrog Offline OP
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 959
As discussed on IRC, due to the .vbs code being 5-6KBs this isn't an option frown


The .vbs source:
Code:
Function IStr(item)
  if (IsNumeric(Item)) then
    iStr = CInt(Item)
  else
    iStr = Left(Item,Len(item) -1)
  end if
end Function
function iif(psdStr, trueStr, falseStr)
  if psdStr then
    iif = trueStr
  else 
    iif = falseStr
  end if
end function
set objFSO = CreateObject("Scripting.FileSystemObject")
set objPStatFile = objFSO.OpenTextFile("D:\My Mirc Client\Test\pstats.txt", 1, false)
strPStatFile = objPStatFile.ReadAll
objPStatFile.close
arrPStat = Split(strPStatFile,vbLf)
set rOBJ = New RegExp
rOBJ.IgnoreCase = True
rOBJ.Global = True
rOBJ.Pattern = "^rank (\d+) char ([^\x20]+) network ([^\x20]+) userhost ([^\x20]+) level (\d+) created (\d+) lastlogin (\d+) online (0|1) sex (?:(?:(m)ale)|(?:(f)emale)|(?:(n)ot set)) class \{([^\}]+)\} ttl (\d+) regentm (\d+) challengetm (\d+) slaytm (\d+) idled (\d+) x_pos (\d+) y_pos (\d+) amulet (\d+[a-z]?) charm (\d+[a-z]?) helm (\d+[a-z]?) boots (\d+[a-z]?) gloves (\d+[a-z]?) _
                 ring (\d+[a-z]?) leggings (\d+[a-z]?) shield (\d+[a-z]?) tunic (\d+[a-z]?) weapon (\d+[a-z]?) align ([neg]) alignchanged (0|1) powerpots (\d+) luckpots (\d+) fights ([0-5]) bets ([0-5]) bwon (\d+) blost (\d+) badd (\d+) bminus (\d+) hero (0|1) hlevel (\d) engineer (0|1) englevel (\d) gold (-?\d+) pen_mesg (\d+) pen_nick (\d+) pen_part (\d+) pen_kick (\d+) pen_quit (\d+) pen_quest (\d+) pen_logout (\d+)$"
dim mOBJ
set objFILE = objFSO.CreateTextFile("D:\My Mirc Client\Test\pstats2.txt")
For Each strPStat in arrPstat
  if (right(strPstat,1) = vbCr) then strPstat = left(strPstat,len(strPstat) -1) 
  set mOBJ = rOBJ.Execute(strPstat)
  If (mOBJ.Count > 0) then
    GEND = iif(IsNull(mOBJ(0).submatches(8)),"M",iif(IsNull(mOBJ(0).submatches(9)),"F","N"))
    PSUM = CInt(IStr(mOBJ(0).submatches(19))) + CInt(IStr(mOBJ(0).submatches(20))) + CInt(IStr(mOBJ(0).submatches(21))) + CInt(IStr(mOBJ(0).submatches(22))) + CInt(IStr(mOBJ(0).submatches(23))) + CInt(IStr(mOBJ(0).submatches(24))) + CInt(IStr(mOBJ(0).submatches(25))) + CInt(IStr(mOBJ(0).submatches(26))) + CInt(IStr(mOBJ(0).submatches(27))) + CInt(IStr(mOBJ(0).submatches(28)))
    AMOD = iif(mOBJ(0).submatches(29) = "e","0.9",iif(mOBJ(0).submatches(29) = "g","1.1","1.0"))
    HMOD = 1.0 + CDBL(mOBJ(0).submatches(39)) * (0.02 + CDbl(mOBJ(0).submatches(40)) * 0.01)
    MSUM = Fix(CDbl(PSUM) * CDbl(AMOD) * CDbl(HMOD))
    TFIGHTS = CInt(mOBJ(0).submatches(35)) + CInt(mOBJ(0).submatches(36))
    if (TFIGHTS = "0") then
      FWPR = 0.0
      FLPR = 0.0
    else
      FWPR = round(CDBL(mOBJ(0).submatches(35)) / CDbl(TFIGHTS) * 100,1)
      FLPR = round(CDBl(mOBJ(0).submatches(36)) / CDbl(TFIGHTS) * 100,1)
    end if
    if (mOBJ(0).SubMatches(35) = "0" or mOBJ(0).SubMatches(36) = "0") then
      FRAT = "0.0"
    else 
      FRAT = round(CDbl(mOBJ(0).submatches(35)) / CDbl(mOBJ(0).submatches(36)),2)
    end if
    EMOD = 1.0 + CDbl(mOBJ(0).submatches(41)) * (.02 + CInt(mOBJ(0).submatches(42)) * .01)
    TPEN = CLng(mObj(0).submatches(44)) + CLng(mObj(0).submatches(45)) + CLng(mObj(0).submatches(46)) + CLng(mObj(0).submatches(47)) + CLng(mObj(0).submatches(48)) + CLng(mObj(0).submatches(49)) + CLng(mObj(0).submatches(50))
    objfile.writeline(mOBJ(0).submatches(0) & "" & mOBJ(0).submatches(1) & "" & mOBJ(0).submatches(2) & "" & mOBJ(0).submatches(3) & "" & mOBJ(0).submatches(4) & "" & mOBJ(0).submatches(5) & "" & mOBJ(0).submatches(6) & "" & mOBJ(0).submatches(7) & "" & GEND & "" & mOBJ(0).submatches(11) & "" & mOBJ(0).submatches(12) & "" & _ 
                      mOBJ(0).submatches(13) & "" & mOBJ(0).submatches(14) & "" & mOBJ(0).submatches(15) & "" & mOBJ(0).submatches(16) & "" & mOBJ(0).submatches(17) & "" & mOBJ(0).submatches(18) & "" & PSUM & "" & MSUM & "" & mOBJ(0).submatches(19) & "" & mOBJ(0).submatches(20) & "" & mOBJ(0).submatches(21) & "" & _
                      mOBJ(0).submatches(22) & "" & mOBJ(0).submatches(23) & "" & mOBJ(0).submatches(24) & "" & mOBJ(0).submatches(25) & "" & mOBJ(0).submatches(26) & "" & mOBJ(0).submatches(27) & "" & mOBJ(0).submatches(28) & "" & mOBJ(0).submatches(29) & "" & mOBJ(0).submatches(30) & "" & AMOD & "" & mOBJ(0).submatches(31) & "" & _
                      mOBJ(0).submatches(32) & "" & mOBJ(0).submatches(33) & "" & mOBJ(0).submatches(34) & "" & TFIGHTS & "" & mOBJ(0).submatches(35) & "" & FWPR & "" & mOBJ(0).submatches(36) & "" & FLPR & "" & FRAT & "" & mOBJ(0).submatches(37) & "" & mOBJ(0).submatches(38) & "" & mOBJ(0).submatches(39) & "" & _
                      mOBJ(0).submatches(40) & "" & HMOD & "" & mOBJ(0).submatches(41) & "" & mOBJ(0).submatches(42) & "" & EMOD & "" & mOBJ(0).submatches(43) & "" & TPEN & "" & mObj(0).submatches(44) & "" & mObj(0).submatches(45) & "" & mObj(0).submatches(46) & "" & mObj(0).submatches(47) & "" & mObj(0).submatches(48) & "" & _
                      mObj(0).submatches(49) & "" & mObj(0).submatches(50) & "")
  end if
next

Last edited by FroggieDaFrog; 19/10/10 04:13 PM.

I am SReject
My Stuff
Re: .vbs script & COMs [Re: FroggieDaFrog] #226930 19/10/10 06:56 PM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
When the boolean value in Wscript.Shell's Run() is set to true mIRC should wait... not sure why it isn't!

You could possibly try combining Chessnut's method with yours:

Code:
alias workaround {
  if ($com(a)) .comclose a
  .comopen a MSScriptControl.ScriptControl
  noop $com(a,Language,4,bstr,VBScript)
  noop $com(a,ExecuteStatement,1,bstr, $&
    set objWSH = CreateObject("WScript.Shell") $crlf $& 
    objWSH.Run( $+ $qt($mircdirtest\pstat.vbs) $+ ,0,true))
  var %result = $com(a).result
  .comclose a
  window -nh @MI-WebGet
  filter -fwc $qt("test\pstats2.txt") @MI-WebGet *
  :error | reseterror | %s = $null
  if ($com(a)) { .comclose a }
  :end | return %s
}