VB6 Variables and Objects
Started by
Tassadar369
, Jul 14 2005 03:26 AM
#1
Posted 14 July 2005 - 03:26 AM
#2
Posted 14 July 2005 - 06:48 AM
what specific language are you programming please be specific. You can make use of the CASE SELECT conditional statement then.
#3
Posted 14 July 2005 - 06:55 AM
The title kind of says that:
"VB6 Variables and Objects, can you store object names in variables"
"VB6 Variables and Objects, can you store object names in variables"
#4
Posted 14 July 2005 - 07:13 AM
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
Public Sub cmdTest_Click()
Dim sName as string
sName = cmdTest.Name
Debug.Print sName
End sub
#5
Posted 14 July 2005 - 02:31 PM
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
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
#6
Posted 14 July 2005 - 02:40 PM
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?
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?
#7
Posted 14 July 2005 - 02:42 PM
Yes sir. Bingo! I think..
#8
Posted 14 July 2005 - 02:49 PM
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
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
#9
Posted 14 July 2005 - 03:53 PM
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"
I also have another question whats the difference between
Set Variable = "One"
and
Variable = "One"
Edited by Tassadar369, 14 July 2005 - 03:55 PM.
#10
Posted 08 September 2005 - 07:07 PM
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
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
Similar Topics
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users