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
  • You're right about example code turning on a light bulb, I've learned so much by just googling and searching threads. When I feel like I hit a wall, another forum thread will pop-up and turn the bulb back on.

    The code below works with VBA, not inside PC-DMIS Basic Editor.
    Sub TestComment()
    
    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
    
    
    
       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", COMMENT_FIELD, 1)
        retval = DmisCommand.SetToggleString(1, OUTPUT_TYPE, 0)
    
    
    End Sub


Reply
  • You're right about example code turning on a light bulb, I've learned so much by just googling and searching threads. When I feel like I hit a wall, another forum thread will pop-up and turn the bulb back on.

    The code below works with VBA, not inside PC-DMIS Basic Editor.
    Sub TestComment()
    
    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
    
    
    
       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", COMMENT_FIELD, 1)
        retval = DmisCommand.SetToggleString(1, OUTPUT_TYPE, 0)
    
    
    End Sub


Children
No Data