My target is to create unique number for every single report, number should be in a format 00000. Script should read this number from .txt file, then increase by 1 and add text "Report no.: ". Final result should be: like "Report no.: 0015". I have script:
[Sub Main
Dim App As Object
Set App = CreateObject ("PCDLRN.Application")
Dim Text As String
Dim Part As Object
Set Part = App.ActivePartProgram
Dim RepNo As String
Dim No As Integer
Dim V100 As Object
Set V100 = part.getvariablevalue ("V100")
Open "X:\CMM_Data\Proven programs\SCRIPT\REPORTNO.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, No
Loop
Close #1
No=No+1
If No>9999Then
Set Text = "Report no.: "
End If
If No>999 Then
Set Text = "Report no.: 0"
End If
If No>99 Then
Set Text = "Report no.: 00"
End If
If No>9 Then
Set Text = "Report no.: 000"
End If
If No<=9 Then
Set Text = "Report no.: 0000"
End If
'MsgBox Text
'MsgBox No
RepNo = Text & No
MsgBox RepNo
PART.SetVariableValue "V100", RepNo
Part.RefreshPart
End Sub]
This script giving report number which I want but I can't transfer RepNo (report number) to pc dmis, pc dmis showing massage "Runtime error on line: 43 - type mismatch". line 43: "PART.SetVariableValue "V100", RepNo" I did try the way of tries and mistakes but no result achieved. Can please any one tel me what is the problem with this script?
Code in Pc dmis:
[ASSIGN/100="REPORT NO.: 0001"
CS3 =SCRIPT/FILENAME= C:\USERS\DMILIUS\DESKTOP\DELETE\TEST.BAS
FUNCTION/Main,SHOW=NO,,
STARTSCRIPT/
COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
V100]
Get/SetVariableValue only works during the execution of the script. If you want to change the actual value of the assignment in your program, you should use PutText instead. That is a little more tedious though, you can find an example of how to utilize that in the source of my "Program Logger" script:
Hi,
I'm using BASIC "Language Reference Manual" PC-DMIS 3.6, there is the same example as in you post plus this example working well. It working in the way pcdmis-script-pcdmis and with numbers. I need script which should work in the way .txt-script-pcdmis and with string.
Also your logic for the string generation is wrong.
If No>9999Then
Set Text = "Report no.: "
End If
If No>999 Then
Set Text = "Report no.: 0"
End If
If No>99 Then
Set Text = "Report no.: 00"
End If
If No>9 Then
Set Text = "Report no.: 000"
End If
If No<=9 Then
Set Text = "Report no.: 0000"
End If
You need to reverse the order of the if statements.
If No<=9 Then
Set Text = "Report no.: 0000"
End If
If No>9 Then
Set Text = "Report no.: 000"
End If
If No>99 Then
Set Text = "Report no.: 00"
End If
If No>999 Then
Set Text = "Report no.: 0"
End If
If No>9999Then
Set Text = "Report no.: "
End If
Thanks for help,
By using your first suggestion I did overcome this problem.
About "logic for the string generation" as i see I'm still struggle to think in more complex way.
Regards
Finished code of stage:
[Sub Main
Dim App As Object
Set App = CreateObject ("PCDLRN.Application")
Dim Text As String
Dim Part As Object
Set Part = App.ActivePartProgram
Dim No As Integer
Dim V100 As Object
Set V100 = part.getvariablevalue ("V100")
Open "X:\CMM_Data\Proven programs\SCRIPT\REPORTNO.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, No
Loop
Close #1
No=No+1
If No>9999Then
Text = "Report no.: "
Else
If No>999 Then
Text = "Report no.: 0"
Else
If No>99 Then
Text = "Report no.: 00"
Else
If No>9 Then
Text = "Report no.: 000"
Else
If No<=9 Then
Text = "Report no.: 0000"
End If
End If
End If
End If
End If
Other think What I do need is to ensure that when program will be run offline, script should not save number of report to file. I do need insert peace of code which will indicate when script is used in online. I believe that for this purpose should be used GetProgramOption and PCD_ISONLINE but at the moment I have no success. So how I can get 1 if CMM is online and 0 if offline?