Results 1 to 19 of 19

Thread: Calling Functions with parameters

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    1,026

    Resolved Calling Functions with parameters

    I am wanting to create a function that will add a textbox or label to a form, my problem is that I need my user to be able to access all of the properties of that object.

    Is there any way to give the calling program access to those properties without having to list every single one of them?

    Thanks,

    Squirrelly1
    Last edited by squirrelly1; Feb 16th, 2005 at 10:44 AM.
    Now happily married and still crankin' away at the keyboard. Life is grand for a coder, no?

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: Calling Functions with parameters

    Hi,

    Something like;
    Dim txtTextbox As New textBox (form scope at least)

    Calling event
    txtTextBox = AddtextBox(txtTextBox)
    Me.Controls.Add(txtTextBox)

    Private Function AddtextBox(ByVal txtTemp As TextBox) As TextBox
    txtTemp.Name = "TestText1"
    txtTemp.Width = 40
    txtTemp.Top = 15
    txtTemp.Left = 24
    txtTemp.Text = "New text Box"
    txtTextBox.Visible = True
    Return txtTemp
    End Function
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: Calling Functions with parameters

    HI,

    I may have misunderstood you. If you want the user to have access to the properties, you must list them somewhere. Otherwise, how is the user going to select the property wants to access? If you mean you want to create several TextBoxes/labels and don't want to list all the properties every time in your code, then yes you can.

    Perhaps you can elaborate a little.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    1,026

    Re: Calling Functions with parameters

    well, i wanted the calling event to be able to set the parameters...

    but I guess that would defeat the purpose of having a seperate function to add the textbox, huh?

    ok... well nvm on this one I guess

    I'll just have to list just the parameters that I want to use in the function and live with it

    Thanks,

    Squirrelly1
    Now happily married and still crankin' away at the keyboard. Life is grand for a coder, no?

  5. #5
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: Calling Functions with parameters

    Hi,

    The calling event CAN set the parameters and pass them to the function.

    The purpose of having a function would be if you wanted to use it from other forms - make it Public and preferably put it in the Module.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    1,026

    Re: Calling Functions with parameters

    Actually I'm going to put it into a DLL so that I only have to change one file when I want to make changes to the user interface. I doubt I'm the first one who thought of this, but I'm still pretty proud of it. LOL
    Now happily married and still crankin' away at the keyboard. Life is grand for a coder, no?

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    Re: Calling Functions with parameters

    You can set and get all of the properties via Reflection.
    VB Code:
    1. 'setting
    2.         Dim txt As New TextBox
    3.         txt.GetType.GetProperty("Text").SetValue(txt, "I set this via reflection by name!", Nothing)
    4.         MsgBox(txt.Text)
    5.  
    6. 'getting
    7.         Dim txt As New TextBox
    8.         For Each pi As Reflection.PropertyInfo In txt.GetType.GetProperties()
    9.             MsgBox(pi.Name)
    10.         Next

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    1,026

    Re: Calling Functions with parameters

    if I were to do all that, why wouldn't I just go

    txt.Text = "I set this with a lot less code!"

    ???

    Squirrelly1
    Now happily married and still crankin' away at the keyboard. Life is grand for a coder, no?

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    Re: Calling Functions with parameters

    I don't know why you originally said "I need my user to be able to access all of the properties of that object" but that is how you can do it. The code you wrote couldn't be done at runtime whereas the property name and value in the reflection example can be passed in as text at anytime. I just wrote the example to show you the basic code of how to use reflection to get or set properties at runtime. Also reflection doesn't care what typeof object you pass it as long as you use correct property names.

    So you could script or have the user type in a property name and value at runtime and have it set or retrieved at runtime on any object. There is also the option of the PropertyGrid control which you could use to get/set properties of an object.

    I have an example related to Reflection that demonstrates what I mean but it also has other junk and I'm afraid it is not well commented. Let me know if you want me to post it.
    Last edited by Edneeis; Feb 17th, 2005 at 01:10 AM.

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    1,026

    Re: Calling Functions with parameters

    This isn't exactly what I was talking about, but it seems like it could be very useful. Could you post that example for me?

    Thanks,

    Squirrelly1
    Now happily married and still crankin' away at the keyboard. Life is grand for a coder, no?

  11. #11
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    Re: Calling Functions with parameters

    Here you go. Select a control from the left then the 'Refresh' link on the right. That will fill the treeview with all the properties of the last selected control. Then just pick a property and change it using the set/get links on the bottom right. Some properties can not be sent because I didn't work out how to translate the more complex types from a string.
    Attached Files Attached Files

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    1,026

    Re: Calling Functions with parameters

    thanks a mil.. i'll have to take a look at this when I have time

    Later
    Now happily married and still crankin' away at the keyboard. Life is grand for a coder, no?

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    1,026

    Re: Calling Functions with parameters

    Actually, I downloaded the file before I posted that I would take a look when I had time, and I happen to be working and unable to devote the attention required to learn from this example right now.

    erm... joke?
    Now happily married and still crankin' away at the keyboard. Life is grand for a coder, no?

  14. #14
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: Calling Functions with parameters

    Quote Originally Posted by squirrelly1
    Actually, I downloaded the file before I posted that I would take a look when I had time, and I happen to be working and unable to devote the attention required to learn from this example right now.

    erm... joke?

    I don't think he's being offensive. English is not his native language. I have had one or two misunderstandings with his meanings but he really sounds friendly
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  15. #15

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    1,026

    Re: Calling Functions with parameters

    Since your wanting to post screen snapshots... take a look at this one and call me liar... It is not my fault if the system is messed up... it was still showing 0 views when you posted your little comment.
    Attached Images Attached Images  
    Now happily married and still crankin' away at the keyboard. Life is grand for a coder, no?

  16. #16
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: Calling Functions with parameters

    Hi,

    I think there is a genuine misunderstanding here. Kulrom, you are assuming that the forum clock etc is infalible. It is not as I have noticed occasions when the time goes haywire (i.e. gets confused). I've seen posts timed earlier that the previous post by several hours. Squirrelly1 has no reason to make a false claim on this. It would be better to accept that it is a system fault rather than a personal one.

    It's a bit like line calls in tennis. We all call what we believe we see but often see calls differently. It's not that someone is dishonest but the way the human brain and eyes work.

    Can we call a let please?
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  17. #17

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    1,026

    Re: Calling Functions with parameters

    Fine by me... As far as I'm concerned, Thread Closed
    Now happily married and still crankin' away at the keyboard. Life is grand for a coder, no?

  18. #18
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    Re: Calling Functions with parameters

    Hey not to beat a dead horse or anything but the File Create and Modify dates are the times that I made the zip otherwise it would be before even my post.

    Anyway I don't want to get you started again, I just had to throw that in there and definately the forum clock has some issues from time to time.

  19. #19

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    1,026

    Re: Calling Functions with parameters

    Teeheehee... Sry guys, I've been at my gf's all weekend. Erm? Maybe I misunderstood you, which is completely likely, but did you say that the created and modified date/time for a file that was downloaded onto my computer is based upon the date/time that you created the zip file on your computer??? I thought that sounded a little funny so I checked it out... here you go...

    I promise to leave the damned horse alone now...

    Squirrelly1
    Attached Images Attached Images  
    Now happily married and still crankin' away at the keyboard. Life is grand for a coder, no?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width