Results 1 to 8 of 8

Thread: what is the structure below stores?? i am confuse

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2003
    Posts
    599

    what is the structure below stores?? i am confuse

    Private Type HOSTENT
    hName As Long
    hAliases As Long
    hAddrType As Integer
    hLen As Integer
    hAddrList As Long
    End Type
    Thank You

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    A 'Private Type' has been set up called HOSTENT.

    HOSTENT contains 5 elements, in this case Longs and Integers.

    You can access those elements by Dimensioning a variable as the HOSTENT, Like:

    VB Code:
    1. Dim PersDetails as HOSTENT
    2.  
    3.     PersDetails.hName = 1234
    4.     PersDetails.hAliases = 45657
    5.     'etc
    6.  
    7.   'And, then display them like:
    8.  
    9.     Msgbox PersDetails.hName
    10.     Msgbox PersDetails.hAliases

    Note: The Data Types dont seem to reflect the wanted use tho.
    ie. Shouldn't hName be dimensioned as a String?



    Bruce.
    Last edited by Bruce Fox; Jul 28th, 2003 at 09:49 PM.

  3. #3
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Heres an (Excell VB) Extract:
    Type Statement


    Used at module level to define a user-defined data type containing one or more elements.

    Syntax

    [Private | Public] Type varname
    elementname [([subscripts])] As type
    [elementname [([subscripts])] As type]
    . . .

    End Type

    The Type statement syntax has these parts:

    Part Description
    Public Optional. Used to declare user-defined types that are available to all procedures in all modules in all projects.
    Private Optional. Used to declare user-defined types that are available only within the module where the declaration is made.
    varname Required. Name of the user-defined type; follows standard variable naming conventions.
    elementname Required. Name of an element of the user-defined type. Element names also follow standard variable naming conventions, except that keywords can be used.
    subscripts When not explicitly stated in lower, the lower bound of an array is controlled by the Option Base statement. The lower bound is zero if no Option Base statement is present.
    type Required. Data type of the element; may be Byte, Boolean, Integer, Long, Currency, Single, Double, Decimal (not currently supported), Date, String (for variable-length strings), String * length (for fixed-length strings), Object, Variant, another user-defined type, or an object type.



    Remarks

    The Type statement can be used only at module level. Once you have declared a user-defined type using the Type statement, you can declare a variable of that type anywhere within the scope of the declaration. Use Dim, Private, Public, ReDim, or Static to declare a variable of a user-defined type.

    In standard modules and class modules, user-defined types are public by default. This visibility can be changed using the Private keyword.

    Line numbers and line labels aren't allowed in Type...End Type blocks.

    User-defined types are often used with data records, which frequently consist of a number of related elements of different data types.

    The following example shows the use of fixed-size arrays in a user-defined type:

    Type StateData
    CityCode (1 To 100) As Integer ' Declare a static array.
    County As String * 30
    End Type

    Dim Washington(1 To 100) As StateData

    In the preceding example, StateData includes the CityCode static array, and the record Washington has the same structure as StateData.

    When you declare a fixed-size array within a user-defined type, its dimensions must be declared with numeric literals or constants rather than variables.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2003
    Posts
    599

    Thumbs up

    Thanks brucefox...

    actually its my fault... i did not specify correctly...... what i mean is the structure type is used in a section to call for IPHOSTNAME... and they often use this structure to get the information ... so i would like to know what are the content in those Struct
    Thank You

  5. #5
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Originally posted by vbnew
    ... so i would like to know what are the content in those Struct

    One simple way would be to use the MsgBox method above to confirm the data.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2003
    Posts
    599

    Lightbulb

    Ya lah,

    damn , i am so stupid .............. Thanks Bruce Fox. maybe i am a little bit lazy to key in that line of code.... lazyness hell..... BruceFox thanks.... (maybe i am too eager untill all hell in my brain) Thanks
    Thank You

  7. #7
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Well, I had previously done it, so here it is

    VB Code:
    1. Option Explicit
    2.  
    3. Private Type HOSTENT
    4.     hName As Long
    5.     hAliases As Long
    6.     hAddrType As Integer
    7.     hLen As Integer
    8.     hAddrList As Long
    9. End Type
    10.  
    11. Private Sub SomeSub()
    12.  
    13.   Dim IPHostDetails As HOSTENT
    14.  
    15.     IPHostDetails.hName = 'something from your Connection to the URL
    16.     IPHostDetails.hAliases = 'something from your Connection to the URL
    17.     'etc
    18.     'etc
    19.  
    20.   'And, then display them like:
    21.  
    22.     MsgBox IPHostDetails.hName
    23.     MsgBox IPHostDetails.hAliases
    24.     MsgBox IPHostDetails.hAddrType
    25.     MsgBox IPHostDetails.hLen
    26.     MsgBox IPHostDetails.hAddrList
    27.  
    28. End Sub
    Last edited by Bruce Fox; Jul 28th, 2003 at 10:09 PM.

  8. #8
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Better yet:
    VB Code:
    1. MsgBox "IPName: " & IPHostDetails.hName & vbCrLf _
    2.     & "IPAliases: " & IPHostDetails.hAliases & vbCrLf _
    3.     & "IPAddrType: " & IPHostDetails.hAddrType & vbCrLf _
    4.     & "IPLen: " & IPHostDetails.hLen & vbCrLf _
    5.     & "IPAddrList: " & IPHostDetails.hAddrList

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