Results 1 to 5 of 5

Thread: [RESOLVED] Form of frustration :)

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    10

    Resolved [RESOLVED] Form of frustration :)

    Hi all,

    I created an array like this on form 1
    Dim bigFeet(1 to5) As String

    On form one I placed a textbox
    Then I toddled along and opened up another form,on which I placed
    a list box and a command button.In the List items I just placed a,b,c ect

    I was trying to use form 2 to place a value into the array in from 1

    I then put this code within the command button event in form 2

    If Form2.List1.Text = "a" Then bigFeet(0) = "pigs Alive"
    Form1.Text1.Text=bigFeet()
    the idea was to pass "pigs alive" to bigFeet element,then publish it to the world in Text1.

    The brilliant idea was that I could fill an array thingy from another form.
    But the brilliant plan didn't work and if I see this message one more time.."Sub or Function not defined.". I will sell go and live in the North Pole(well until it melts anyway
    Can any of you supervb brains help me out on what is problem.

    Kind Regards
    and many salutations peace and love to all
    Tom

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Form of frustration :)

    Welcome to the forums.

    Normally to share a form's variables with other forms, you would declare the variable as Public on that form. Then to reference that variable from another form, you prefix the variable with the form's name, i.e., Form1.SomeVariable

    However, arrays are slightly different as are other things too. You can't do this with arrays. There are workarounds that include creating Public Let/Get properties on the form to access the array, but more hassle than it's worth in my opinion.

    A simpler solution, which can be used for any variable type is to use a bas module. Add a module (not class module) to your project if not already there. Add this to the module: Public bigFeet(1 to 5) As String (also remove it from your form). Now you can access bigFeet() from anywhere in your project. This is true with all Public variables declared in a module.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    10

    Re: Form of frustration :)

    Hello There LaVolpe,

    Many thanks for your reply and thank you for welcoming me to the forums.
    I appreciate your reply and will endeavour to undertake your instructions.
    Again many thanks.

    Kind Regards
    Tommy

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Form of frustration :)

    Now that we've helped you, you can help us by marking the thread as resolved. If you have JavaScript enabled you can do that easily by pulling down the Thread Tools menu and selecting the Mark Thread Resolved item. Also if someone has been particularly helpful you have the ability to affect their forum "reputation" by rating their post. Only those ratings that you give after you have 20 posts will actually count, but in all cases the person you rate will see your rating and know that you appreciate their help.

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    10

    Re: Form of frustration :)

    Hi all,

    Just to give you an update on what I did with the help of LaVolpe.

    I created two forms and a module.

    On the forms I placed a listbox,and textbox and a command.

    In the module I placed the following code

    Public Sub ello()
    Dim bigFeet(1 To 5) As String

    If Form2.List1.Text = "1" Then bigFeet(1) = "sausage"
    If Form2.List1.Text = "2" Then bigFeet(1) = "brecon beacons"
    Form1.Text1 = bigFeet(1)

    End Sub

    All I did then was place ello in the command procedures code and bob's uncle!! works a treat,and enables me to do what I wanted to do originally..use one form to enter a value into an array on another form.
    Thanks again.
    Tommy

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