Jump to content

Passing a variable name to a function?


 Share

Recommended Posts

Hi,

I've created a tiny function to make it easier to debug variables in my scripts.

Func Debug($DATA)

; Local $DISPLAY

; $display = string($DATA)

MsgBox(0, "Debug", "[" & $DATA & "]")

EndFunc

When I don't seem to be getting the correct results from a script I just call the debug function: debug ($any_variable) and it will display the variable value at that point in the logic flow.

What I just discovered is that, once I start working with more than a couple variables, it's tough to figure out which variable I'm looking at when the box pops up.

As you can see from the rem'd out lines up above I've attempted to put the variable NAME ($file, $I, etc.) and not value into a local string variable which I could then incorporate into my msgbox display string.

I can't seem to get it to work :lmao: but I know it's probably something stupid that I'm missing. None of the string manipulation functions seem to do what I want.

Any ideas?

Jay

Link to comment
Share on other sites

Hi,

I've created a tiny function to make it easier to debug variables in my scripts.

Func Debug($DATA)

; Local $DISPLAY

; $display = string($DATA)

MsgBox(0, "Debug", "[" & $DATA & "]")

EndFunc

When I don't seem to be getting the correct results from a script I just call the debug function:  debug ($any_variable) and it will display the variable value at that point in the logic flow.

What I just discovered is that, once I start working with more than a couple variables, it's tough to figure out which variable I'm looking at when the box pops up.

As you can see from the rem'd out lines up above I've attempted to put the variable NAME ($file, $I, etc.) and not value into a local string variable which I could then incorporate into my msgbox display string.

I can't seem to get it to work  :lmao:  but I know it's probably something stupid that I'm missing.  None of the string manipulation functions seem to do what I want.

Any ideas?

Jay

<{POST_SNAPBACK}>

Cake!

Func Debug($DATA,$variablename="")
;   Local $DISPLAY
;   $display = string($DATA)
    MsgBox(0, "Debug", "$" & $variablename & "[" & $DATA & "]")
EndFunc

Download the latest beta so you can use optional paramaters in your functions.

Just call it like this

Func Debug($variable,"variable")

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

Cake!

Func Debug($DATA,$variablename="")
;    Local $DISPLAY
;    $display = string($DATA)
    MsgBox(0, "Debug", "$" & $variablename & "[" & $DATA & "]")
EndFunc

Download the latest beta so you can use optional paramaters in your functions.

Just call it like this

Func Debug($variable,"variable")

<{POST_SNAPBACK}>

Thanks, I'll give it a shot!

Although I was really looking for a function that could extract it from the passed variable itself rather than passing along a string to describe the variable.

Link to comment
Share on other sites

Thanks, I'll give it a shot!

Although I was really looking for a function that could extract it from the passed variable itself rather than passing along a string to describe the variable.

<{POST_SNAPBACK}>

No function exists and its not an easy thing to implement either. I did it once but the method wasn't pretty. Its probably for the best that Jon didn't take that particular bit of code.
Link to comment
Share on other sites

or you can take it the other way :lmao:

just try this:

dim $abc,$xyz
$abc="a string value"
debug("abc"); see below for $sign
$xyz=12345
debug("xyz")

Func Debug($DATA)
MsgBox(0, "Debug",$data & "=" & Eval($DATA)) ; remenber no $sign in front of the variable name
EndFunc

no $sign: I wonder why (implementation dependant?? or choosen??)

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