2

I need some assistance with outputting an error in CMD.

We have a timesheet system that is failing to add holidays into the users time sheets, it's done via a script. here is the portion of the script in question.

    sql = "select h_user,h_date1,h_hrs,h_approved,hol_default from holidays,hol_type,logins_users where userid=h_user and h_type=hol_id and h_date1='" & today & "' order by h_type desc"
    'WScript.Echo Sql

    ar.Open Sql, cnn ', adOpenForwardOnly, adLockReadOnly, adCmdText

    If Not (ar.EOF And ar.BOF) Then  'found some holidays
        ar.movefirst()
        While Not ar.EOF
            count = count + 1
            user = ar.Fields("h_user").Value
            datestr = ar.Fields("h_date1").Value
            hours = ar.Fields("h_hrs").Value
            approved = ar.Fields("h_approved").Value
            defaulthours = ar.Fields("hol_default").Value
            If hours = 8 Then actualhours = defaulthours
            If hours = 4 Then actualhours = defaulthours / 2
            If hours = 0 Then actualhours = 0

            sqlstr = "select * from timesheets where ts_user=" & user & " and ts_hrs in(" & hours & "," & defaulthours &") and ts_date='" & today & "' and ts_job=20"
            ar1.Open sqlstr, cnn
            If Not (ar1.EOF And ar1.BOF) Then
                'record exists
                sqlstr = "update timesheets set ts_eduser=0,ts_eddate=now() where ts_user=" & user & " and ts_hrs=" & actualhours & " and ts_date='" & today & "' and ts_job=20"
            Else
                'no record
                sqlstr = "insert into timesheets (ts_user,ts_date,ts_hrs,ts_approved,ts_job,ts_cruser,ts_crdate) values (" & user & ",'" & today & "'," & actualhours & "," & approved & ",20,0,Now())"
            End If
            ar1.Close()
            cnn.Execute("insert into tracking (t_user,t_query) values (0,'" & addslashes(sqlstr) & "')")
            cnn.Execute(sqlstr)
            ar.MoveNext()
        Wend
    End If
    ar.Close
Next
message = message & count & " holidays entries added" & vbCrLf
count = 0

Set ar1 = Nothing
Set ar2 = Nothing
Set ar1 = CreateObject("ADODB.RecordSet")
Set ar2 = CreateObject("ADODB.RecordSet")

For n = 0 To 28
    daystr = DateAdd("d", n, Now())

    today = Mid(daystr, 7, 4) & "-" & Mid(daystr, 4, 2) & "-" & Left(daystr, 2)

What I need to do is specifically output the results of defaulthours in a cmd window to allow me to inspect the error in the data it's retrieving.

I realise it's a WScript.Echo command but I've tried several variations and it stops the script from running.

Could someone point me in the right direction?

1 Answer 1

1

Run the script with cscript.exe instead of the default interpreter (wscript.exe).

cscript //NoLogo C:\path\to\your.vbs

cscript.exe prints WScript.Echo messages to the console instead of displaying message popups.

Alternatively you could replace WScript.Echo with WScript.StdOut.WriteLine, which will require cscript and raise an error otherwise (because WScript.StdOut is not available in wscript).

Sign up to request clarification or add additional context in comments.

3 Comments

Hey thanks for responding, I am running the script already in cscript via command line and at the moment all I get is the following results, C:\JARS_auto.vbs(178, 65) Microsoft VBScript runtime error: Type mismatch I need to actually get that data, so I can find the record in myphpadmin and delete / amend it.
@CarlHeath That is an entirely different problem than what you posted in your question. Please reduce your code to a minimal reproducible example that still exposes the problem, and post a new question with that code and the error message the code produced.
I found the answer I was looking for by adding the line wscript.echo defaulthours above line 178, now it outputs what the data its trying to dived by two is. Just got to try and track down the record in the back end and amend it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.