hexagon logo

Comment Script

I was working on this script to help quickly insert comments into a program for reporting purposes and thought I would share with people to get feedback and maybe answer a couple of questions.

The way the script works is it asks the user to enter the number of comments to insert with an input box, then it adds numbered (001,002,etc) $$ comments based on the number entered.

Everything works well for me when I use Excel VBA, but I get errors when using the PC-Dmis basic editor. I'm aware there are differences between the two, but I'm not really sure what the key differences are. So if anyone has input on that or how to fix my script to work INSIDE the pc-dmis basic editor, I would greatly appreciate it.

Below is the working code for Excel VBA:
Sub QuickPCDComment()

Dim DmisApp As Object
Dim DmisPart As Object
Dim DmisCommands As Object
Dim DmisCommand As Object


  Set DmisApp = CreateObject("PCDLRN.Application")
  Set DmisPart = DmisApp.ActivePartProgram
  Set DmisCommands = DmisPart.Commands


Dim inputAnswer As Integer

    inputAnswer = InputBox("Enter number of comments to insert (zero ends loop):")

'''Displays PC-DMIS Application

DmisApp.Visible = True
DmisApp.SetActive
DmisApp.Maximize

If inputAnswer < 10 Then

'''Input entered below 10

Dim counter

Dim commentNumber As String

    counter = 0

    commentNumber = 1

Do While counter < inputAnswer

   Set DmisCommand = DmisCommands.Add(SET_COMMENT, True)
    DmisCommand.Marked = True
    retval = DmisCommand.PutText("", ID, 0)
    retval = DmisCommand.SetToggleString(4, COMMENT_TYPE, 0)
    retval = DmisCommand.PutText("00" + commentNumber, COMMENT_FIELD, 1)
    retval = DmisCommand.SetToggleString(1, OUTPUT_TYPE, 0)

    counter = counter + 1

    commentNumber = commentNumber + 1

Loop

Else

'''Input entered above 10

Dim counter2

Dim commentNumber2 As String

    counter2 = 0

    commentNumber2 = 1

'''Comments # 1-9

Do While counter2 < 9

   Set DmisCommand = DmisCommands.Add(SET_COMMENT, True)
    DmisCommand.Marked = True
    retval = DmisCommand.PutText("", ID, 0)
    retval = DmisCommand.SetToggleString(4, COMMENT_TYPE, 0)
    retval = DmisCommand.PutText("00" + commentNumber2, COMMENT_FIELD, 1)
    retval = DmisCommand.SetToggleString(1, OUTPUT_TYPE, 0)

    counter2 = counter2 + 1

    commentNumber2 = commentNumber2 + 1

Loop


'''Comments # 10-inputAnswer

Do While counter2 < inputAnswer

   Set DmisCommand = DmisCommands.Add(SET_COMMENT, True)
    DmisCommand.Marked = True
    retval = DmisCommand.PutText("", ID, 0)
    retval = DmisCommand.SetToggleString(4, COMMENT_TYPE, 0)
    retval = DmisCommand.PutText("0" + commentNumber2, COMMENT_FIELD, 1)
    retval = DmisCommand.SetToggleString(1, OUTPUT_TYPE, 0)

    counter2 = counter2 + 1

    commentNumber2 = commentNumber2 + 1

Loop


End If



End Sub


Below is sample code for reference to change to a REPT comment
  Set DmisCommand = DmisCommands.Add(SET_COMMENT, TRUE)
    DmisCommand.Marked = TRUE
  ' Set Id  =
    retval = DmisCommand.PutText ("", ID, 0)
  ' Set Comment Type  = REPT
    retval = DmisCommand.SetToggleString (2, COMMENT_TYPE, 0)
  ' Set Comment Item 1 = Please Edit Comment Text!
    retval = DmisCommand.PutText ("Please Edit Comment Text!", COMMENT_FIELD, 1)


Parents
  • I changed it to what suggested within the script to get it working. Now I understand that "FUNCTION/Main" within PC-DMIS is calling Sub Main () within the script.

    Thank you both for the explanation.

    This has gotten me thinking and prompted another question for me. Is it common/good practice to use ONE bas script file containing multiple "Subs/Functions" and then calling the script in different spots in the PC-DMIS program?

    Example Script:
    Sub [COLOR=#FF0000]Main[/COLOR] ()
    stuff
    End Sub
    
    Sub [COLOR=#FF0000]Alt [/COLOR]()
    stuff
    End Sub
    
    Sub [COLOR=#FF0000]Alt2[/COLOR] ()
    stuff
    End Sub


    In the PC-DMIS program..
    CS1 =SCRIPT/FILENAME= V1
    FUNCTION/[COLOR=#FF0000]Main[/COLOR],SHOW=YES,,
    STARTSCRIPT/
    
    stuff..
    
    CS2 =SCRIPT/FILENAME= V1
    FUNCTION/[COLOR=#FF0000]Alt[/COLOR],SHOW=YES,,
    STARTSCRIPT/
    
    stuff..
    
    CS3 =SCRIPT/FILENAME= V1
    FUNCTION/[COLOR=#FF0000]Alt2[/COLOR],SHOW=YES,,
    STARTSCRIPT/


    Sure that's a valid way and it would be my preference to keep it all in one .BAS file vs creating individual ones that sometimes get difficult to keep track of and/or maintain. It's called a "library" of scripts that are all conveniently located in one place (keep backups of backups of backups!). And remember duplicated code is bad, so please Don’t Repeat Yourself (DRY), and also Keep It Simple, Stupid (KISS). Be lazy the right way - write code only once!
Reply
  • I changed it to what suggested within the script to get it working. Now I understand that "FUNCTION/Main" within PC-DMIS is calling Sub Main () within the script.

    Thank you both for the explanation.

    This has gotten me thinking and prompted another question for me. Is it common/good practice to use ONE bas script file containing multiple "Subs/Functions" and then calling the script in different spots in the PC-DMIS program?

    Example Script:
    Sub [COLOR=#FF0000]Main[/COLOR] ()
    stuff
    End Sub
    
    Sub [COLOR=#FF0000]Alt [/COLOR]()
    stuff
    End Sub
    
    Sub [COLOR=#FF0000]Alt2[/COLOR] ()
    stuff
    End Sub


    In the PC-DMIS program..
    CS1 =SCRIPT/FILENAME= V1
    FUNCTION/[COLOR=#FF0000]Main[/COLOR],SHOW=YES,,
    STARTSCRIPT/
    
    stuff..
    
    CS2 =SCRIPT/FILENAME= V1
    FUNCTION/[COLOR=#FF0000]Alt[/COLOR],SHOW=YES,,
    STARTSCRIPT/
    
    stuff..
    
    CS3 =SCRIPT/FILENAME= V1
    FUNCTION/[COLOR=#FF0000]Alt2[/COLOR],SHOW=YES,,
    STARTSCRIPT/


    Sure that's a valid way and it would be my preference to keep it all in one .BAS file vs creating individual ones that sometimes get difficult to keep track of and/or maintain. It's called a "library" of scripts that are all conveniently located in one place (keep backups of backups of backups!). And remember duplicated code is bad, so please Don’t Repeat Yourself (DRY), and also Keep It Simple, Stupid (KISS). Be lazy the right way - write code only once!
Children
No Data