Jump to content

How to call inside function variable outside the program.


Andy2520
 Share

Recommended Posts

Dear Team,

Please go throught the below code where it went wrong . I want to use the all input variable function variable through out the script.

When i display the msg box with variable getting blank msg box .It should displaly computed function variables and user inputs as well .

Please help me .

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>

Dim $hMsg
Dim $path
Dim $test
Dim $usrname ; get the user name
Dim $mserver ;get server name
Dim $lpwd ;
Dim $Email
Dim $Empid
Dim $splitsrname
Dim $hButton
Dim $hButton2
Dim $intWindow
Dim $delwindow
Dim $hInput;Email address

$hGUI = GUICreate("Lotus Notes Auto Config", 460, 189, -1, -1)
$Empid = GUICtrlCreateLabel("Enter TCS Emp ID :", 33, 30, 140, 27)
GUICtrlSetFont(-1, 10, 800, 0)
$hLabel2 = GUICtrlCreateLabel("Enter Email Address :", 33, 64, 153, 27)
GUICtrlSetFont(-1, 10, 800, 0)
$hLabel3 = GUICtrlCreateLabel("Enter Server Name :", 33, 102, 153, 27)
GUICtrlSetFont(-1, 10, 800, 0)
$hInput = GUICtrlCreateInput("", 220, 30, 221, 27)
$hInput2 = GUICtrlCreateInput("", 220, 64, 221, 27)
$hInput3 = GUICtrlCreateInput("", 220, 102, 221, 27)
$hButton = GUICtrlCreateButton("OK", 82, 146, 96, 26)
GUICtrlSetFont(-1, 8.5, 800, 0)
$hButton2 = GUICtrlCreateButton("Cancle", 228, 146, 98, 26)
GUICtrlSetFont(-1, 8.5, 800, 0)
$hLabel4 = GUICtrlCreateLabel("(Eg.Inblrm06.tcs.com)", 42, 121, 117, 13)
$hLabel5 = GUICtrlCreateLabel("(Eg.first.last name@tcs.com )", 34, 85, 144, 17)
GUISetState(@SW_SHOW)
$hMsg = 0
While $hMsg <> $GUI_EVENT_CLOSE
    $hMsg = GUIGetMsg()
    Switch $hMsg 
            Case $hButton
            $Empid = GUICtrlRead($hInput)
            $mserver = GUICtrlRead($hInput3)
            $Email = GUICtrlRead($hInput2)
            $splitsrname1 = StringRight($mserver, 8)
            ;$splitsrname = StringTrimRight($mserver, 8)
            ;MsgBox(1,"Input details","Emp id ",(GUICtrlRead($hInput)))
            $result = StringCompare(".tcs.com", $splitsrname1)
            $splitemname = StringRight($Email, 8)
            $result1 = StringCompare("@tcs.com", $splitemname)
            If $result <> 0 or $Empid = "" Or $Email = "" Or $mserver = "" or $result1 <>0 Then
            MsgBox(0, "Warning", "Please type the all inputs in correct format " & @CRLF & "TRY AGAIN ?")
            Else
               GUIDelete($delwindow)
                Idfile()
             EndIf
             
        Case $hButton2
            ExitLoop
    EndSwitch
   ;GUIDelete($delwindow)
WEnd

Func Idfile()
    $hGUI1 = GUICreate("Lotus Notes Auto Config ", 394, 142, -1, -1)
    $hLabel1 = GUICtrlCreateLabel("Select Notes ID file ", 98, 16, 142, 27)
    GUICtrlSetFont(-1, 10, 800, 0)
    $hButton1 = GUICtrlCreateButton("Browse", 53, 92, 96, 23)
    GUICtrlSetFont(-1, 10, 800, 0)
    $hButton21 = GUICtrlCreateButton("Done", 229, 92, 95, 23)
    GUICtrlSetFont(-1, 8.5, 800, 0)
    $path = GUICtrlCreateInput("", 19, 43, 349, 27)
     GUISetState()
    $hMsg1 = 0
    While $hMsg1 <> $GUI_EVENT_CLOSE
        $hMsg1 = GUIGetMsg()
        Select
            Case $hMsg1 = $hButton1
                $File2open = FileOpenDialog("Browse", "C:\", "ID file  (*.id)") ;returns the file path
                GUICtrlSetData($path, $File2open) ;set input data
                $test = GUICtrlSetData($path, $File2open)
             Case $hMsg1 = $hButton21
                $temp= GUICtrlRead($path)
                 if $temp = "" then 
                  MsgBox(1,"Error ","ID File Location Cannot be blank")
                  GUIDelete($delwindow)
                  Idfile()
                 Else 
                  ;MsgBox(1,"ID File path",($temp))
                  EndIf
               Return
        EndSelect
    WEnd
 EndFunc   ;==>Idfile
 
 MsgBox(1,"Input details","Emp id ",$Empid)
 MsgBox(1,"Input details","Emp address ",$Email)
 MsgBox(1,"Input details","server Name",$mserver)
 MsgBox(1,"Input details","Id file path",$path)
Link to comment
Share on other sites

Thanks for your reply ,

Still no luck unable to display the inputs ouside the function .Last msg box should display the all inputs  .:( :(

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>

Global $hMsg
Global $path
Global $test
Global $mserver ;get server name
Global $lpwd ;
Global $Email
Global $Empid
Global $splitsrname
Global $hButton
Global $hButton2
Global $intWindow
Global $delwindow
Global $hInput;Email address

$hGUI = GUICreate("Lotus Notes Auto Config", 460, 189, -1, -1)
$Empid = GUICtrlCreateLabel("Enter TCS Emp ID :", 33, 30, 140, 27)
GUICtrlSetFont(-1, 10, 800, 0)
$hLabel2 = GUICtrlCreateLabel("Enter Email Address :", 33, 64, 153, 27)
GUICtrlSetFont(-1, 10, 800, 0)
$hLabel3 = GUICtrlCreateLabel("Enter Server Name :", 33, 102, 153, 27)
GUICtrlSetFont(-1, 10, 800, 0)
$hInput = GUICtrlCreateInput("", 220, 30, 221, 27)
$hInput2 = GUICtrlCreateInput("", 220, 64, 221, 27)
$hInput3 = GUICtrlCreateInput("", 220, 102, 221, 27)
$hButton = GUICtrlCreateButton("OK", 82, 146, 96, 26)
GUICtrlSetFont(-1, 8.5, 800, 0)
$hButton2 = GUICtrlCreateButton("Cancle", 228, 146, 98, 26)
GUICtrlSetFont(-1, 8.5, 800, 0)
$hLabel4 = GUICtrlCreateLabel("(Eg.Inblrm06.tcs.com)", 42, 121, 117, 13)
$hLabel5 = GUICtrlCreateLabel("(Eg.first.last name@tcs.com )", 34, 85, 144, 17)
GUISetState(@SW_SHOW)
$Empid = GUICtrlRead($hInput)
$mserver = GUICtrlRead($hInput3)
$Email = GUICtrlRead($hInput2)
$splitsrname1 = StringRight($mserver, 8)
$hMsg = 0
While $hMsg <> $GUI_EVENT_CLOSE
    $hMsg = GUIGetMsg()
    Switch $hMsg 
            Case $hButton
            $Empid = GUICtrlRead($hInput)
            $mserver = GUICtrlRead($hInput3)
            $Email = GUICtrlRead($hInput2)
            $splitsrname1 = StringRight($mserver, 8)
            ;$splitsrname = StringTrimRight($mserver, 8)
            ;MsgBox(1,"Input details","Emp id ",(GUICtrlRead($hInput)))
            $result = StringCompare(".tcs.com", $splitsrname1)
            $splitemname = StringRight($Email, 8)
            $result1 = StringCompare("@tcs.com", $splitemname)
            If $result <> 0 or $Empid = "" Or $Email = "" Or $mserver = "" or $result1 <>0 Then
            MsgBox(0, "Warning", "Please type the all inputs in correct format " & @CRLF & "TRY AGAIN ?")
            Else
               GUIDelete($delwindow)
                Idfile()
             EndIf
             
        Case $hButton2
            ExitLoop
    EndSwitch
   ;GUIDelete($delwindow)
WEnd

Func Idfile()
    $hGUI1 = GUICreate("Lotus Notes Auto Config ", 394, 142, -1, -1)
    $hLabel1 = GUICtrlCreateLabel("Select Notes ID file ", 98, 16, 142, 27)
    GUICtrlSetFont(-1, 10, 800, 0)
    $hButton1 = GUICtrlCreateButton("Browse", 53, 92, 96, 23)
    GUICtrlSetFont(-1, 10, 800, 0)
    $hButton21 = GUICtrlCreateButton("Done", 229, 92, 95, 23)
    GUICtrlSetFont(-1, 8.5, 800, 0)
    $path = GUICtrlCreateInput("", 19, 43, 349, 27)
     GUISetState()
    $hMsg1 = 0
    While $hMsg1 <> $GUI_EVENT_CLOSE
        $hMsg1 = GUIGetMsg()
        Select
            Case $hMsg1 = $hButton1
                $File2open = FileOpenDialog("Browse", "C:\", "ID file  (*.id)") ;returns the file path
                GUICtrlSetData($path, $File2open) ;set input data
                $test = GUICtrlSetData($path, $File2open)
             Case $hMsg1 = $hButton21
                $temp= GUICtrlRead($path)
                 if $temp = "" then 
                  MsgBox(1,"Error ","ID File Location Cannot be blank")
                  GUIDelete($delwindow)
                  Idfile()
                 Else 
                  ;MsgBox(1,"ID File path",($temp))
                  EndIf
               Return
        EndSelect
    WEnd
 EndFunc   ;==>Idfile
 
 MsgBox(1,"Input details","Emp id ",$Empid)
 MsgBox(1,"Input details","Emp address ",$Email)
 MsgBox(1,"Input details","server Name",$mserver)
 MsgBox(1,"Input details","Id file path",$path)

Code is here :

Link to comment
Share on other sites

  • Moderators

Aniiii,

Try using the correct syntax for the MsgBox calls:

MsgBox(1 ,"Input details", "Emp id: " & $Empid)
Putting the variable you want to display in the place of the timeout parameter as you are currently doing is not going to give you what you want. ;)

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

After testing found out that your syntax of message box was wrong:

MsgBox(1,"Emp id ",$Empid)
 MsgBox(1,"Emp address ",$Email)
 MsgBox(1,"server Name",$mserver)
 MsgBox(1,"Id file path",$path)

Should give you the results you're looking for

Edit:  Oh Melba23 beat me too it.........

Edited by Rogue5099
Link to comment
Share on other sites

Aniiii,

Try using the correct syntax for the MsgBox calls:

MsgBox(1 ,"Input details", "Emp id: " & $Empid)
Putting the variable you want to display in the place of the timeout parameter as you are currently doing is not going to give you what you want. ;)

M23

 

Thanks Melba ..

IF you look at fin id file ()

I have browse button to select the id file and path should display in input box .

Path which available i want to display that path outside of function  ..

Func Idfile()
    $hGUI1 = GUICreate("Lotus Notes Auto Config ", 394, 142, -1, -1)
    $hLabel1 = GUICtrlCreateLabel("Select Notes ID file ", 98, 16, 142, 27)
    GUICtrlSetFont(-1, 10, 800, 0)
    $hButton1 = GUICtrlCreateButton("Browse", 53, 92, 96, 23)
    GUICtrlSetFont(-1, 10, 800, 0)
    $hButton21 = GUICtrlCreateButton("Done", 229, 92, 95, 23)
    GUICtrlSetFont(-1, 8.5, 800, 0)
    $path = GUICtrlCreateInput("", 19, 43, 349, 27)
     GUISetState()
    $hMsg1 = 0
    While $hMsg1 <> $GUI_EVENT_CLOSE
        $hMsg1 = GUIGetMsg()
        Select
            Case $hMsg1 = $hButton1
                $File2open = FileOpenDialog("Browse", "C:\", "ID file  (*.id)") ;returns the file path
                GUICtrlSetData($path, $File2open) ;set input data
                $test = GUICtrlSetData($path, $File2open)
                 
             Case $hMsg1 = $hButton21
                $temp= GUICtrlRead($path)
                 if $temp = "" then 
                  MsgBox(1,"Error ","ID File Location Cannot be blank")
                  GUIDelete($delwindow)
                  Idfile()
                 Else 
                  ;MsgBox(1,"ID File path",($temp))
                  EndIf
               Return
        EndSelect
    WEnd
 EndFunc   ;==>Idfile
 
 MsgBox(1 ,"Input details", "Emp id: " & $Empid)
 MsgBox(1,"Input details","Emp address " & $Email)
 MsgBox(1,"Input details","server Name" & $mserver)
 MsgBox(1,"Input details","Id file path" & $temp)
Link to comment
Share on other sites

It would be better to change your function so that it didn't call itself because when that happens all the GUI controls are duplicated.

Instead of calling idfile return -1 for example then call the function like this

While idfile() <> -1

Wend

Then, as you have been told three times already, make the variables global or return an array or pass them as parameters using ByRef.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

It would be better to change your function so that it didn't call itself because when that happens all the GUI controls are duplicated.

Instead of calling idfile return -1 for example then call the function like this

While idfile() <> -1

Wend

Then, as you have been told three times already, make the variables global or return an array or pass them as parameters using ByRef.

Thanks Martin its resolved now  ...

Thank you so much  :)

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