Results 1 to 7 of 7

Thread: Distinguishing variables

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2012
    Location
    Priors Road Cheltenham, Gloucestershire GL52 5
    Posts
    17

    Distinguishing variables

    I have 2 lists of variables, ex. Name,Name1... Name10 and Type,Type1...Type10. I also have a text box that I am entering a word into, ex. "Land" into txtWord. I want to find the Type variable that equals "Land", and then print the corresponding Name variable into a textbox, txtAnswer. What code would I use to do this? Hope I've been clear enough and I hope you can help.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Distinguishing variables

    Moved From The CodeBank (which is for sharing code rather than posting questions )

  3. #3
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Distinguishing variables

    Since programs normally don't have any reason to "look at themselves" there isn't really anything built in to support it.

    If you simply want to associate a bunch of variables with a bunch of controls you might consider using data arrays and control arrays.

  4. #4
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,261

    Re: Distinguishing variables

    I think what he's looking for is the TypeName-Function or the TypeOf-Operator, but i doubt it's going to work on an entry in a textbox since the Text-Property per se returns a string.
    What he might try is
    IsNumeric, IsDate, but i haven't found anything like IsText or similiar
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  5. #5
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Distinguishing variables

    I think this just a question about Arrays, it's not very clear.
    Code:
    Option Explicit
    
    Private strTypes(2) As String
    Private strNames(2) As String
    
    Private Sub Command_Click()
    Dim intI As Integer
    txtAnswer.Text = vbNullString
    If txtWord.Text <> vbNullString Then
        Do
            If UCase(strTypes(intI)) = UCase(txtWord.Text) Then
                txtAnswer.Text = strNames(intI)
            Else
                intI = intI + 1
            End If
        Loop Until intI > UBound(strTypes) Or txtAnswer.Text <> vbNullString
    End If
    End Sub
    
    Private Sub Form_Load()
    '
    ' List of Types
    '
    strTypes(0) = "Land"
    strTypes(1) = "Sea"
    strTypes(2) = "Air"
    '
    ' List of Names
    '
    strNames(0) = "England"
    strNames(1) = "Atlantic Ocean"
    strNames(2) = "Cloud"
    End Sub

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Distinguishing variables

    I was thinking Dictionary myself... or rather a Collection where the key is the "type" (eg, Land) and the value would be the corresponding name.

    I'd provide a sample but I don't have VB6 on this machine.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,261

    Re: Distinguishing variables

    Quote Originally Posted by ITbanter2k12 View Post
    Hope I've been clear enough and I hope you can help.
    Well, asking this question and getting 4 different answers should give you a clue.....
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

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