hexagon logo

Default Radio Button Selection by Variable Value

I tried looking for this on the forum and found bits and pieces of the information I needed to figure it out. So I am posting this here to try to consolidate things.

Task: Changing the Default Radio Button based on previous runs selection

Program Code:
INPUT      =LABEL/
            ASSIGN/OPERATOR="XXX - Place Holder"
            ASSIGN/JOB="XXXXX"
            ASSIGN/SAMP=""
            ASSIGN/SHIFT="3rd"
            ASSIGN/FIXTURE="NO"
            ASSIGN/PROBE="NO"
            ASSIGN/PROG="NO"
            ASSIGN/CAL="NO"
            ASSIGN/MACHINE=""
Operator_Input=SCRIPT/FILENAME= C:\PC-DMIS\4_3\BASIC SCRIPTS\BASIC INPUT.BAS
            FUNCTION/Main,SHOW=NO,,
            STARTSCRIPT/

Basic Script Section:
'--------
'This sets the later used value as a string
Dim Shift As String 
'--------
'This sets the previous used value from the variable in the program
Set ShiftCheck    = PCDPartProgram.GetVariableValue ("SHIFT") 
'--------
'This sets the String value to a value
Shifty      = ShiftCheck.StringValue
'--------
'This controls the specific Radio Button Value based on the pulled Value
Select Case Shifty
  Case ""
Check = -1 'Clears the Radio Button Selections
  Case "1st"
Check = 0 'First Radio Button in Group
  Case "2nd"
Check = 1 'Second Radio Button in Group
  Case "3rd"
Check = 2 'Third Radio Button in Group
  End Select 
'--------
'This is the section used in the Dialogue for the Button
'Box & Buttons & Text For Shift Selection
GroupBox              5,55,130,25
  Text                10,65,25,12, "Shift # :"
    OptionGroup .grp1
      OptionButton 40,64,22,12, "1st", .option1
      OptionButton 65,64,22,12, "2nd", .option2
      OptionButton 90,64,22,12, "3rd", .option3
'--------
'This is the call out at the end of the Dialogue to control the Radio Button Group Value
Dialg.grp1 = Check
'--------
'Section to control the Radio Button Selected for this execution
'Controls shift Selection
    Select Case Dialg.grp1
      Case 0
        Shift = ("1st")
      Case 1
        Shift = ("2nd")
      Case 2
        Shift = ("3rd")
    End Select
'--------
'Command to place the new selection into the program
 If Cmd.GetText(DEST_EXPR,0) = "SHIFT" Then
      bln = Cmd.PutText("""" + Shift + """", SRC_EXPR, 0)
        Cmd.ReDraw
    End If 


That is each basic step. If it needs to be broke down more say something and I will help out.
  • It seems that you have left some essential parts of the script out...?
  • Hey look an example of what I am talking about........ Rolling eyes

    '  Rploughe 2014
    'Example of using a Radio selection In a dialogue
    'Uses Variable In program "SHIFT"
    'Script must be placed below variable, because of the Get.VariableValue
    'Variable will only update upon execution of the program
    
    
    Sub Main()
    Dim PCDApp, PCDPartPrograms, PCDPartProgram
    Dim PCDCommands, PCDCommand As Object
    Dim Shift As String
    
    
    'Creat PC-Dmis Commands
    Set PCDApp = CreateObject("PCDLRN.Application")
    Set PCDPartProgram = PCDApp.ActivePartProgram
    Set PCDCommands = PCDPartProgram.Commands
    
    
    'Pull In Variable Value from Program
    Set ShiftCheck    = PCDPartProgram.GetVariableValue ("SHIFT")
    
    
    'Assigns Variable String Value To an item
    Shifty      = ShiftCheck.StringValue
    
    
    'Controls which Button will be highlighted off of pulled value
    Select Case Shifty
      Case ""
    Check = -1 'Clears the selections based on a no value pull, or blank
      Case "1st"
    Check = 0 'First button labeled in group
      Case "2nd"
    Check = 1 'Second button labeled in group
      Case "3rd"
    Check = 2 'Third button labeled in group
      End Select 
    
    
    'Opens Dialog For Input
    Begin Dialog DIALOG_1 50,10, 300, 200,      oOPERATORINPUT
    
    
    'Box & Buttons & Text For Shift Selection
    GroupBox              5,55,130,25
      Text                   10,65,25,12, "Shift # :"
        OptionGroup .grp1 '<---- Group controlled by current selection process, other groups may be used
          OptionButton 40,64,22,12, "1st", .option1 'Noted as a selection value of 0
          OptionButton 65,64,22,12, "2nd", .option2 'Noted as a selection value of 1
          OptionButton 90,64,22,12, "3rd", .option3 'Noted as a selection value of 2
    
    
    'Ok And Cancel Buttons 
      OKButton       165,180,50,15
      CancelButton 225,180,50,15
     End Dialog
    
    
    'Code Begins
    Dim Dialg As DIALOG_1
    
    
    'Shift Selection based On pulled In value
    Dialg.grp1 = Check '<-- Uses item "Check" to set value upon execution
    
    
    button1 = Dialog(Dialg)
    Dim Progtype As String
      If button1 = 0 Then
        Progtype= "END"
      Else
    
    
     'Controls shift Selection For Output
        Select Case Dialg.grp1 '<---- pulls out selected value upon closing dialogue window
          Case 0
            Shift = ("1st")
          Case 1
            Shift = ("2nd")
          Case 2
            Shift = ("3rd")
        End Select
    End If
    
    'Begins the Variable assignment To PCDMIS For Each COMMAND
    For Each PCDCommand In PCDCommands
      If PCDCommand.Type = ASSIGNMENT Then
        If PCDCommand.GetText(DEST_EXPR,0) = "SHIFT" Then
          bln = PCDCommand.PutText("""" + Shift + """", SRC_EXPR, 0)
            PCDCommand.ReDraw
        End If
      End If
    Next Cmd
    
    
    'Cleanup
    Set PCDCommands = Nothing
    Set PCDCommand = Nothing
    Set PCDPartProgram = Nothing
    Set PCDApp = Nothing
    
    
    End Sub
    


    Just remember you have to execute the script with the variable assignment. Variable will only update upon execution of program. I checked to make sure this worked prior to posting. So have fun with it.
  • Thank you for saying something. I just cut and pasted code from my ridiculously long long one. Didn't think about making a functional one.
  • Works fine here.
    Just having a play and seeing if I can adapt for our needs.

    Thanks
  • If it needs to be broke down more say something and I will help out.???
  • Meaning.... if you need me to break it down step by step, or if you have any questions I can offer some clarity. I'm confused as to why you posted what you did.