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)


  • That makes a lot of sense. Thank you for your insight. Currently I have everything set up where most of the scripts inside my programs are part specific (I have a billion scripts now). I wanted to start adding in more functions to my scripts and was thinking it would be incredibly cumbersome to update and re-update all of them constantly.

    One of the things I want to start adding to my scripts is variables based on text files and stuff that are being updated on a day to day week to week basis and having things in one place will make that much easier to edit. I know that wouldn't apply to this comment script, but I'm glad I got that working as a toolbar button