Visual Basic question

liunx

Guest
..Return is not a keyword in visual basic. To return a value from a function, you need to referance its name and assign it a value.


Private Sub moose()
moose = "Hello World"
End Sub

Private Sub Command1_Click()
MsgBox moose()
End Sub

By convention, its best to use uppercase for the first letter of your functions and sub routines. (e.g. Moose)

Regards...Oh, you have to specify the return type.

Private Function Moose() As String
Moose = "Hello World"
End Sub

Private Sub Command1_Click()
MsgBox(Moose())
End Sub

Regards.

Has been several years since I used Visual Basic.

EDIT: Just noticed another thing. Your using a sub, rather than a function. A sub cannot return a value. See my code now.

Regards...No worries. ;)Yes, it is cleaner.

Using a lot of global variables can result in a code that is hard to understand and maintain.

I would recommend getting a book on the language or doing a few basic tutorials on the internet if you plan on pursuing programming in the future.

These are pretty fundamental concepts that will need to be solidified for your ultimate success.

Good Luck :)..The good thing about helping others is it will test how much you really know and help you solidify what you do know.

I hope it all goes well for you!

:)..
 
Back
Top