Jump to content

passing variables to functions


masonje
 Share

Recommended Posts

I'm not able to get this to run correctly. It will compile, and run the GUI, but errors out on the _srvConnect() function The error is attached and below is the code...

#include <GuiConstants.au3>

$ipParce = StringLeft(@IPAddress1, 6)

$homeIPparce = "10.70." ;parced to 6 digits, including decimals

$url = "domain.com"

$vncPath = "C:\Program Files\RealVNC\VNC4\vncviewer.exe"

;set var to make compiler stop complaining....

$port = ""

$server = ""

;Setup GUI

GUICreate("VNC Connect", 152, 90, (@DesktopWidth - 152) / 2, (@DesktopHeight - 110) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$Button_Tower = GUICtrlCreateButton("Tower", 10, 10, 130, 30)

$Button_Linux = GUICtrlCreateButton("Server2", 10, 50, 130, 30)

Func _srvConnect()

;Determin home or outside network

If $ipParce = $homeIPparce Then

$run = $vncPath & " " & $server

Run($run)

Exit

Else

$run = $vncPath & " " & $url & ':' & $port

Run($run)

Exit

EndIf

Exit

EndFunc ;==>_srvConnect

;Start GUI

GUISetState()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $Button_Tower

;set port and server infor for Button_1

$port = "4444"

$server = "10.70.1.11"

;Connect to server

_srvConnect($port & $server)

Case $msg = $Button_Linux

;set port and server infor for Button_2

$port = "5555"

$server = "10.70.1.12"

;Connect to server

_srvConnect($port & $server)

EndSelect

WEnd

Exit

PS, the personal stuff has all been changed, so don't bother! :P Also I attached my real source file so it can be read w/ the tabs.

guiconnect_posted.au3

Link to comment
Share on other sites

  • Moderators

Does this help?

#include <GuiConstants.au3>
Dim $ipParce = StringLeft(@IPAddress1, 6)
Dim $homeIPparce = "10.70.";parced to 6 digits, including decimals
Dim $url = "domain.com"
Dim $vncPath = "C:\Program Files\RealVNC\VNC4\vncviewer.exe"
;set var to make compiler stop complaining....
Dim $port = ""
Dim $server = ""

;Setup GUI
GUICreate("VNC Connect", 152, 90, (@DesktopWidth - 152) / 2, (@DesktopHeight - 110) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$Button_Tower = GUICtrlCreateButton("Tower", 10, 10, 130, 30)
$Button_Linux = GUICtrlCreateButton("Server2", 10, 50, 130, 30)

Func _srvConnect(ByRef $vncPath, ByRef $port, ByRef $server, ByRef $url, ByRef $homeIPparce, ByRef $ipParce)
;Determin home or outside network
    If $ipParce = $homeIPparce Then
        $run = $vncPath & " " & $server
        Run($run)
        Exit
    Else
        $run = $vncPath & " " & $url & ':' & $port
        Run($run)
        Exit
    EndIf
    Exit
EndFunc  ;==>_srvConnect

;Start GUI
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_Tower
        ;set port and server infor for Button_1
            $port = "4444"
            $server = "10.70.1.11"
        ;Connect to server
            _srvConnect($vncPath, $port, $server, $url, $homeIPparce, $ipParce)
        Case $msg = $Button_Linux
        ;set port and server infor for Button_2
            $port = "5555"
            $server = "10.70.1.12"
        ;Connect to server
            _srvConnect($vncPath, $port, $server, $url, $homeIPparce, $ipParce)
    EndSelect
WEnd
Exit

Edit:

Forgot some stuff...

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I'm not able to get this to run correctly. It will compile, and run the GUI, but errors out on the _srvConnect() function The error is attached and below is the code...

PS, the personal stuff has all been changed, so don't bother! :P Also I attached my real source file so it can be read w/ the tabs.

you haven't setup your _srvconnect() to accept any arguments. if you want to send it a value, you have to assign a name to the value being received, like

Func _SrvConnect($argument)
then use $argument within the function to refer to the referenced. Another option if you're using global variables and it's just working with those, take out the arguments being passed in the function call, and call it with just:

_SrvConnect()

***edit** fixed typo. also, please use [ code ] and [ /code ] (without the spaces) to seperate your code and make it stand out... PS. welcome to the forum

Edited by cameronsdad
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...