Results 1 to 7 of 7

Thread: Sub Problems

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2001
    Location
    Scotland
    Posts
    64

    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

  2. #2
    jdn
    Guest
    I guess this is what you want to do
    VB Code:
    1. Private Enum State
    2.    Dormant = 1
    3.    Listening = 2
    4.    Connecting = 3
    5.    Connected = 4
    6. End Enum
    7.  
    8. Sub Status(intState As State)
    9.      'your code here
    10. End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2001
    Location
    Scotland
    Posts
    64

    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

  4. #4
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    You didn't have your Select Case block right.
    VB Code:
    1. 'assuming you keep the enum
    2. Select Case intState
    3.    Case State.Dormant 'or just Case Dormant.  if you use a lot of enums, qualifying them is more readable
    4.       'block to run when it's set as Dormant
    5.    Case State.Listening
    6.       'block to run when it's Listening
    7.    '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

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2001
    Location
    Scotland
    Posts
    64

    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

  6. #6
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    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:
    1. Private Enum State
    2.     dormant = 1
    3.     Listening = 2
    4.     Connecting = 3
    5.     Connected = 4
    6. End Enum
    7.  
    8. Private Sub Status(intState As State) '(1)
    9.     Select Case intState                        '(2)
    10.         Case dormant                              '(3)
    11.             txtstatus.Text = "Dormant"
    12.             txtstatus.BackColor = &HFF00&
    13.         Case Listening
    14.             txtstatus.Text = "Active - Listening"
    15.             txtstatus.BackColor = &HFFFF&
    16.         Case Connecting
    17.             txtstatus.Text = "Active - Connecting"
    18.             txtstatus.BackColor = &H80FF&
    19.         Case Connected
    20.             txtstatus.Text = "Active - Connected"
    21.             txtstatus.BackColor = &HFF&
    22.         Case Else
    23.             txtstatus.Text = "ERROR"
    24.             txtstatus.BackColor = &HFF&
    25.     End Select                                        '(4)
    26. End Sub
    27.  
    28. Private Sub Command1_Click()
    29.     Status dormant
    30. End Sub

    Regards
    Stuart
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  7. #7
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    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
  •  



Click Here to Expand Forum to Full Width