Author Topic: store Private sub name as string  (Read 2938 times)

0 Members and 1 Guest are viewing this topic.

Oak3s

  • Guest
store Private sub name as string
« on: March 08, 2007, 06:42:29 PM »
is there a way to save the name of a Private Sub?
Code: [Select]
'global variables
Dim strFileName As String

Private Sub sldPLYWOOD_LButtonDown()  [color=red]i have a lot of privite sub's like this, ex: sldPLYWOOD2,sldPLYWOOD3[/color]
strFileName = sldPLYWOOD.FileName
[color=red]rather than say sldPLYWOOD i would like to same something
like "[/color][color=purple]this sub[/color]"[color=red]. is there a way to do that?[/color]

Change_sldPreview

End Sub
Public Sub Change_sldPreview()
sldPreview.FileName = strFilename
[color=red]
that way i could do something like:
strFileName = [/color][color=purple]this sub[/color][color=red].FileName[/color]
End Sub


Arizona

  • Guest
Re: store Private sub name as string
« Reply #1 on: March 08, 2007, 07:00:09 PM »
If Dim strFileName As String was defined as Public strFileName As String you could then use it through out the project. Or perhaps you could use a call statement and pass it the necessary argument?
What are you trying to do with it once you have it? :-)
« Last Edit: March 08, 2007, 07:08:07 PM by Arizona »

uncoolperson

  • Guest
Re: store Private sub name as string
« Reply #2 on: March 08, 2007, 07:13:36 PM »
could the "me" keyword help out at all with this?

(and yes greg, it is all about me... incase you were wondering)

Oak3s

  • Guest
Re: store Private sub name as string
« Reply #3 on: March 08, 2007, 07:27:35 PM »
What are you trying to do with it once you have it? :-)
the "it" is what im trying to get. how do i go about storing the sub's name without doing the following in each sub:
Code: [Select]
strFileName = sldPLYWOOD.FileName
...
strFileName = sldPLYWOOD2.FileName

i would like to do this:
Code: [Select]
strFileName = (whatever the sub's name is).FileName
uncoolperson, i tried "Me" but i coulding get it to work. possibly my lack of understanding is the hang-up ;)

Bryco

  • Water Moccasin
  • Posts: 1883
Re: store Private sub name as string
« Reply #4 on: March 08, 2007, 09:18:17 PM »
There is not enough info here to help you.

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: store Private sub name as string
« Reply #5 on: March 08, 2007, 11:28:25 PM »
VBA is an interpreted language. I use a ``similar'' concept for my AutoLisp code. So i say: knock yourself out.

Try this snip. (Looks crude, and its not exactly what your asking about but i think it will do the job.)

http://www.vba-programmer.com/Snippets/Code_Excel/Adding_VBA_Code_via_Program.html
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Dnereb

  • Guest
Re: store Private sub name as string
« Reply #6 on: March 09, 2007, 07:18:11 AM »
The only way I can think of to do what you want is to make a routine that proccesses and  add's code to your project automaticly if needed. There's no object that can give your routines name at hand and API process calss wil get the Interpreter process not the actual code.

To make suche a program will be a project on it's own, and would function a bit like M-Z tools.

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: store Private sub name as string
« Reply #7 on: March 09, 2007, 01:12:46 PM »
The only way I can think of to do what you want is to make a routine that proccesses and  add's code to your project automaticly if needed. There's no object that can give your routines name at hand and API process calss wil get the Interpreter process not the actual code.

To make suche a program will be a project on it's own, and would function a bit like M-Z tools.

If were talking theory here, that should not be a problem at all (I do it all the time in autolisp.).
Code: [Select]
( (lambda ( func )
    ;; copy and paste this to the command line, you should
    ;; then have an anon function: ``((LAMBDA nil (1+ 2)))''
    (list (cons 'lambda (cons nil (list func)))))
 '(1+ 2)
 )

If you take a look at the link i supplied, the author of that VBA code is doing much the same.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Oak3s

  • Guest
Re: store Private sub name as string
« Reply #8 on: March 13, 2007, 06:29:54 PM »
it could be that the answer has already been given. what my very limited understanding of vb(a) tells me is im not asking the question right.
attached is an example of what im trying to do...kinda :)
when i click on image1 i would like the name to be saved as a string
and then added to the listbox1.
right now it adds the text: mulitpage1
that leads me to the question, can an image be the activecontrol? do i seem to be headed in the right direction?

where im trying to go is:
click any image and it will run the same separate sub. that way i dont have to copy and past more code than a line (the name of the separate sub) into each image click event.

i hope this gives more information.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: store Private sub name as string
« Reply #9 on: March 14, 2007, 01:10:53 AM »
Since you want the name of the image you may as well name the control what you want to be placed in the listbox. or
Private Sub Image1_Click()
    FillThatListbox ("This plywood")
End Sub
Private Sub FillThatListbox(strFileName As String)
    ListBox1.AddItem strFileName
End Sub

Sometimes you are better off typing the stuff rather than worrying about it, that's now

Oak3s

  • Guest
Re: store Private sub name as string
« Reply #10 on: March 14, 2007, 01:54:51 PM »
Bryco, i appreciate your responses. your first got me to post a simple example. i hope you looked at it. something i couldnt get it to do is put the right control in the listbox. your second post is below. my responses are there. i hope they dont come across as harsh, when in reality (my reality :) ) they just show my lack of knowledge.
Quote from: Bryco
Since you want the name of the image you may as well name the control what you want to be placed in the listbox in the example i uploaded i thought i did that. or
Private Sub Image1_Click()
    FillThatListbox ("This plywood") what is ("This plywood")?
End Sub
Private Sub FillThatListbox(strFileName As String)
    ListBox1.AddItem strFileName
End Sub

Sometimes you are better off typing the stuff rather than worrying about it, that's now i dont know exactly what you mean here but if i only had to type it out one time...then i wouldnt try to make it clean. but this applies to about 100 controls.


Bryco

  • Water Moccasin
  • Posts: 1883
Re: store Private sub name as string
« Reply #11 on: March 14, 2007, 05:33:58 PM »
I had a look, but no images came with it.
what is ("This plywood")?- "This plywood" would be the string name you want displayed for the image.
Using activecontrol  you didn't get what u wanted
using the sub I provided gives you the correct name.
Did you try it?

Oak3s

  • Guest
Re: store Private sub name as string
« Reply #12 on: March 14, 2007, 09:46:04 PM »
Quote from: Bryco
what is ("This plywood")?- "This plywood" would be the string name you want displayed for the image.
Using activecontrol  you didn't get what u wanted
using the sub I provided gives you the correct name.
Did you try it?

i did not try it. i actually want the string "Image1" to be displayed. but not have to put:
Code: [Select]
FillThatListbox ("Image1")