Jump to content
Sign in to follow this  

problem with switch statement

Recommended Posts


maybe someone can help me out here. the code does not execute in the matter i expect. program excutes line 44, $nMsg = GUIGetMsg(). then it jumps past the switch statement and the case statements and goes to line 49. anyone see what i'm doing wrong. this is my first switch statement, i'm not impressed.

it should never even reach line 49, $nMsg = 0.

#include "Dbug.au3"

Global $CurrentLink

#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=

$Form1 = GUICreate("Form1", 615, 438, 192, 124)

$Label1 = GUICtrlCreateLabel("Label1", 144, 48, 84, 17)

$Radio1 = GUICtrlCreateRadio("Local", 320, 40, 97, 25)

$Radio2 = GUICtrlCreateRadio("Server", 312, 88, 105, 33)


#EndRegion ### END Koda GUI section ###

dim $file

dim $line

dim $Ans

$file = FileOpen("C:\mydata.txt", 0)

; Check if file opened for reading OK

;If $file = -1 Then

; MsgBox(0, "Error", "Unable to open file.")

; Exit


;While 1

; $line = FileReadLine($file)

; If @error = -1 Then ExitLoop

; $Ans =StringInStr($line,"C:\dbaseform")

; if $Ans = 0 Then ;not fould, must be set to the remote server

; $CurrentLink = "server"

; GUICtrlSetData($Label1,"Remote Server")

; Else

; GUICtrlSetData($Label1,"Local")

; EndIf

; MsgBox(0, "Line read:", $line)



dim $nMsg

Dim $LinkChanged

$LinkChanged = False

While 1

$nMsg = GUIGetMsg()

Switch $nMsg



Case $nmsg = $radio1

$CurrentLink = "server"

$LinkChanged = True

Case $nmsg = $radio2

$CurrentLink = "local"

$LinkChanged = True


if $LinkChanged = true Then


$LinkChanged = False



Func ChangeLink($mystring)

if $mystring = "local" Then

$Ans = FileCopy("C:\mydatalocal.txt","C:\mydata.txt",1)

if $Ans = 0 Then ;failure

MsgBox(0,"ERROR","Unable to Write to Mydata.txt")




if $Ans = 0 Then ;failure

MsgBox(0,"ERROR","Unable to Write to Mydata.txt")




test 1.au3

Share this post

Link to post
Share on other sites


Welcome to the AutoIt forum. :mellow:

this is my first switch statement

So I suppose you looked carefully at the Help file to determine the correct syntax to use?

Switch works like this:

Switch <expression>
    Case <value>

as opposed to Select which works like this:

    Case <expression>

So when we look at your script we see:

Switch $nMsg
    Case $nMsg = $Radio1

Can you see why it is not working now? :)


P.S. When you post code, please use Code tags. Put [autoit] before and [/autoit] after your posted code - then you get the nice scrollabel boxes. :)

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Share this post

Link to post
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

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.