• Congratulations to the Class of 2024 on your results!
    Let us know how you went here
    Got a question about your uni preferences? Ask us here

Variables (1 Viewer)

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
The scope of a variable refers to which parts of the program can have access to it, for example Public, Private, Dim in visual basic. if the scope was changed to public then it can be globally accessed within the same solution.
 

velox

Retired
Joined
Mar 19, 2004
Messages
5,521
Location
Where the citi never sleeps.
Gender
Male
HSC
N/A
ah ic, i was a bit lost on the scope part. Cool thank u! I have another question though :(
Procedures and functions are different types of subprograms. What is the difference between the two in terms of how they are called by higher-level routines?
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
Well procedures do a certain task, it does blah blah and that's it, then returns control back to the caller, for functions, they provide a return value generally, just like maths, you know f(x) is a function, and when you sub in x, you'd get y, right?

hmmm i'm not sure about the higher-level routines bit.
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
wrx said:
Got it now. You said the same thing as what the textbook was saying. thanks
HAHA i wrote it ;)

lol jks, hope it helps.
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
wrx said:
Lol You are in the book though. "Winston" is a ficticious language in there somewhere.
HAHAH madness :D
 

velox

Retired
Joined
Mar 19, 2004
Messages
5,521
Location
Where the citi never sleeps.
Gender
Male
HSC
N/A
I have another question :( What exactly does this algorithm do. I tried to follow it but ended up getting lost.

Public Sub DrawLines(Numlines As Integer)
Dim Coord (1, 1) As Integer
Dim CurrentLine as Integer

Randomise Timer
Coord(0, 0) = 0
Coord(0, 1) = 0
CurrentLine = 1
While CurrentLine < Numlines
Coord (0, 1) = Int(Me.Width * Rnd)
Me.Line (Coord(0, 0), Coord(0,1))-(Coord(1,0), Coord(1, 1))
Coord(0, 0) = Coord(1,0)
Coord(0, 1) = Coord(1, 1)
CurrentLine = CurrentLine + 1
Wend

End Sub


Do u think it would be suitable for inclusion into a library of code? Or is it too specific?
 

J0n

N/A
Joined
Aug 28, 2003
Messages
410
Gender
Male
HSC
2004
Hmm.. That code looks a bit buggy - where did you get it from. It looks like it is supposed to draw a number (NumLines) of lines starting from the origin. i.e the origin to some point in the form, then another line from the other end of that line and so on... Maybe it is supposed to have:
Coord(1, 0) = Int(Me.Width * Rnd)
Coord(1, 1) = Int(Me.Height * Rnd)
Instead of just:
Coord (0, 1) = Int(Me.Width * Rnd)
Also, you may have to change the datatype of Coord to Long, as Integer may be a bit too small. And, randomize doesn't have an 's' (at least not in VB) and i don't think you need the word 'Timer' either.
 
Last edited:

SamD

Member
Joined
Jul 21, 2002
Messages
256
Gender
Male
HSC
N/A
The code is VB6, it's question 14 of Set 5D in my SDD prelim text. However it has not been copied correctly from the text (as JOn quite rightly points out). JOn's corrections are essentially correct as is his description of what the algorithm does.

Here's the original:

Public Sub DrawLines(Numlines As Integer)
Dim Coord(1, 1) As Integer
Dim CurrentLine As Integer

Randomize Timer
Coord(0, 0) = 0
Coord(0, 1) = 0
CurrentLine = 1
While CurrentLine < Numlines
Coord(1, 0) = Int(Me.Width * Rnd)
Coord(1, 1) = Int((Me.Height - 500) * Rnd)
Me.Line (Coord(0, 0), Coord(0, 1))-(Coord(1, 0), Coord(1, 1))
Coord(0, 0) = Coord(1, 0)
Coord(0, 1) = Coord(1, 1)
CurrentLine = CurrentLine + 1
Wend

End Sub


Actually an Integer datatype is within the bounds of most screens. Integers range up to 32767 and by default VB6 uses twips. 1024 pixels equates to some 15480 twips (in VB6), so you'd need to use a screen resolution greater than about 2000 pixels wide to run into problems.

HTH
Sam
 

velox

Retired
Joined
Mar 19, 2004
Messages
5,521
Location
Where the citi never sleeps.
Gender
Male
HSC
N/A
Im now thinking that it would be suitable for inclusion into a library of code, as it could be put to many uses (yet to think of any :p). Am I thinking in the right direction?
 

SamD

Member
Joined
Jul 21, 2002
Messages
256
Gender
Male
HSC
N/A
For inclusion in a library of code it needs to be totally general in terms of its interface and it needs to deal with any errors that could be encountered. In other words it should be able to be used without knowing how it works just what it does.

It's almost right, however if you were to add this Sub to a VB6 module it would NOT quite work, the use of Me will cause problems. You'd need to pass the form as a parameter to the Sub and then it should work from a module. It also needs some code for dealing with errors.

Why you would want to draw lines all over a form is another issue. I'm fishing a bit, but maybe you could use it to indicate an error has occured, or with some modification it could be used as an indicator that background processing is occuring.

HTH
Sam
 

SamD

Member
Joined
Jul 21, 2002
Messages
256
Gender
Male
HSC
N/A
wrx said:
Lol You are in the book though. "Winston" is a ficticious language in there somewhere.
In reality Winston is the name of my dog. Apologies to the non-canine Winston!
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
SamD said:
In reality Winston is the name of my dog. Apologies to the non-canine Winston!
HAHAH! it's alright Sam, i knew of a dog named Winston in the quarantine service thing, and a friend of mine in America's dog is also named Winston haha
 

raymes

Member
Joined
Jan 21, 2004
Messages
116
Location
Sydney
Gender
Male
HSC
2004
the charade is over winston...we know your true identity is a dog
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
raymes said:
the charade is over winston...we know your true identity is a dog
LOL no i'm not! *bites raymes* (oh shit the dog behaviour is slowly divulging)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top