Basic to VB

Discuss RoboTask here
Post Reply
Dylan022
Posts: 7
Joined: Mon Mar 06, 2023 10:53 pm

Basic to VB

Post by Dylan022 »

Hello,

We have upgraded from RoboTask 6.4 to 9.4. I see that the basic evaluate functionality has depreciated. Is there any way you could help me turn these two into VB? Our developer that created this originally is no longer here.

Code: Select all

Sub Main
Dim s As String
Dim yr As String
Dim yrInt As Integer
Dim Julian As Integer
Dim d As Date
Dim realMo As String
Dim realDay As String

' extract Julian date from file name
s = RoboTaskApp.ExpandText("{JULDATE_DAY}")
yr = RoboTaskApp.ExpandText("{JULDATE_YEAR}")
yrInt = CInt(yr)
'MsgBox(s)

On Error Resume Next

' convert string date to integer
Julian = CInt(s)
If Err Then
Err.Clear
Julian = 0
End If

If Julian >0 Then
d = DateSerial(yrInt,1,1)
d = DateAdd("d",Julian-1,d)

If(Month(d) < 10) Then
realMo = ("0"+CStr(Month(d)))
Else
realMo = CStr(Month(d))
End If

If(Day(d) < 10) Then
realDay = ("0"+CStr(Day(d)))
Else
realDay = CStr(Day(d))
End If

RoboTaskApp.SetUserVariable("ProcessDate", CStr(yrInt)+"-"+realMo+"-"+realDay)
'MsgBox(CStr(Month(d))+"/"+CStr(Day(d)))
Else
RoboTaskApp.SetUserVariable("ProcessDate", "Invalid")
'MsgBox("Invalid date")
End If
End Sub

Code: Select all

Sub Main
 Dim f As String
 Dim s As String
 Dim yr As String
 Dim Julian As Integer
 Dim d As Date

 ' extract Julian date from file name
 's = RoboTaskApp.ExpandText("{ExtractFileExt({ExtractFileNameNoExt({C_file})})}")
 f = RoboTaskApp.ExpandText("{ExtractFileNameNoExt({RETURN_FILE})}")
'If InStr(f, "ILSTFRM") > 0 Then
 s = Mid(f,11,3)
 yr = Mid(f,7,4)

 On Error Resume Next

 	' convert string date to integer
	 Julian = CInt(s)
	 If Err Then
	    Err.Clear
	    Julian = 0
	 End If

	 If Julian >0 Then
	    d = DateSerial(Year(Date),1,1)
	    d = DateAdd("d",Julian-1,d)
	    RoboTaskApp.SetUserVariable("ConvertedDate", yr+"-"+CStr(Month(d))+"-"+CStr(Day(d)))
	    'MsgBox(CStr(Month (d))+"/"+CStr(Day(d)))
	 Else
	    RoboTaskApp.SetUserVariable("ConvertedDate", "Invalid")
	    'MsgBox("Invalid date")
	 End If

 'Else
 'End If
End Sub
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Basic to VB

Post by Oleg »

I will try to understand what these scripts are supposed to do. But it would be great if you could describe in a couple words what initial data and what they should return.
Oleg Yershov
Dylan022
Posts: 7
Joined: Mon Mar 06, 2023 10:53 pm

Re: Basic to VB

Post by Dylan022 »

Sorry about that. I am trying my best to understand it as well since the task is pretty complex.

For the first script I provided there would be a file loop and then it extracts two strings from the file name and creates the first two variables for Julian.

So for todays file the STR extract would be
{JULDATE_DAY} = 131
{JULDATE_YEAR} = 2023

Then the script calculates a ProcessDate variable and that is later used in a SQL query.

For the second script it is used later in the task. There is an if statement looking for a string in a file name and if the result is false it will run the second script. ConvertedDate would be used in creating a text file and a SQL query.
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Basic to VB

Post by Oleg »

About 1-st script - look at my task example below
Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.
Also you can simply copy task text and paste it into the task list.

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1040932817
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task123"
Hide=INTEGER|0
ID=INTEGER|151779669
LogOnAsUser=INTEGER|1
Name=STRING|"vbscript - 1"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""JULDATE_DAY"" with value ""120"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
linecount=STRING|"1"
varname=STRING|"JULDATE_DAY"
varvalue=STRING|"120"

[Actions\Action2]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""JULDATE_YEAR"" with value ""2020"""
Params=FOLDER

[Actions\Action2\Params]
expand=STRING|"0"
linecount=STRING|"1"
varname=STRING|"JULDATE_YEAR"
varvalue=STRING|"2020"

[Actions\Action3]
ActionID=STRING|"A_SCRIPT_VBSCRIPT"
Enabled=INTEGER|-1
Name=STRING|"VB Script"
Params=FOLDER

[Actions\Action3\Params]
expandvars=STRING|"0"
line00000000=STRING|"Sub DoMain"
line00000002=STRING|"  ' extract Julian date from file name"
line00000003=STRING|"  s = RoboTaskApp.ExpandText(""{JULDATE_DAY}"")"
line00000004=STRING|"  yr = RoboTaskApp.ExpandText(""{JULDATE_YEAR}"")"
line00000005=STRING|"  yrInt = CInt(yr)"
line00000006=STRING|"  'MsgBox(s)"
line00000008=STRING|"  On Error Resume Next"
line0000000A=STRING|"  ' convert string date to integer"
line0000000B=STRING|"  Julian = CInt(s)"
line0000000C=STRING|"  If Err Then"
line0000000D=STRING|"    Err.Clear"
line0000000E=STRING|"    Julian = 0"
line0000000F=STRING|"  End If"
line00000011=STRING|"  If Julian >0 Then"
line00000012=STRING|"    d = DateSerial(yrInt,1,1)"
line00000013=STRING|"    d = DateAdd(""d"",Julian-1,d)"
line00000015=STRING|"    If(Month(d) < 10) Then"
line00000016=STRING|"      realMo = (""0""+CStr(Month(d)))"
line00000017=STRING|"    Else"
line00000018=STRING|"      realMo = CStr(Month(d))"
line00000019=STRING|"    End If"
line0000001B=STRING|"    If(Day(d) < 10) Then"
line0000001C=STRING|"      realDay = (""0""+CStr(Day(d)))"
line0000001D=STRING|"    Else"
line0000001E=STRING|"      realDay = CStr(Day(d))"
line0000001F=STRING|"    End If"
line00000021=STRING|"    RoboTaskApp.SetUserVariable ""ProcessDate"", CStr(yrInt)+""-""+realMo+""-""+realDay"
line00000022=STRING|"    'LogMessage(CStr(yrInt)+""-""+realMo+""-""+realDay)"
line00000023=STRING|"  Else"
line00000024=STRING|"    RoboTaskApp.SetUserVariable ""ProcessDate"", ""Invalid"""
line00000025=STRING|"    'MessageBox(""Invalid date"")"
line00000026=STRING|"  End If"
line00000027=STRING|"End Sub"
line00000029=STRING|"DoMain"
linecount=STRING|"42"
savescript=STRING|"0"

[Actions\Action4]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""{ProcessDate}"""
Params=FOLDER

[Actions\Action4\Params]
icon=STRING|"1"
msg0=STRING|"{ProcessDate}"
msgcount=STRING|"1"
playsound=STRING|"0"
showmessage=STRING|"1"

Separated script is below

Code: Select all

Sub DoMain

  ' extract Julian date from file name
  s = RoboTaskApp.ExpandText("{JULDATE_DAY}")
  yr = RoboTaskApp.ExpandText("{JULDATE_YEAR}")
  yrInt = CInt(yr)
  'MsgBox(s)

  On Error Resume Next

  ' convert string date to integer
  Julian = CInt(s)
  If Err Then
    Err.Clear
    Julian = 0
  End If

  If Julian >0 Then
    d = DateSerial(yrInt,1,1)
    d = DateAdd("d",Julian-1,d)

    If(Month(d) < 10) Then
      realMo = ("0"+CStr(Month(d)))
    Else
      realMo = CStr(Month(d))
    End If

    If(Day(d) < 10) Then
      realDay = ("0"+CStr(Day(d)))
    Else
      realDay = CStr(Day(d))
    End If

    RoboTaskApp.SetUserVariable "ProcessDate", CStr(yrInt)+"-"+realMo+"-"+realDay
    'LogMessage(CStr(yrInt)+"-"+realMo+"-"+realDay)
  Else
    RoboTaskApp.SetUserVariable "ProcessDate", "Invalid"
    'MessageBox("Invalid date")
  End If
End Sub

DoMain
Oleg Yershov
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Basic to VB

Post by Oleg »

For the second script it is used later in the task. There is an if statement looking for a string in a file name and if the result is false it will run the second script. ConvertedDate would be used in creating a text file and a SQL query.
Give an example of file name to test 2-nd script
Oleg Yershov
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Basic to VB

Post by Oleg »

About 2-nd script look at the example below

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1040932817
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task478"
Hide=INTEGER|0
ID=INTEGER|1745158563
LogOnAsUser=INTEGER|1
Name=STRING|"vbscript - 2"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action2=FOLDER
Action3=FOLDER

[Actions\Action1]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""RETURN_FILE"" with value ""c:\incoming\datafiles\qwerty2023131uiop.txt"""
Params=FOLDER

[Actions\Action1\Params]
expand=STRING|"0"
linecount=STRING|"1"
varname=STRING|"RETURN_FILE"
varvalue=STRING|"c:\incoming\datafiles\qwerty2023131uiop.txt"

[Actions\Action2]
ActionID=STRING|"A_SCRIPT_VBSCRIPT"
Enabled=INTEGER|-1
Name=STRING|"VB Script"
Params=FOLDER

[Actions\Action2\Params]
expandvars=STRING|"0"
line00000000=STRING|"Sub DoMain"
line00000001=STRING|"  ' extract Julian date from file name"
line00000002=STRING|"  f = RoboTaskApp.ExpandText(""{ExtractFileNameNoExt({RETURN_FILE})}"")"
line00000003=STRING|"  'f = ""qwerty2023131uiop"""
line00000004=STRING|"  s = Mid(f,11,3)"
line00000005=STRING|"  yr = Mid(f,7,4)"
line00000006=STRING|"  'logmessage(s)"
line00000007=STRING|"  'logmessage(yr)"
line00000009=STRING|"  On Error Resume Next"
line0000000B=STRING|"  ' convert string date to integer"
line0000000C=STRING|"  Julian = CInt(s)"
line0000000D=STRING|"  If Err Then"
line0000000E=STRING|"    Err.Clear"
line0000000F=STRING|"    Julian = 0"
line00000010=STRING|"  End If"
line00000012=STRING|"  If Julian >0 Then"
line00000013=STRING|"    d = DateSerial(Year(Date),1,1)"
line00000014=STRING|"    d = DateAdd(""d"",Julian-1,d)"
line00000015=STRING|"    RoboTaskApp.SetUserVariable ""ConvertedDate"", yr+""-""+CStr(Month(d))+""-""+CStr(Day(d))"
line00000016=STRING|"    'logmessage(yr+""-""+CStr(Month(d))+""-""+CStr(Day(d)))"
line00000017=STRING|"  Else"
line00000018=STRING|"    RoboTaskApp.SetUserVariable ""ConvertedDate"", ""Invalid"""
line00000019=STRING|"    'MsgBox(""Invalid date"")"
line0000001A=STRING|"  End If"
line0000001C=STRING|"End Sub"
line0000001E=STRING|"doMain"
linecount=STRING|"31"
savescript=STRING|"0"

[Actions\Action3]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""file name: {return_file}"""
Params=FOLDER

[Actions\Action3\Params]
icon=STRING|"1"
msg0=STRING|"file name: {return_file}"
msg1=STRING|"{converteddate}"
msgcount=STRING|"2"
playsound=STRING|"0"
showmessage=STRING|"1"
Separated script here:

Code: Select all

Sub DoMain
  ' extract Julian date from file name
  f = RoboTaskApp.ExpandText("{ExtractFileNameNoExt({RETURN_FILE})}")
  'f = "qwerty2023131uiop"
  s = Mid(f,11,3)
  yr = Mid(f,7,4)
  'logmessage(s)
  'logmessage(yr)

  On Error Resume Next

  ' convert string date to integer
  Julian = CInt(s)
  If Err Then
    Err.Clear
    Julian = 0
  End If

  If Julian >0 Then
    d = DateSerial(Year(Date),1,1)
    d = DateAdd("d",Julian-1,d)
    RoboTaskApp.SetUserVariable "ConvertedDate", yr+"-"+CStr(Month(d))+"-"+CStr(Day(d))
    'logmessage(yr+"-"+CStr(Month(d))+"-"+CStr(Day(d)))
  Else
    RoboTaskApp.SetUserVariable "ConvertedDate", "Invalid"
    'MsgBox("Invalid date")
  End If

End Sub

doMain
Oleg Yershov
Dylan022
Posts: 7
Joined: Mon Mar 06, 2023 10:53 pm

Re: Basic to VB

Post by Dylan022 »

Thanks for the help Oleg.
Everything was running great yesterday with the first script and today the second script was hit and all went well.

That was the last task that I needed to migrate to our new RoboTask 9.4 server so you helped me finish that project.

I have two more small questions.
We installed a new anti-virus and I believe it messed up zip packing files. I have attached the error message we are getting, it references the DelZip DLL . Yesterday when the error appeared we uninstalled Sentinel 1 from the server and after a reboot the zip feature was working, but today it's not working again and S1 was never re-installed. I am wondering if something residual stayed and has messed up with the DLL. Would you have that available to download?

The 2nd question would be for the check for updates. I have also attached the error, basically it says check your internet.
We have pretty strict rules on our firewall so I am sure it's being blocked. Do you have an IP address or URL that the check for updates tool is reaching out to so I could white-list that?


Thanks for all your help.
Attachments
Zip error.png
Zip error.png (31.93 KiB) Viewed 2638 times
update error.png
update error.png (3.3 KiB) Viewed 2638 times
Oleg
Site Admin
Posts: 3014
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: Basic to VB

Post by Oleg »

Would you have that available to download?
all previous versions here: https://robotask.com/download/oldversions/
The current version is on Download page: https://robotask.com/download/
Do you have an IP address or URL that the check for updates tool is reaching out to so I could white-list that?
the updates URL is: https://www.robotask.com/rss/updates/
Of course CheckForUpdates utility uses this URL with parameters: product ID and current version
Oleg Yershov
Post Reply