Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

VB6 Variables and Objects


  • Please log in to reply

#1
Tassadar369

Tassadar369

    New Member

  • Member
  • Pip
  • 4 posts
I'm making a program and instead of using a whole bunch of if then statements is there a way you can store an object name in a variable?
  • 0

Advertisements


#2
kool808

kool808

    Visiting Staff

  • Member
  • PipPipPipPip
  • 1,690 posts
what specific language are you programming please be specific. You can make use of the CASE SELECT conditional statement then.
  • 0

#3
ratmilk

ratmilk

    Member

  • Member
  • PipPipPip
  • 151 posts
The title kind of says that:
"VB6 Variables and Objects, can you store object names in variables"
  • 0

#4
Ctrl_Alt_Del

Ctrl_Alt_Del

    Member

  • Member
  • PipPip
  • 74 posts
Sure. Open a new project and put a button on the form. In the click event of the button declare a string variable.

Public Sub cmdTest_Click()
Dim sName as string

sName = cmdTest.Name
Debug.Print sName

End sub
  • 0

#5
Tassadar369

Tassadar369

    New Member

  • Topic Starter
  • Member
  • Pip
  • 4 posts
I want it so you can use the variables in other functions not just print them I could use ObjectName.Name for that..
I need something like:
Select case Bot
Case "1"
RTB = RichTextBox1
WinSock = sckWinSock1
Case "2"
RTB = RichTextBox2
WinSock= sckWinSock2
End select
If winSock2.State <> sckDisconnected Then: WinSock2.Disconnect
  • 0

#6
Ctrl_Alt_Del

Ctrl_Alt_Del

    Member

  • Member
  • PipPip
  • 74 posts
If you want to store the variable name you need to do that in a string. You can then pass that string to any function or procedure that you want to but it will still be just a string. The debug.print was an example to demonstrate that the name was stored in a variable.


I think, but I am by no means sure, that what you may be wanting to do is to pass an entire object to a function or a sub so that you will have access to all of the methods and properties of that object available. Is that correct?
  • 0

#7
Tassadar369

Tassadar369

    New Member

  • Topic Starter
  • Member
  • Pip
  • 4 posts
Yes sir. Bingo! I think.. :tazz:
  • 0

#8
Ctrl_Alt_Del

Ctrl_Alt_Del

    Member

  • Member
  • PipPip
  • 74 posts
OK, say that you want to pass an ADO recordset to a Sud Procedure and use it there.


Public Sub ReadRecords(rsToRead as ADODB.Recordset)

If not rsread.eof and nor rsread.bof then
rsread.movefirst
While not rsread.eof
If not is null rsread(0).value then
Do Something with it
End if
rsread.movenext
Loop
end if


End Sub


Public Sub cmdRead_click()
Dim rsMyRS as new adodb.recordset
' Connect recordset, get records etc
ReadRecords rsMyRs
Set rsMyRs = nothing
end sub


You can do this with any object
  • 0

#9
Tassadar369

Tassadar369

    New Member

  • Topic Starter
  • Member
  • Pip
  • 4 posts
I'm trying to define some variables that represent object names and then use the variables so that they can be used in calling other functions
I also have another question whats the difference between
Set Variable = "One"
and
Variable = "One"

Edited by Tassadar369, 14 July 2005 - 03:55 PM.

  • 0

#10
I love my vans

I love my vans

    Member

  • Member
  • PipPipPip
  • 144 posts
Im going to take a stab at this, havent really read any of the posts.

To declare a variable as an object

Dim TextInput as TextBox

Then to call it like this

TextInput = Text1

TextInput.Text = "This is really going into Text1"

SHabba
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP