Jump to content

Function problem with GUI


Appie78
 Share

Recommended Posts

Hi all,

I'm having some problems with starting a function for the second time thru a while loop.

The first time the function works fine, if I want to start it for the second time nothing happens!

Does anyone have any idea's?

Thanks

Electron microscopes rule!!!
Link to comment
Share on other sites

This is the code!!

CODE

While 1

$msg = GUIGetMsg()

Select

Case $msg = $holder1

Holder1()

Case $msg = $recall

Recall()

Case $msg = $Version

MsgBox(0, "Custom Service", "Version 1.4.5")

Case $msg = $Help

File()

Case $msg = $GUI_EVENT_CLOSE or $msg = $exit

Exit

EndSelect

WEnd

Func Recall()

$Recall = FileOpen("c:\Positions.log", 0);

If $recall = -1 Then

Return MsgBox(0, "Error", "No file with positions.")

Exit

EndIf

$line = FileRead($recall)

$avArray = StringSplit($line, ";",1);

_ArrayTrim($avArray, 2, 0, 2)

_ArrayDisplay($avArray)

$tel = UBound($avArray)

$coor = $tel - 2; posities - 2.

If $coor < 3 Then

Return MsgBox(0,"JEOL Custom Service", "No data in file or corrupted file.")

Exit

EndIf

For $i = 1 To $coor Step 3

$x = $avArray[$i]

$y = $avArray[$i+1]

$r = $avArray[$i+2]

WinActivate("JEOL Scanning Electron Microscope")

Sleep(200)

ControlClick ("JEOL Scanning Electron Microscope", "", 95 , "left" , 1 , 20 , 20); view25

Sleep(1000)

ControlClick("JEOL Scanning Electron Microscope", "", 89, "left", 1, 20, 20)

Sleep(500)

WinActivate("Stage Control")

Sleep(200)

send("!p")

Send($x)

Send("{Tab}")

Send($y)

Send("{Tab}")

Send($r)

Sleep(200)

ControlClick("Positioning", "", 1, "left", 1, 20, 20)

Sleep(1000)

ControlClick ("JEOL Scanning Electron Microscope", "", 95 , "left" , 1 , 20 , 20)

Sleep(500)

If $i = $coor - 2 Then

$msg = MsgBox(0,"JEOL Custom Service", "Finished")

Else

$msg = MsgBox(1, "JEOL Custom Service", "Continue or Cancel?")

If $msg = 2 Then

ExitLoop

Else

MsgBox(0,"JEOL Custom Service", "Moving to next position",3)

EndIf

EndIf

Next

FileClose($Recall)

EndFunc

Electron microscopes rule!!!
Link to comment
Share on other sites

  • Moderators

Pokerface,

Although you have not shown your GUI creation code, from the While...WEnd loop, it is obvious that you created a control in your GUI and stored its ControlID in variable $recall. Becasue it was created in the main script and not in a function, it is automatically Global in scope.

Then in your Recall() function, you reuse the same variable to hold the file handle when you open c:\Positions.log. So when you go back to the While...WEnd loop, the value in $recall is no longer the ControlID and GUIGetMsg is most unlikely to produce the new value!

Solution: Set the $recall variable in the function as a Local variable - or better still, do not reuse variable names!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

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

 

Link to comment
Share on other sites

Pokerface,

Although you have not shown your GUI creation code, from the While...WEnd loop, it is obvious that you created a control in your GUI and stored its ControlID in variable $recall. Becasue it was created in the main script and not in a function, it is automatically Global in scope.

Then in your Recall() function, you reuse the same variable to hold the file handle when you open c:\Positions.log. So when you go back to the While...WEnd loop, the value in $recall is no longer the ControlID and GUIGetMsg is most unlikely to produce the new value!

Solution: Set the $recall variable in the function as a Local variable - or better still, do not reuse variable names!

M23

You where spot on!!!

Thanks I was using $recall in my GUI aswell!!!

Thanks again,

Pokerface

Electron microscopes rule!!!
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...