hexagon logo

New to VB

I'm trying to pass a variable for work orde number from pc-dmis user input

C2 =COMMENT/INPUT,NO,FULL SCREEN=NO,
What is the Work Order #?
ASSIGN/V1=C2.INPUT

to VB script which creates excel file. The WO# has to go to a specific cell (D1).

Thanks
  • I would also like to know this.
    Specifically how to get either Report Comments or Variables to output to Excel from within PC-DMIS
  • If this is a script that you call from your part program, you can pass the variable to the script like this:
    C1         =COMMENT/INPUT,NO,FULL SCREEN=NO,
                Enter the WORKORDER number
                ASSIGN/VAR_WO=C1.INPUT
    CS1        =SCRIPT/FILENAME= C:\DATA\SCRIPTS\ARGTEST.BAS
                FUNCTION/Main,SHOW=YES,[B][COLOR=#FF0000]ARG1=VAR_WO[/COLOR][/B],,
                STARTSCRIPT/


    Then modify the script to receive it like this:
    Sub Main [COLOR=#FF0000][B](str As String)[/B][/COLOR]
    
    MsgBox(str)
    
    End Sub


    I'm assuming there's plenty of examples in your existing script to show how to put data into a specific cell in the spreadsheet.
  • There's so many examples here on this forum on how to get a handle on the PCDLRN object and so much more on VBA on the interwebz. Wish I had time to guide you step by step but not right meow...
  • Ahhh, that's what I was looking for! I was under the impression it was similar to how VB handles Functions and the like (which it is); I didn't notice the "arg" parameter in CS1.
    +1
  • Thanks DJAMS, but i'm not clear on how this works. This is what i've done.

    CS1 =SCRIPT/FILENAME= C:\EXCEL DATA\EXCEL LOOP NV.BAS
    FUNCTION/Main,SHOW=YES,ARG1=WO,,
    STARTSCRIPT/
    ENDSCRIPT/

    My variable is just WO.

    xlSheet.Range("D1").Value = ARG1 = WO

    All i get is word TRUE in cell D1.

    The script modification you showed is just a pup up window. Or am i missing something???

    Thanks for your help.
  • In your script you would have, at the top;
    Sub Main (strVariable As String)

    So basically every time you run this script, and pass a variable to it (by using the ARG thingy) it will set the VB variable strVariable to that value.
    In your VB file you would use the strVariable variable, which would be the work order.

    And, of course, don't forget the End Sub

    EDIT:
    So I think it would look something similar to

    Sub Main (strVariable As String)
    [I]Code involving the excel stuff...[/I]
    
    xlSheet.Range("D1").Value=strVariable
    
    [I]Probably more code involving excel..[/I]
    
    End Sub
    
  • From another thread ....




    You can get vb.net express for free, but .net is a step change from vb scripts, although it might get you started with Object Orientated Programming.

    Also there is VBA (Visual Basic for Applications) contained within MS Office - (Alt+F11) opens up the Development Environment.

    (I still use this to browse the object model for PC-Dmis.)


    Getting your head around Objects is kind of key, it's a gradual process but it's where you need to head.


    I think PC-Dmis automation is actually quite a good learning resource as you can apply stuff to what you already know.


    i.e.

    Dim pcapp as Object

    '(Dim is the key word used to declare a variable in VB, it's like ASSIGN in PC-Dmis
    'In this case we're declaring pcapp as an Object Variable, unlike a normal variable which will typically store a bit of information, an object variable represents an object, from which we can access its properties, methods and functions
    'More on this in a minute

    Set pcapp = CreateObject("pcdlrn.application")

    'This creates an object, in this case it creates an object representing the pcdmis application. You could also create an Excel "excel.application" or a Word "winword.application" objetct in order to control either of those bits of software
    'You typically only use the CreateObject function to get hold of the top-level object like the application itself.

    'Once we've got our claws into the main application we can do lots of stuff.

    Dim pcpart as Object

    'decalre another Object Variable

    Set pcpart = pcapp.activepartprogram

    'set its value to the active part program - we now have our claws into the active part program

    'from here we can do more stuff

    msgbox(pcpart.name)

    'msgbox is like an operator comment. we're going to display the Name property of the active part program

    'we could also access some of the part programs methods like close, quit, or save (pcpart.close, pcpart.quit, pcpart.save)

    'More often than not we're going to want to do something with the commands within the program - guess how we do that?
    'That's right, we create another object to represent the programs commands

    Dim cmds as Object
    Set cmds = pcpart.commands

    'again we can access the commands properties (commands is a collection of individual commands)

    msgbox(cmds.count)

    'Count is the number of commands in the collection

    'or we can step through the commands and do stuff

    Dim cmd as Object

    'This is going to represent each individual command in the program, one at a time

    for each cmd in cmds

    'for each is a looping technique, so for each command object, in the commands collection
    msgbox(cmd.id)
    'display the ID property

    next
    'move on the the next command


    'There are lots of useful functions that allow us to target certain type of commands


    for each cmd in cmds


    if cmd.isdimension then

    'Will only return TRUE if the command is a dimension command, the code within this IF statement will process only dimension type commands, it's no use me asking for the Measured property of an alignment - it doesn't exist

    msgbox(cmd.dimensioncommand.meas)

    'So we know this is a dimension command, we can then access the dimensioncommand properties and methods
    'This will display the measured value for each dimension in the commands

    end if

    next


    Right, that's all I've time for but it might give you an idea/get you started.

    ​​​​​​​