Jump to content

Read and set formatted text from inifile


Recommended Posts

Hello, 

I'm trying to create a little GUI which informs a user about an available Update. I need to have this in different languages. I read the different language parts from an inifile. However, the @crlf part is displayed as plain text in my label and I find no workaround to get this to work.

This is what I need:

https://picload.org/view/dciiorgg/capture.png.html

And this I get:

https://picload.org/view/dciiorgr/capture2.png.html

 

Any help would be kindly appreciated!

Manfred

 

Below the code I have so far and the inifile I read from:

#Region Main ; =====================================  MAIN  ==========================================

$sTitle = "A BIOS update is available for your computer"
$sMsg = "This update fixes errors and security problems of your computer. You should install the update as soon as possible." & @CRLF & @CRLF & "Attention: The process takes up to 10 minutes. Your system will be restarted automatically. Turning it off before completing this reboot may result in system errors!"  & @CRLF & @CRLF & "Save your work before continuing!"
$sInstall = "Install now"
$sPostpone = "Postpone"
$pngLogoBIOS = ".\bin\LogoBIOS.png"
$iniMsgBoxText = ".\MsgBoxText.ini"


; Read-in the text for the message according to the user language
$UserLanguage = _GetLanguage()
$UserLanguage = "German"
$aMsgBoxText = IniReadSection($iniMsgBoxText, $UserLanguage)
If not @error Then
    $sTitle = $aMsgBoxText[1][1]
    $sMsg = $aMsgBoxText[2][1]
    $sInstall = $aMsgBoxText[3][1]
    $sPostpone = $aMsgBoxText[4][1]
EndIf

; ===== GUI ======
$hGUI = GUICreate($sTitle, 650, 380, -1, -1, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)
_GUICtrlCreateGIF($pngLogoBIOS, '', 450, 40, 135, 135)
GUICtrlCreatePic($jpgBarBottom, 0, 285, 650, 65)
$lblMsg = GUICtrlCreateLabel($sMsg , 50, 45, 350, 180)
GUICtrlSetFont(-1, 11)
$btn_Install = GUICtrlCreateButton($sInstall, 50, 230, 150, 25)
GUICtrlSetFont(-1, 11)
$btn_Postpone = GUICtrlCreateButton($sPostpone, 250, 230, 150, 25)
GUICtrlSetFont(-1, 11)
GUISetState(@SW_SHOW, $hGUI)

#EndRegion Main  ; =================================  MAIN  ===========================================

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
        ;   ExitLoop

        Case $btn_Install
            Exit 0

        Case $btn_Postpone
            Exit 1

    EndSwitch
WEnd

; Retrieve the language of the operating system.
Func _GetLanguage()
    ; @OSLang and @MUILang is four characters in length, the first two is the dialect and the remaining two are the language group.
    ; Therefore we only require the language group and therefore select the two right-most characters.
    Switch StringRight(@MUILang, 2)
        Case "07"
            Return "German"
        Case "09"
            Return "English"
        Case "0a"
            Return "Spanish"
        Case "0c"
            Return "French"
        Case "16"
            Return "Portuguese"

        Case Else
            Return "English"

    EndSwitch
EndFunc   ;==>_GetLanguage

 

MsgBoxText.ini

Link to comment
Share on other sites

You can use something like the following:

Opt("ExpandVarStrings", 1)
$sMsg = "This update fixes errors and security problems of your computer. You should install the update as soon as possible.@CRLF@@CRLF@Attention: The process takes up to 10 minutes. Your system will be restarted automatically. Turning it off before completing this reboot may result in system errors!@CRLF@@CRLF@Save your work before continuing!"
Opt("ExpandVarStrings", 0)
MsgBox(4096, "", $sMsg)

 

Link to comment
Share on other sites

you are going to have to alter your GUI to display the 3 different paragraphs in 3 different places, then remove the quotation marks and CRLF from your ini

If @error Then
    MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!")
EndIf

"Yeah yeah yeah patience, how long will that take?"  -Ed Gruberman

REAL search results  |  SciTE4AutoIt3 Editor Full Version

Link to comment
Share on other sites

Thanks for your replies.

@Subz: I already tried this but it doesn't work. It works perfectly when I assign the string to my variable as I already do at the beginning of my script. But as soon as I get the info from inireadsection it is 'misinterpreted' unfortunately. Then it seems to be just a long string....

@alienclone: Yeah, I was thinking about this as well. Just hoped the is an other possibility to get around.

Link to comment
Share on other sites

I don't think you used it correctly, because it works fine for me, did you change your variables to @CRLF@@CRLF@ and remove the quotes as I did in the example above?

PS: With the code above you don't actually have to use Opt("ExpandVarStrings", 0).

Also if you don't want to use that method then you can use:

$sMsg = Execute($aMsgBoxText[2][1])

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...