|
-
Sep 17th, 2012, 05:05 AM
#1
Thread Starter
Junior Member
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.
-
Sep 17th, 2012, 05:20 AM
#2
Re: Distinguishing variables
Moved From The CodeBank (which is for sharing code rather than posting questions )
-
Sep 17th, 2012, 05:26 AM
#3
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.
-
Sep 17th, 2012, 06:06 AM
#4
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
-
Sep 17th, 2012, 09:34 AM
#5
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
-
Sep 17th, 2012, 10:55 AM
#6
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
-
Sep 17th, 2012, 11:11 AM
#7
Re: Distinguishing variables
 Originally Posted by ITbanter2k12
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|