• 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 (2 Viewers)

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
Long takes up to approximately 2 billion.

Doubling an Integer is barely 128 thousand.
 

allGenreGamer

Member
Joined
Nov 26, 2003
Messages
111
Yeah, as in the program restarts from the very beginning. Basically shutting down then reloading automatically.
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
Originally posted by allGenreGamer
Yeah, as in the program restarts from the very beginning. Basically shutting down then reloading automatically.
I remember there's an actual method of doing that, but don't quite remember, but you can go with a sleezy inefficient but workable method.
 

J0n

N/A
Joined
Aug 28, 2003
Messages
410
Gender
Male
HSC
2004
If the reason you want to restart your program is to reset all the controls and variables on a form, you could just unload it, then reload it again:
Code:
Public Sub Restart()
	Unload Form1
	Load Form1
	Form1.Show
End Sub
Otherwise, you will probably have to look up some API or something for adding your application to task scheduler. Another way would be to Shell (execute) your program again, then kill the old instance. e.g.
Code:
Public Sub Restart()
	Dim AppPath As String
	AppPath = IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\")
	Shell AppPath & App.EXEName & ".exe"
	End
End Sub
 

Owyn

Member
Joined
Feb 1, 2004
Messages
102
Location
Sydney, NSW
Gender
Male
HSC
2006
Parameters

Does anyone know how to pass variables from one form to another without using global, and i know how to send variables to subprograms, but how do you get that sub program to return a variable without turning it into a function?
 

Winston

Active Member
Joined
Aug 30, 2002
Messages
6,128
Gender
Undisclosed
HSC
2003
Originally posted by Owyn
Does anyone know how to pass variables from one form to another without using global, and i know how to send variables to subprograms, but how do you get that sub program to return a variable without turning it into a function?
I have no idea what you're really asking... if you wanna pass a variable to another form, you should have a set function in the other form

for example


Form 1

has a integer type called Number with the value 5

Dim Number as Integer = 5

so that's in Form 1

and you want Form 2 to get this value


in Form 2

Dim NumberPassedFromForm1 as Integer

Sub setNumber (NumberFromForm1 as integer)

NumberPassedFromForm1 = NumberFromForm1

End Sub
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
Does anyone know how to pass variables from one form to another without using global
As per Winston's suggest, use get/set functions in either form to access each other's private variables.

how do you get that sub program to return a variable without turning it into a function?
Subs do not return values by definition. Functions return values by definition. ie, you shouldnt have a sub that returns a value.

The only way to get a sub to return a value is to pass one of its arguments by reference, essentially turning it into a pointer.
 

Owyn

Member
Joined
Feb 1, 2004
Messages
102
Location
Sydney, NSW
Gender
Male
HSC
2006
thanks for the help. I know that functions are perfect for what i'm after, however i also need it to interact with the actual form, so i didn't want to use function, but it Winstons method looks like it could work. Thanks again.
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
Functions can interact with forms. What exactly are you trying to do?
 

Owyn

Member
Joined
Feb 1, 2004
Messages
102
Location
Sydney, NSW
Gender
Male
HSC
2006
Yeh, there just not meant to, their meant to be independent, so they can be used with any other project.
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
You can pass the form as a parameter to the function, so that the function can interact with any form you pass it.
 

Owyn

Member
Joined
Feb 1, 2004
Messages
102
Location
Sydney, NSW
Gender
Male
HSC
2006
It didn't seem to work, however i did mangage to change what I'm after to a sub that is passed 2 parameters. I tested it and it works fine for one, but when i try to pass a second it goes screwy.

Just and idea of what I'm after:

Dice(Dice1, Dice2) //Meant to be calling the sub and sending variales Dice1 and Dice2//

Sub Dice(Dice1, Dice2) //Top line of the sub i created//

This works if i kill dice2 from both, but when i added it either expects an = or says theres a syntax error.
 

J0n

N/A
Joined
Aug 28, 2003
Messages
410
Gender
Male
HSC
2004
Originally posted by Owyn
This works if i kill dice2 from both, but when i added it either expects an = or says theres a syntax error.
To get rid of that error, try removing the brackets when you call your subprogram, or altenately, put the word "Call" in front. e.g.

Dice Dice1, Dice2

OR

Call Dice(Dice1, Dice2)
 

Owyn

Member
Joined
Feb 1, 2004
Messages
102
Location
Sydney, NSW
Gender
Male
HSC
2006
Thankyou, that worked perfectly, the first i don't know if it works but the second works. Thankyou
 

Owyn

Member
Joined
Feb 1, 2004
Messages
102
Location
Sydney, NSW
Gender
Male
HSC
2006
This next question is even more difficult to ask, because i don't know if its possible or not. Is there any command i can do so that the code in a procedure stops running, like happens with breakpoints, and won't resume until a conditon in the interface?
 

J0n

N/A
Joined
Aug 28, 2003
Messages
410
Gender
Male
HSC
2004
In the IDE, the Stop statement will pause the excecution of your program until you press play again, like breakpoints, although i don't think that is what you want.
The best way is probably to just use a boolean flag, and not do something until that flag is set to True. e.g

While Flag = False
Doevents
Wend

You would set the boolean variable 'Flag' to True, on the event that you want the code to resume on.
 

Kulazzi

Active Member
Joined
Aug 10, 2003
Messages
1,736
Location
Condell Park
Gender
Female
HSC
2005
Ok, I'm a prelim student currently working on a mini project in class, which is to make a simple timer. Now, I have a warning sign coming up when there is ten seconds left to go and a picture of an "alarm clock" when there is 5 secs left to go. What I wanna do is have the alarm clock flashing/blinking (teacher says animating), how do I go abt doing that???? :confused:

also where can you download VB 6.0 from?
 
Last edited:

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
how do I go abt doing that????
Read up on the timer control, and change a picturebox/imagebox's picture when the timer control fires.

where can you download VB 6.0 from?
Buy it, or ask your school for help.
 

J0n

N/A
Joined
Aug 28, 2003
Messages
410
Gender
Male
HSC
2004
To make the time flash, you can just change the .ForeColor propertey of the Label/Textbox you are using to display the time. e.g.

Private Sub Timer1_Timer()
Label1.ForeColor = IIf(Label1.ForeColor = vbBlack, vbRed, vbBlack)
End Sub

You can't download VB 6 free (legally). Although you can download the Control Creation Edition, which has a few limitations such as you can't compile, or you could buy a VB 6 book that has 'VB 6 Working Model Edition' who's only limitation is that you can't compile (there is a registry hack for that on the net ;) ).
 

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

Top