Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

Using script control

Hi,

I'm kinda at my wits end.

I was trying to use the ScriptControl in VB, and this is the code that I was trying to add into the script control:
Dim runLine as string
Set sc = New ScriptControl
sc.Language = "VBScript"
sc.AddObject "App", VB.App

sc.AddCode runLine


In "runLine", it contains:

Function chk(cnt)
If cnt <= 0 and datediff ("n", "04-13-2005 01:25", "04-15-2005 15:12") >=60 then
chk = True
else
chk = False
end if

End Function



however at the it prompts:
Run-time error '91':
Object variable or With block variable not set

I really can't tell which part of the function is wrong. Can anyone elighten me? Thanks!
0
sata
Asked:
sata
  • 6
  • 4
1 Solution
 
Shiju SasidharanAssoc Project ManagerCommented:
in which line did u get          Run-time error '91':


0
 
sataAuthor Commented:
sc.AddCode runLine
0
 
Shiju SasidharanAssoc Project ManagerCommented:
i checked it
no error comes , can u please check the content in runLine ?
i placed the content directly to runLine and tried
here is my code
'===================
    Dim runLine As String
    Set sc = New ScriptControl
    sc.Language = "VBScript"
    sc.addObject "App", VB.App
    runLine = " Function chk(cnt) " & vbCrLf & _
            "    If cnt <= 0 And DateDiff(""n"", ""04-13-2005 01:25"", ""04-15-2005 15:12"") >= 60 Then " & vbCrLf & _
            "       chk = True " & vbCrLf & _
            "    Else " & vbCrLf & _
            "       chk = False " & vbCrLf & _
            "    End If " & vbCrLf & _
            " End Function"
    sc.AddCode runLine
'========================


and one more thing
>>DateDiff("n", "04-13-2005 01:25", "04-15-2005 15:12") >= 60
why do u need such a static checking ? it always gives 3707

;-)
Shiju

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
sataAuthor Commented:
oh actually the datediff part is a variable actually. The values will be replaced into the date time string before it is feed into runLine.

I will try again. thanks.
0
 
sataAuthor Commented:
Hi Shiju,

I tried to paste in your code directly, and run, but I still get the same error.

Is there some settings that I'm missing?
0
 
Shiju SasidharanAssoc Project ManagerCommented:
hi
Are u sure, u get error in the following line ?
>> sc.AddCode runLine

are u using any On Error goto
or  On Error Resume statements in ur code ?
also pls check whether u have included the reference
      Microsoft Script Control 1.0





0
 
sataAuthor Commented:
yes. I'm not using on error yet. coz' i hv not finish the code. I will normally put in error check after I complete certain section of codes, and this is not the case.

also, I have reference Microsoft Script Control 1.0.

This set of codes used to work, but I'm not sure why it just don't now...
0
 
Shiju SasidharanAssoc Project ManagerCommented:
hi
if u dont mind , can u please post the complete code segment ?
0
 
sataAuthor Commented:
hmm.. i hope this segment helps:

Dim scriptFunction As String
scriptFunction = "Function chk(cnt) " & vbCrLf & _
                 "%Lines%" & vbCrLf & "End Function"


            If Not rsJobCount.EOF Then
           
                runjobcond = rsJobRules("ActionCondition")
                runjobcond = Replace(runjobcond, "%False%", "chk=False")
                runjobcond = Replace(runjobcond, "%True%", "chk=True")
                runjobcond = Replace(runjobcond, "%Jobcount%", "cnt")
                runjobcond = Replace(runjobcond, "%alertunit%", """" & rsJobRules("AlertTimeunit") & """")
                runjobcond = Replace(runjobcond, "%lasttime%", """" & Format(rsJobRules("LastActivateTime"), "mm-dd-yyyy hh:mm") & """")
                runjobcond = Replace(runjobcond, "%curdatetime%", """" & Format(Date$ & " " & Time$, "mm-dd-yyyy hh:mm") & """")
                runjobcond = Replace(runjobcond, "%alerttime%", rsJobRules("AlertTimevalue"))
                runLine = Replace(scriptFunction, "%Lines%", runjobcond)
                sc.AddCode runLine
                chkrun = sc.Run("chk", rsJobCount(0))
            End If


When runjobcond is first assigned ( runjobcond = rsJobRules("ActionCondition")) , it will contain:

If %Jobcount% <= 0 and datediff (%alertunit%, %lasttime%, %curdatetime%) >=%alerttime% then
%True%
else
%False%
end if


so after all the replace of values, it will turn out to be what I have first pasted on my post.


0
 
sataAuthor Commented:
i've found the error. It's with my sequence.
My code is:

Set sc = New ScriptControl
sc.Language = "VBScript"
sc.AddObject "App", VB.App

formA.show

set sc = nothing


In formA, then I will do the code segment pasted one post earlier. However, while the code is processing for formA, it will proceed to set sc to nothing. thus the error.

Apologies for any confusion caused. Thanks for all the help!
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now