hexagon logo

Help: Puttext method Problem

Hi,

Since our operators dont seem to be able to enter SNs correctly, I'm trying to program a dropdown menu fed with a textfile that contains all the SNs.
The Dropdown is made in Basic and reads out everything in the textfile...
So far so good...
When I try to transfer the data to PCDMIS, it doesnt work anymore (most probably because I'm doing something wrong)...


This is my code inside PCDMIS:

ZUWEISEN/DROP_SEL=""
CS1 =SKRIPT/DATEINAME= U:\LAURENT DESPINEUX\PC DMIS\AUTOMATED\SUPERDYNAMIC\DROPDOWN HYPERDYNAMIC (FROM FILE).BAS
FUNKTION/Main,EINBLENDEN=JA,,
STARTSKRIPT/
ZUWEISEN/DROP_SEL=0
ENDESKRIPT/
KOMMENTAR/PROT,
"" + DROP_SEL​



Dim PCDDmisApp As Object
Dim PCDDmisPart As Object
Dim PCDDmisCommands As Object
Dim PCDDmisCommand As Object
Dim DROP_SEL As String

Sub Main ()



Set PCDDmisApp = CreateObject("PCDLRN.Application")
Set PCDDmisPart = PCDDmisApp.ActivePartProgram
Set PCDDmisCommands = PCDDmisPart.Commands

Dim Command As Object

Let Count = "1"
Open "U:\Laurent Despineux\PC DMIS\Automated\Superdynamic\list.txt" For Input As #1
Do While Not EOF(1)
       Line Input #1, Textline
       Count = Count + 1
Loop
Close #1

Dim MyList$ (25)

Let C= "0"
Open "U:\LAURENT DESPINEUX\PC DMIS\AUTOMATED\SUPERDYNAMIC\list.txt" For Input As #1
Do While Not EOF(1)
       Line Input #1, Textline
               MyList(C) = LEFT(Textline, 10)
       C = C + 1
Loop
Close #1

Begin Dialog DialogName1 200,184, "Part Number Selection Dialog Box"
Text 10,10,88,22, "N auswählen:"
DropListBox 42,76,108,186, MyList$(), .DropList1$
CancelButton 42,108,40,12
OKButton 90,108,40,12
End Dialog


Dim Dlg1 As DialogName1

'       Dlg1.DropList1  =  0 this shows item (0) default In the window In the drop down list
'       You can change it To show Any item On top from Mylist()
Dlg1.DropList1  =  0

'       If cancel button is selected, Exit Sub
Button = Dialog(Dlg1)
If Button = 0 Then Exit Sub
  
Vari = Dlg1.DropList1
Set PCDDmisCommand = PCDDmisCommands.Add(ASSIGNMENT,True)
PCDDmisCommand.Marked = True
retval = PCDDmisCommand.PutText("DROP_SEL",DEST_EXPR,0)
retval = PCDDmisCommand.PutText(mylist$(Vari),SRC_EXPR,0)
MsgBox mylist$(Vari)
End Sub

​


If i'm putting a Value manually (for instance "12345") instead of the variable (mylist$(Vari)) then it's working...
Additional information: the "ZUWEISEN/DROP_SEL=0" contains the Value chosen in the dropbox when the script is finished... unluckily I cannot use it since when i check it's content with a usercomment, it is "0"
Any ideas?

  • we had a similar problem with operators. I cant help you with the code but we now print out QR codes with the serial numbers and use a barcode scanner for them to scan the serial number into a trace field. we haven't had a serial number entered wrong for the last 3 years since we implemented it.
  • Good day,

    your problem can be solved relatively easily:​


    you define a DropListBox called "DropList1$"
    DropListBox 42,76,108,186, MyList$(), .DropList1$

    but call for "Vari = Dlg1.DropList1"

    If you don't have "Option Explicit" at the beginning, it creates the objects and variables automatically and you don't get an error message, but you quickly overlook a typo


    at least that's how it works for me
    (Caution, I did not test the file reading)
    (why are you opening the file twice?)​

    Option Explicit
    
    Sub Main()
      ' Dim something -----
        Dim PCDDmisApp As Object
        Dim PCDDmisPart As Object
        Dim PCDDmisCommands As Object
        Dim PCDDmisCommand As Object
        Dim DROP_SEL As String
        Set PCDDmisApp = CreateObject("PCDLRN.Application")
        Set PCDDmisPart = PCDDmisApp.ActivePartProgram
        Set PCDDmisCommands = PCDDmisPart.Commands
        Dim Command As Object
        
        Dim vSNRList(25) As String
        Dim vSNRLine As String
        Dim vSNRCount As Integer
        Dim vButton As Integer
        Dim retval
    
      ' count something ?
        'Let count = "1"
        'Open "U:\LAURENT DESPINEUX\PC DMIS\AUTOMATED\SUPERDYNAMIC\list.txt" For Input As #1
        'Do While Not EOF(1)
        '   Line Input #1, Textline
        '   count = count + 1
        'Loop
        'Close #1
    
    
      ' Get list
        'Let C = "0"
        'vSNRCount = 0
        'Open "U:\LAURENT DESPINEUX\PC DMIS\AUTOMATED\SUPERDYNAMIC\list.txt" For Input As #1
        'Do While Not EOF(1)
        '  Line Input #1, vSNRLine
        '  vSNRList(vSNRCount) = Left(vSNRLine, 10)
        '  vSNRCount = vSNRCount + 1
        'Loop
        'Close #1
        vSNRList(0) = "test0"
        vSNRList(1) = "test1"
        vSNRList(2) = "test2"
    
    
      ' Dim Dialog
        Begin Dialog DialogName1 200,184, "Part Number Selection Dialog Box"
          Text 10, 10, 88, 22, "N auswählen:"
          DropListBox 42, 76, 108, 186, vSNRList(), .DropList1
          CancelButton 42, 108, 40, 12
          OKButton 90, 108, 40, 12
        End Dialog
        Dim Dlg1 As DialogName1
        
      ' start Dialog
        Dlg1.DropList1 = vSNRList(0)
        vButton = Dialog(Dlg1)
        
        If vButton = 0 Then Exit Sub
        
        Set PCDDmisCommand = PCDDmisCommands.Add(ASSIGNMENT, True)
        PCDDmisCommand.Marked = True
        retVal = PCDDmisCommand.PutText("DROP_SEL", DEST_EXPR, 0)
        retVal = PCDDmisCommand.PutText(vSNRList(Dlg1.DropList1), SRC_EXPR, 0)
        
        'MsgBox MyList$(Vari)
        'MsgBox vSNRList(Dlg1.DropList1)
    End Sub​
    
  • Good point. We do it for engravings at the moment. It's something i will definitely consider (and if not for this part, maybe for others!)
  • To be honest: I dont know. It's some old code i just found and wanted to reuse.
    One opening of the file would be enough of course.
    Oh man... these typos...

    Thank you! I'll change an see if it's working :-)

  • I adapted a little but still have the same problem.
    It shows me the Serial Number I selected inside the code that embeds the script...
    But when i try "to do something" inside PCDMIS it shows a 0 Value.
    Pretty sure, that's why it's colored in red too.

    When i replace the Values in my list with

    01234
    01235
    01236
    01237
    01238
    01239

    and i select "01239" then it's all good and works...

    I now noticed, that no matter what I type into my list, only the last item in the list works inside of PCDMIS.
    It also needs to be a purely numeric value (anything else and it's red again).
  • I changed this: vSNRList(vSNRCount) = Cint(vSNRLine )
    Now it's working (for numeric values). Anybody knows if it's possible to pass string values from basic to PCDMIS?
    I have a feeling it's only working for numerics...
  • Good day,

    * Cint(vSNRLine)
    please don't do that, because that will generate an error as soon as you have any character other than a number. You should always treat "serial numbers" as a string.
    - if at all then please like this: CStr(vSNRLine)

    * now to your second problem:
    if pcDMIS finds a character string that doesn't have a "..." then it thinks it's talking about a float or int.
    A conversion to this format is carried out internally.
    This conversion fails as soon as he finds a letter (therefore it is displayed in red because of the "SN")
    - if you want the character string to always be treated as a string also in pcDMIS you must put this in ".

    you only have to instruct your basic script to set the " additionally​.
    for example like this:
    retVal = PCDDmisCommand.PutText(Chr(34) + vSNRList(Dlg1.DropList1) + Chr(34), SRC_EXPR, 0)
    
  • "I now noticed, that no matter what I type into my list, only the last item in the list works inside of PCDMIS"
    - Can you please elaborate further or please post your code.
  • Thank you!
    That's been the problem all along Smiley
    I did try to use numerical values only and it still didn't work, so i thought it had to be something else.
    I Didnt think it could be solved by just adding the "..." in Basic.
    That's way better then only beeing able to use numeric values.