Results 1 to 10 of 10

Thread: weird variable names

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Location
    Lowestoft
    Posts
    91

    weird variables

    say i have option1, option2, option3...all the way to option10

    how do i increment the variable name, i tried:
    Code:
    for j = 1 to 10
        option[j].text = ""
    next j
    but that sort of thing doesnt work. ne ideas?

    [Edited by Mag-Net on 07-18-2000 at 09:16 AM]
    Mag-Net's Home
    Visual Studio 6-Enterprise - SP4
    ICQ: 35519773
    Have Fun

  2. #2
    Addicted Member
    Join Date
    Jul 1999
    Location
    St-Élie d'Orford, Quebec, Canada
    Posts
    133
    Hi,

    is it still time to reconcider things like using a
    collection for option1 to 10 or you are stuck with the
    way it is ?

    Another way to do so ( if you don't have tons of controls on your form) is to loop for each control in the form and if
    the control type or name is correct, do what you want to
    do... Do you know what I mean ? If not, reply this post
    for sample code...

  3. #3
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565
    What you need is a Control Array instead of 10 seperately named controls.

    So you would have a control named optButton appear on your form 10 times each with a differnt index (1-10).

    Then you could use the following

    Code:
    Dim intCount as Integer
    
      For intCount = 1 To 10
    
        optButton(intCount).Text = ""
    
      Next intCount

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Location
    Lowestoft
    Posts
    91
    no i need it like it is, they are called txtOption1 and so on, they link to a database with the names as Option1 and so on, i have got a function to strip the txt off it and return the name that would be in the database, that is y i cant have a control array. ne ideas now?
    Mag-Net's Home
    Visual Studio 6-Enterprise - SP4
    ICQ: 35519773
    Have Fun

  5. #5
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565
    Try this ...

    Code:
    Dim ctl As Control
    
      For Each ctl In Me
      
        If InStr(ctl.Name, "Option") Then
          ctl.Text = ""
        End If
      
      Next ctl

  6. #6
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    You can still use the control array.

    Use the long forgotten, and underused (in my opinion) Tag property of each option button. Store the relevant database name in the Tag.

    Or strName = optionArray(index).Name & cstr(index)
    Iain, thats with an i by the way!

  7. #7
    Addicted Member
    Join Date
    Jul 2000
    Location
    Scotland
    Posts
    184
    Controls are held in a Collection referreced by Index Number or name. Why not build a string appended with the number then such as :

    Controls("Command1").Top

    Then you can use something like this:


    Dim MYCONTROL As Control

    For Each MYCONTROL In Controls()
    Debug.Print MYCONTROL.Name
    If TypeName(MYCONTROL) = "TextBox" Then

    etc..

    Bit sketchy this but I'm off home now....

  8. #8
    Fanatic Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    554
    I Just Wanted To Say Hear Hear to Iain17 as lotsa guys ask what the tag properties for etc (roflmao)

    And now its got so i just say, its for hanging your coat on when you get into the office.


    DocZaf
    {;->

  9. #9
    Junior Member
    Join Date
    Jul 2000
    Location
    Portland, OR
    Posts
    16
    I think the easiest way to do this would be to have a thing as following:

    Controls

    Option(?) {10 options in arrary 0 to 9}[? = number of options needed in arrary]


    Code:
    dim stro(option.lbound to option.ubound)
    
    private sub from_load()
     stro(0) = "{what ever you want option(0) to be}
     .
     .
     .
     stro(9) = "{what ever you want option(9) to be}
    end sub
    Get the point? That would be the easiest way to store it.

    Now, the reading part:

    Code:
    private sub option_click
     if stro(index) = "What ever" then
       'do this
      elseif stro(index) = "This" then
       'do this code
      .
      .
      .
     end if
    end sub
    That should do it for you. The stro is an arrary with the same number of items as the options. Then during form load you set each index of stro to what you want that options code to be.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Location
    Lowestoft
    Posts
    91
    kule idea thanks, i will add that to my next revision of the program, thanks I like your ideas about the tag property, and agree that many ppl dont know what it is or how to use it etc. Ah well, they may learn.... enjoy
    Mag-Net's Home
    Visual Studio 6-Enterprise - SP4
    ICQ: 35519773
    Have Fun

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