• Best of luck to the class of 2024 for their HSC exams. You got this!
    Let us know your thoughts on the HSC exams here
  • YOU can help the next generation of students in the community!
    Share your trial papers and notes on our Notes & Resources page
MedVision ad

VB Help Topic (1 Viewer)

allGenreGamer

Member
Joined
Nov 26, 2003
Messages
111
I have a question regarding Visual Basics: how do I declare global variables?
Btw if anyone else has questions with VB plz ask here. Since many ppl would prob use VB for their major project, let's all help each other out. Thanks.
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
Declare it outside of a method....

public number as integer
 

allGenreGamer

Member
Joined
Nov 26, 2003
Messages
111
Refer to your previous thread.
sorry, serious forgotten as it has been such a long time. :p

another question. I've declared variables under "option explicit", but when I use them in a different form it says "variable not defined" - how can I can declare variables so that they're available in multiple forms? Is that actually possible? Or do they have to be declared as public... sorry this question might be really pathetic but this is my first programmin experience so please approve.
 

J0n

N/A
Joined
Aug 28, 2003
Messages
410
Gender
Male
HSC
2004
Yes, you have to declare it as Public, and refer to it as Form1.variable - where Form1 is then name of the form containing the variable, and variable is the name of the variable (der :p), or declare it in a module (not a form).
 

allGenreGamer

Member
Joined
Nov 26, 2003
Messages
111
You ppl have been extremely helpful! I can't believe how fast I receive these replies! Thanks for being so willing to guide me through my project :)
This is not VB related... but I need it for the "Design Specifications" stage. In Microsoft Words, how do I bring up the toolbar that enables me to draw dataflow diagrams, structure diagrams etc? My friend did it for me at school but I forgot how to bring it up :p

variable is the name of the variable (der )
heheheh :D
 

Seraph

Now You've done it.......
Joined
Sep 26, 2003
Messages
897
Gender
Male
HSC
N/A
Originally posted by allGenreGamer
You ppl have been extremely helpful! I can't believe how fast I receive these replies! Thanks for being so willing to guide me through my project :)
This is not VB related... but I need it for the "Design Specifications" stage. In Microsoft Words, how do I bring up the toolbar that enables me to draw dataflow diagrams, structure diagrams etc? My friend did it for me at school but I forgot how to bring it up :p


heheheh :D
Oh in microsoft word

its just the autoshapes i think you are talking about
Go to View - Toolbars - and tick Drawing

:D
 

allGenreGamer

Member
Joined
Nov 26, 2003
Messages
111
Hmmm... I've typed this under "Option Explicit" in coinGame.frm:

dim coinResult as string

Next in coinGame2.frm I typed this:

Private Sub Form_Load()

Select Case coinGame.coinResult
(irrelvent :))
End Select

End Sub

But I get the error "method or data member not found"! Please help me. coinGame.coinResult should work shouldn't it? Since I declared it in coinGame.frm... sorry I just don't get it :(
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
Use:
Code:
Public coinResult As String
instead of
Code:
Dim coinResult As String
 

allGenreGamer

Member
Joined
Nov 26, 2003
Messages
111
Thank to u ppl I've finally completed the first section of my project! :) :D :cool: ;)

Another question. I know how to make an event occur every (say 2 second) interval by using a timer. How can I make an event occur ONCE after a certain amount of time has elasped? Thanks.
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
Disable the timer at the end of the event you fired.

Code:
Timer.Enabled = False
 

allGenreGamer

Member
Joined
Nov 26, 2003
Messages
111
Quick question: How do I call a module I've created in VB? Thanks. Unfortunately I don' have the VB help file so :(
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
You can't call a module. You can only call the functions inside a module. If the functions are public, you can just call them by their function name anywhere in the program.
 

allGenreGamer

Member
Joined
Nov 26, 2003
Messages
111
Can someone plz write an example of declaring and defining a function in a module, and then calling the function in the program? Sorry I'm seriously this lost :(
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
In a module:

Code:
Public Sub Testing()
    MsgBox "this is from a public function"
End Sub
In your form (in form load for example):
Code:
Private Sub Form_Load()
    Testing
End Sub
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
Hmmm isn't that Sub-Routine though, i thought he wanted to know about functions in modules

none the less here's how to declare a function in a module



Function myFunction() As String
myFunction = "Test"
End Function

put this function in a Module

and if you want to test that function out

just for testing purposes put a button on a form

and in the Command Click event put in


MsgBox(Module1.myFunction)

and this should print out Test in a message box.

hope that helps.
 

allGenreGamer

Member
Joined
Nov 26, 2003
Messages
111
Thanks. With u ppl's help I've managed to place subprograms into modules and my code is finally looking elegant! :) :) :)
New questions. How do I DIM a two dimensional array?
How do I reset a timer?

Thanks, my project is going well thanks to u ppl :cool:
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
Code:
Dim test(2, 2) As Integer
creates a 3x3 integer array

Reset a timer? Enabled = True
 

allGenreGamer

Member
Joined
Nov 26, 2003
Messages
111
New questions:
- Which datatype can store up to 180000? When I use "integer" it says "out of range".
- Is there a function that enables the program to restart? (like "end" quits the program automatically)
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
Originally posted by allGenreGamer
New questions:
- Which datatype can store up to 180000? When I use "integer" it says "out of range".
- Is there a function that enables the program to restart? (like "end" quits the program automatically)
I'm pretty sure Long can store up to that, it think it's double of Integer, but then again i'm not quite remembering whether or not Integer was 32 bit under VB 6, cause if it was then Long would be double it. But from the looks of it i just tried it, long holds that value range you specified.

Allows the program to restart? You mean it shutsdown then reloads again?
 

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

Top