hexagon logo

IF_GOTO/C1.INPUT and multiple languages...

OK, I'm stumped (not really, but I would like a general solution).

If I have an IF_GOTO/C1.INPUT == "YES" in my program, it will break when I change PC-DMIS to Swedish.

So, I can write IF_GOTO/(C1.INPUT == "YES") or (C1.INPUT == "JA") to make it work in English and Swedish (and some more, like German).

But how do I write to have it work in the current language PC-DMIS is set to, whatever language that is?

In the Report Editor there's a function LOADSTR(xyz) which can get the current translation of string #xyz, but that doesn't work in a part program.
  • $$ NO,
                Initialise B_RES (aka Boolean Result)
                ASSIGN/B_RES=0
    C1         =COMMENT/YESNO,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
                Is NinjaBadger a genius?
    $$ NO,
                Get the comment type (i.e. YESNO) as a string
                ASSIGN/COMTYPE=GETTEXT(190,0,{C1})
    $$ NO,
                IF left part of that (as long as the number of charachters in the result) = the user selection, then it's a YES
                IF/LEFT(COMTYPE,LEN(C1.INPUT))==C1.INPUT
                ASSIGN/B_RES=1
                END_IF/
                COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
                B_RES



    I'm making the assumption it's always YESNO in that order, i.e. it's not NONOUI in French or something daft.

    Now we can have a boolean 1/0 result instead of a language specific!


    Edited as I realised I didn't need to use GETCOMMAND (YESNO command has an ID)
    Also I'd used "Comment Type" (language specific) as an argument for gettext instead of 190
  • NinjaBadger, that's a quite beautiful solution - although more or less the same approach as I took in my 'hackish' solution!

    I can see two problem with yours, though - if a language has a word for NO beginning with the word for YES (as in YES and YESNOT), or if the PC-DMIS translation calls the function ASK_FOR_YES_OR_NO in some language...

    (none of them apply to my hack)
  • NinjaBadger, that's a quite beautiful solution - although more or less the same approach as I took in my 'hackish' solution!

    I can see two problem with yours, though - if a language has a word for NO beginning with the word for YES (as in YES and YESNOT), or if the PC-DMIS translation calls the function ASK_FOR_YES_OR_NO in some language...

    (none of them apply to my hack)


    I understand your first point can you explain the second point a bit more?
  • I meant that the YESNO part of COMMENT/YESNO ... is available for translator abuse - it could be translated to something similar to COMMENT/ASK_FOR_YES_OR_NO ... and your code would match "ASK" or "AS"...
  • Not sure if this will help - you'll need to play around with it. It does prepend the returned value with an ampersand. Don't know if resource.dll would be better for you than strings.dll. The listing in online help doesn't seem to be complete. Entering some random numbers returned strings not listed.

    ASSIGN/V1=GETSETTING("LangStr(-9)")  'returns "&Yes"
    ASSIGN/V1=GETSETTING("LangStr(-10)")  'returns "&No"


    (from online help under String Functions):
    "LangStr(<Number or ID>Wink" – Returns a string from PC-DMIS's resources in the current language from a resource ID number or from one of these IDs:
    "Yes", "No", "Oper", "Rept", "Input", "Doc", "YesNo", "Readout", "Internal", "External", "Rect ", "Polr ", "Out", "In", "Least_Sqr", "Min_Sep", "Max_Insc", "Min_CircSc", "Fixed_Rad", "Workplane", "Xaxis", "YAxis", "ZAxis", "Xplus", "Xminus", "YPlus", "YMinus", "ZPlus", "ZMinus", "Point", "Plane", "Line", "Circle", "Sphere", "Cylinder", "Round_Slot", "Square_slot", "Cone", or "None".

    If the value you use is a positive number, PC-DMIS pulls the string from its resource.dll file. If you use a negative number, PC-DMIS pulls the string from its strings.dll file (the strings table).
  • I dug a little deeper and found that -276 = "Yes" and -287 = "No". You can generate a list with the code below which creates the commands in the Edit Window. Running will give you a report with the number/string pairs. Don't know how long this list is (I stopped at 1000). This negative loop is for "strings.dll".
    Sub GetSettingLangStr()
        Dim oApp As PCDLRN.Application
        Dim oPart As PCDLRN.PartProgram
        Dim oCmds As PCDLRN.Commands
        Dim oCmd As PCDLRN.Command
        Dim i As Long
        Dim bRet As Boolean
        Dim sStr As String
        Dim Result As Variant
        
        On Error GoTo ErrCatcher
        
        Set oApp = CreateObject("PCDLRN.Application")
        Set oPart = oApp.ActivePartProgram
        Set oCmds = oPart.Commands
        
        oApp.Visible = False
        For i = -1 To -1000 Step -1
            
            Set oCmd = oCmds.Add(ASSIGNMENT, True)
            oCmd.Marked = True
            bRet = oCmd.PutText("V4", DEST_EXPR, 0)
            sStr = "GETSETTING(" & Chr(34) & "LangStr(" & i & ")" & Chr(34) & ")"
            bRet = oCmd.PutText(sStr, SRC_EXPR, 0)
            
            Set oCmd = oCmds.Add(SET_COMMENT, True)
            oCmd.Marked = True
            bRet = oCmd.PutText("", ID, 0)
            bRet = oCmd.SetToggleString(2, COMMENT_TYPE, 0)
            sStr = Chr(34) & i & ":   " & Chr(34)
            bRet = oCmd.PutText(sStr, COMMENT_FIELD, 1)
            sStr = Chr(34) & i & ":   " & Chr(34) & "+V4"
            Result = oCmd.SetExpression(sStr, COMMENT_FIELD, 1)
            
        Next i
        oApp.Visible = True
        oPart.RefreshPart
        
    ExitSub:
        Set oCmd = Nothing
        Set oCmds = Nothing
        Set oPart = Nothing
        Set oApp = Nothing
        Exit Sub
    ErrCatcher:
        MsgBox ("Error: " & Err.Number & vbCrLf & "Description: " & Err.Description)
        On Error GoTo 0
        Resume ExitSub
    End Sub
  • I learned today that v2014.1 has added the .INPUTVALUE property to the YES/NO comment. If the answer is YES, the INPUTVALUE=1. In the answer is NO, the INPUTVALUE=2. I am told that this should be the same in all languages, but I don't know for sure.
  • Verified. Just what I was wishing for! Great!
    (Not that I didn't manage before, but this makes programs much cleaner/safer)
  • Verified. Just what I was wishing for! Great!
    (Not that I didn't manage before, but this makes programs much cleaner/safer)


    +1