Results 1 to 13 of 13

Thread: [RESOLVED] Public Constants?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Resolved [RESOLVED] Public Constants?

    I looked and an example, and they used public constants to do something. What do they do? Can someone give me a link to a tutorial or explain it?
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Public Constants?

    See if this FAQ topic answers your question.

    Edited: Just because you saw some code written a certain way does not necessarily mean it was correctly written, nor that it was necessary. Always keep that in mind.
    Last edited by LaVolpe; Jul 27th, 2010 at 03:19 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: Public Constants?

    Well. Sorta. I remeber there being something like
    Public Wall
    Public Const Width
    Public Const Height

    And stuff like that. Well, sorta like that.... Do you know of an example with making walls and stuff?
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: Public Constants?

    Oh w8! I remember now! It was Public Types! That was it! If i used thoes, how would i make it like:
    Public Type Wall
    lngX as Long
    lngY as Long
    lngWidth as Long
    lngHeight as Long
    End Type
    How would i get collision, bitblt, and have more than one wall?
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Public Constants?

    The Public/Private keywords just specify where something can be used, as explained by the FAQ article. In the same way you can have a Private Sub and a Public Sub, you can have a Private Type and a Public Type (and in both cases you can leave Public/Private out, and guess which one VB will use).

    A Type is just a way of grouping multiple variables together - in that Wall example it is the various properties that are needed for a Wall (X/Y/Width/Height).

    To use it you would declare a variable of that data type (Wall) rather than the usual ones (String/Integer/etc), and set the values. eg:
    Code:
    Dim MyWall as Wall
      MyWall.lngX = 3
      MyWall.lngY = 2
      MyWall.lngWidth = 7
      MyWall.lngHeight = 14
    The alternative would be multiple variables with similar names, eg:
    Code:
    Dim MyWall_lngX as Long, MyWall_lngY as Long, MyWall_lngWidth as Long, MyWall_lngHeight as Long
      MyWall_lngX = 3
      MyWall_lngY = 2
      MyWall_lngWidth = 7
      MyWall_lngHeight = 14
    Using a Type means that you have fewer variables, and generally the code is easier to read/write (eg: at the . you get a drop-down list).

    How would i get collision, bitblt,
    Exactly the same as you would with individual variables.
    and have more than one wall?
    As with the usual data types, you use an array.

    Using an array of a user-defined-Type is much better than using array(s) of basic data types, because with basic data types you have two options:
    • Use different arrays for each property (X/Y/Width/Height). Compared to a Type, this means more typing and more variables, and increased chances of problems (eg: you need to make sure each array has the same amount of items as the others, and that element 1 in one array refers to the same item as element 1 in the others).
    • Use a multidimensional array, with one 'column' per property. Not only do you need to remember what each 'column' number means (eg: is 3 the Width?), but it is also very bad if the properties should have different data types (because in a multidimensional array everything has the same data type).
    Last edited by si_the_geek; Jul 28th, 2010 at 05:31 AM.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: Public Constants?

    So there isn't really a plus to using types than just plain ol' variables?
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Public Constants?


    My post explained 3 pluses for using Types for non-array variables, and several more (which are much more significant) for array variables.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: Public Constants?

    Oh. Ik that. rofl. im just thinking..... I guess it would be easier... What am i doing wrong though? Its not working and whenever i type the name of the object and the the . to get properties, it doesn't show them up like it should.....
    Public Type Examples
    Width as Long
    Height as Long
    Top as Long
    Left as Long
    End Type

    ????
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Public Constants?

    That creates the Type, but why aren't you showing us the part that has problems - the code to use it?

    As in my example in post #5, you should be declaring a variable of that type, and then using the variable.

    Here is another example based on your latest Type:
    Code:
    Public Type Examples
      Width as Long
      Height as Long
      Top as Long
      Left as Long
    End Type
    Private MyVar as Examples
    ...
    MyVar.Width = 3

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: Public Constants?

    So.... you have to have something be as the Example? then whenever you type MyVar then the . all of the properties would show up in the window? (like width, height, left, top, etc.)
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  11. #11
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Public Constants?

    That is correct.

  12. #12

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: Public Constants?

    Okay. That makes sense. Thanks everyone!
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

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