|
-
Jul 21st, 2001, 07:57 PM
#1
Thread Starter
Lively Member
Sub Problems
I want to make a procedure to change a textboxs text and backcolor values.
I need to define a user-type variable that can be one of the following states:
Dormant
Listening
Connecting
Connected
Then, how can I pass that as an arguement into my Sub routine for setting the textbox up ?
Sub Status()
AMD Athlon 1.0 GHz
128MB RAM
GeForce 2 MX
30 GB HD
-
Jul 21st, 2001, 08:11 PM
#2
I guess this is what you want to do
VB Code:
Private Enum State
Dormant = 1
Listening = 2
Connecting = 3
Connected = 4
End Enum
Sub Status(intState As State)
'your code here
End Sub
-
Jul 21st, 2001, 08:15 PM
#3
Thread Starter
Lively Member
No Joy
This did not work :
Private Enum State
Dormant = 1
Listening = 2
Connecting = 3
Connected = 4
End Enum
Sub Status(intState As State)
Select Case State
Case "Dormant"
txtStatus.Text = "Dormant"
txtStatus.BackColor = &HFF00&
Case "Active - Listening"
txtStatus.Text = "Active - Listening"
txtStatus.BackColor = &HFFFF&
Case "Connecting"
txtStatus.Text = "Active - Connecting"
txtStatus.BackColor = &H80FF&
Case "Connected"
txtStatus.Text = "Active - Connected"
txtStatus.BackColor = &HFF&
Case Else
txtStatus.Text = "ERROR"
txtStatus.BackColor = &HFF&
End Sub
AMD Athlon 1.0 GHz
128MB RAM
GeForce 2 MX
30 GB HD
-
Jul 21st, 2001, 08:17 PM
#4
Fanatic Member
You didn't have your Select Case block right.
VB Code:
'assuming you keep the enum
Select Case intState
Case State.Dormant 'or just Case Dormant. if you use a lot of enums, qualifying them is more readable
'block to run when it's set as Dormant
Case State.Listening
'block to run when it's Listening
'etc...
Last edited by Kaverin; Jul 21st, 2001 at 08:22 PM.
I'm baaaack...
VB5 Professional Edition, VC++ 6
Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se
I feel special because I finally figured out how to loop midis: Post link
I'm a fanatic too 
-
Jul 21st, 2001, 08:22 PM
#5
Thread Starter
Lively Member
More Ideally...
Emmm. "User Type not Defined" is the error I get.
And is there anyway I can link 'Status' with a Winsock control ?
IE - If its connected State = Connected ???
AMD Athlon 1.0 GHz
128MB RAM
GeForce 2 MX
30 GB HD
-
Jul 21st, 2001, 08:27 PM
#6
PowerPoster
Hi
A few errors in ur code
1. Sub must be Private if using Private Enum and in same form
2. As Kaverin said... u should be testing variable not the Enum
3. Cases should not have quotes... I would use State.Dormant etc but you can use just Dormant
4. There is a missing End Select
VB Code:
Private Enum State
dormant = 1
Listening = 2
Connecting = 3
Connected = 4
End Enum
Private Sub Status(intState As State) '(1)
Select Case intState '(2)
Case dormant '(3)
txtstatus.Text = "Dormant"
txtstatus.BackColor = &HFF00&
Case Listening
txtstatus.Text = "Active - Listening"
txtstatus.BackColor = &HFFFF&
Case Connecting
txtstatus.Text = "Active - Connecting"
txtstatus.BackColor = &H80FF&
Case Connected
txtstatus.Text = "Active - Connected"
txtstatus.BackColor = &HFF&
Case Else
txtstatus.Text = "ERROR"
txtstatus.BackColor = &HFF&
End Select '(4)
End Sub
Private Sub Command1_Click()
Status dormant
End Sub
Regards
Stuart
-
Jul 21st, 2001, 08:28 PM
#7
Fanatic Member
From what you posted, you're trying to use the name of the enum by itself, and VB thinks you're trying to use a variable. You've got to look at the var you pass into your sub like in what I mentioned (either with or without qualifying the enum name). You could define the param of your sub as the enum that the winsock control uses for its constants if you want, whatever that particular one is.
I'm baaaack...
VB5 Professional Edition, VC++ 6
Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se
I feel special because I finally figured out how to loop midis: Post link
I'm a fanatic too 
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
|