Jump to content

Holding a string value when calling from sub to sub?


Recommended Posts

Posted

can you hold a string valu when calling from sub to sub?

 

Cheers

 

Col.

Posted

If you don't declare it

e.g. declared

(defun test1 (/ strng1)
(setq strng1 (getstring "Enter sumthin: "))
)

undeclared

(defun test2 ()
(setq strng2 (getstring "Enter sumthin else"))
)

If you load and run these functions, !strng1 will return nil [won't be available for other subs]; !strng2 will return a string [available]

Posted

In VB you can set it to a module level variable ( ie "Private varname as string" at the top of a module) or a global variable ( ie "Public varname as string"). Module level is available to all subs/functions in module and globals are available to any module. This is one way, there are other ways to accomplish it also.

Posted

Of course, you can still use local variables and just pass the first function result to the second function as an argument.

 

;;; function 1 just sets a string to the var [b]str[/b]
(defun fun1 ( / str)
 (setq str "\nthis is a test string")
 str
)

;;; function 2 expects an argument and prints it.
(defun fun2 (arg)  
 (princ arg)
)
;;; this code just calls function 2 with function 1 as an argument
(fun2 (fun1))

;;; when you are done, [b]str[/b] is either 
;;; nil or it's previous value before running
;;; any of this code.

Posted

hi,

 

i am using Vb and have tried putting the following at then top of the module in the General / Declarations sections

 

Public MyAttTextStr As String

[/code[

 

but looking in the local window it does not show the string at all?

 

if i put it at the top of the module with the other Dims then it works for that module?

 

cheers,

 

col

Posted

sorry, actually it does work!!

 

many thanks!

 

col

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...