|
-
Jul 27th, 2010, 02:31 PM
#1
Thread Starter
Fanatic Member
[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?
-
Jul 27th, 2010, 02:44 PM
#2
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.
-
Jul 27th, 2010, 07:06 PM
#3
Thread Starter
Fanatic Member
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?
-
Jul 27th, 2010, 09:56 PM
#4
Thread Starter
Fanatic Member
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?
-
Jul 28th, 2010, 05:25 AM
#5
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.
-
Jul 28th, 2010, 07:40 PM
#6
Thread Starter
Fanatic Member
Re: Public Constants?
So there isn't really a plus to using types than just plain ol' variables?
-
Jul 29th, 2010, 02:10 AM
#7
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.
-
Jul 29th, 2010, 02:19 PM
#8
Thread Starter
Fanatic Member
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
????
-
Jul 30th, 2010, 02:32 AM
#9
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
-
Jul 30th, 2010, 01:51 PM
#10
Thread Starter
Fanatic Member
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.)
-
Jul 30th, 2010, 02:18 PM
#11
-
Aug 1st, 2010, 12:01 AM
#12
Re: Public Constants?
Yea, types/structs are extremely useful, but they take a while to get used to.
Software I use and highly recommend: Opera, Miranda IM, Peerblock, Winamp, Unlocker Assistant, JoyToKey, Virtual CloneDrive, Secunia PSI, ExplorerXP, GOM Player, Real Alternative, Quicktime Alternative,Sumatra PDF, and non-freeware: Photoshop and VB6( ).
My codebank: AllRGB, Rounded Rectangle(math), Binary Server, Buddy Paint, LoadPictureGDI+, System GUID/Volume Serial, HexToAsc, List all processes and their paths, quasiString matching
Strings(search, extraction, retrieval etc): Retrieve BBCode Link from HTML, RemoveBetween ()'s, strFindBetween(str1,str2), Insert text in HTML, HTML - GetSpanByID
-
Aug 1st, 2010, 01:19 PM
#13
Thread Starter
Fanatic Member
Re: Public Constants?
Okay. That makes sense. Thanks everyone!
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
|