Results 1 to 5 of 5

Thread: [RESOLVED] Help with variables

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2012
    Location
    Sweden
    Posts
    44

    Resolved [RESOLVED] Help with variables

    So I've been trying for TOO long with this now, i really need some help..

    I'll try to explain..
    I want to "Dim" a command, so that when i want to use the "command" (which is "button1.location" I just want to enter button =
    I also want to take the text from a string and put it after "="

    Example of how it looks like in my brain... :

    Code:
    Dim button as string = "button1.location"
    Dim box as string = "box1.location"
    
    button = box
    This is so that i can create a private Sub and use the Call command instead of typing the same code.. There really should be some way to do it

    Help....


    Edit: What. The. Hell. Why did it just work.. Ignore the Newb.
    Last edited by ErikJohansson; Sep 14th, 2012 at 04:19 PM.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,381

    Re: Help with variables

    Something you should defiantly do, which I've suggested to you in the past is to turn option strict and explicit on. Because if you do want to get the location of a button or box, the variable type would be a point, not a string.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  3. #3
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Help with variables

    In the future, I'd advise you state your problem instead of the solution you think might work. Your OP describes a solution, one that looks like something I'd advise against. I can't completely extrapolate from it what your problem is but it seems like something that can be solved in a clean manner with delegates.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Help with variables

    Quote Originally Posted by ErikJohansson View Post
    So I've been trying for TOO long with this now, i really need some help..

    I'll try to explain..
    I want to "Dim" a command, so that when i want to use the "command" (which is "button1.location" I just want to enter button =
    I also want to take the text from a string and put it after "="

    Example of how it looks like in my brain... :

    Code:
    Dim button as string = "button1.location"
    Dim box as string = "box1.location"
    
    button = box
    This is so that i can create a private Sub and use the Call command instead of typing the same code.. There really should be some way to do it

    Help....


    Edit: What. The. Hell. Why did it just work.. Ignore the Newb.
    By sayign it worked I take it that you actually mean it did not give you an error. You are assigning two strings then assigning one string value to the other which is perfectly fine but it would appear that you are trying to work with the property of an object namely Button.Location which of course is not a string and can not be used in such a way.

    As mentioned in post number 2 you would have to define it as a Point and it takes 2 numeric values not a string.

  5. #5
    Fanatic Member
    Join Date
    Dec 2007
    Location
    West Yorkshire, UK
    Posts
    791

    Re: [RESOLVED] Help with variables

    Have a look at this page, it explains .Location
    You do not need
    Code:
    Dim button As String = "button1.Location
    you need something more like
    Code:
    Button1.Location = New Point(100, 200)
    The numbers 100 and 200 are pixels measured from the Left and Top respectively of the container that the button is in. This will probably be the form itself in this case.

Tags for this Thread

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