Jump to content

If,then,else does not work in variables?


 Share

Recommended Posts

Hello Guys. I want to create a little programm where you can make messageboxes and save them (for people who dont know how to do that themself :3). I have some kinda radio field buttons to decide what icon the messagebox should show. With the inputboxes, i do it like this:

 

            $FinalTitle = GUICtrlRead($Title)
            $FinalMessage = GUICtrlRead($Message)
            MsgBox($FinalIcon,$FinalTitle,$FinalMessage)

 

But for some reason the one with the icon does not work properly: 

 

            $FinalIcon = If GUICtrlRead($Error) = 1 Then
             <syntax error>
            GUICtrlSetData($FinalIcon,16)

 

 

Please help me, im a noob :D

Link to comment
Share on other sites

  • Moderators

@ju4711 it is a bit difficult to ascertain what you are trying to do from such a small non-runnable snippet. You appear to be trying to read from a control on your GUI named $Error, but you're leaving us to guess whether this is an input, a combo box, etc. How about helping us help you and posting your code, or at least a runnable reproducer? ;)

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Well , youre right. I will just copy and paste the whole script in here:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("My MsgBox", 654, 221, 174, 117)
$Exit = GUICtrlCreateMenu("&Exit")
$Credits = GUICtrlCreateMenu("&Credits")
$Help = GUICtrlCreateMenu("&Help")
$Generate = GUICtrlCreateButton("Generate", 248, 128, 155, 49)
$Error = GUICtrlCreateRadio("Error (Icon)", 32, 48, 115, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$Warning = GUICtrlCreateRadio("Warning (Icon)", 32, 96, 115, 17)
$Information = GUICtrlCreateRadio("Information (Icon)", 32, 144, 115, 17)
$Title = GUICtrlCreateInput("Type in your title here.", 248, 48, 153, 21)
$Message = GUICtrlCreateInput("Type in your message here.", 248, 88, 153, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

#NoTrayIcon

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Generate
            $FinalIcon = If GUICtrlRead($Error) = $GUI_CHECKED  Then
                GUICtrlSetData($FinalIcon,16)
                GUICtrlRead($FinalIcon)
            $FinalTitle = GUICtrlRead($Title)
            $FinalMessage = GUICtrlRead($Message)
            MsgBox($FinalIcon,$FinalTitle,$FinalMessage)

 

 

Okay, i hope you can work with that xd ^^. $Error for example is just the radio field button to choose an icon and $FinalError is that what comes out from "GuiCtrlRead"

Link to comment
Share on other sites

  • Moderators

Better, but still confusing. You have an IF with no EndIF. So, if $Error is checked, do you want to perform one of the actions below, or all of them?

GUICtrlSetData($FinalIcon,16)
GUICtrlRead($FinalIcon)
$FinalTitle = GUICtrlRead($Title)
$FinalMessage = GUICtrlRead($Message)
MsgBox($FinalIcon,$FinalTitle,$FinalMessage)

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

oh. Well, if $Error is checked, the programm should change the data of $FinalIcon to 16 so that the msgbox showes the right icon.

I guess that would mean... After the "GuiCtrlRead($FinalIcon)" there should be an Endif. (Im not sure tbh :/)

Link to comment
Share on other sites

ju4711,

Is this what you are trying to do...?

; *** Start added by AutoIt3Wrapper ***
#include <GUIConstantsEx.au3>
; *** End added by AutoIt3Wrapper ***

#include <WindowsConstants.au3>

#AutoIt3Wrapper_Add_Constants=n

#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("My MsgBox", 654, 221, 174, 117)
$Exit = GUICtrlCreateMenu("&Exit")
$Credits = GUICtrlCreateMenu("&Credits")
$Help = GUICtrlCreateMenu("&Help")
$Generate = GUICtrlCreateButton("Generate", 248, 128, 155, 49)
$Error = GUICtrlCreateRadio("Error (Icon)", 32, 48, 115, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$Warning = GUICtrlCreateRadio("Warning (Icon)", 32, 96, 115, 17)
$Information = GUICtrlCreateRadio("Information (Icon)", 32, 144, 115, 17)
$Title = GUICtrlCreateInput("Type in your title here.", 248, 48, 153, 21)
$Message = GUICtrlCreateInput("Type in your message here.", 248, 88, 153, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

#NoTrayIcon

Local $finalicon

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Generate
            If GUICtrlRead($Error) = $GUI_CHECKED Then $finalicon = 16
            If GUICtrlRead($Warning) = $GUI_CHECKED Then $finalicon = 48
            If GUICtrlRead($Information) = $GUI_CHECKED Then $finalicon = 64
            $FinalTitle = GUICtrlRead($Title)
            $FinalMessage = GUICtrlRead($Message)
            MsgBox($finalicon, $FinalTitle, $FinalMessage)
    EndSwitch
WEnd

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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...