Emuforums.com

Go Back   Emuforums.com > General Discussion > Web development / Programming
About Us Register FAQ Members List Calendar Mark Forums Read

Login to remove all ads!
Reply
 
LinkBack Thread Tools Display Modes
Old May 13th, 2004   #1 (permalink)
Ataru Moroboshi Fan =)
 
Metalmurphy's Avatar
 
Join Date: Jun 2001
Location: Portugal, Oporto
Posts: 5,759
Quick question about Visual Basic!

Anyof u guys know how to declair a variable so we can use it in diff forms? Kinda stuck here and need some help

Thks in advanced!
Metalmurphy is offline   Reply With Quote
Old May 13th, 2004   #2 (permalink)
I want you INSIDE me
 
Kirby's Avatar
 
Join Date: Mar 2002
Location: Massachusetts, USA
Posts: 8,382
Don't you use the global variable?
Code:
Private strExample As String
But I only think that applied to the current form. Other than that, I think you can't have 1 variable declared to all the forms at once.
__________________

Kirby's AnimeDB list
AMD Athlon64 X2 4400+ Toledo, Nvidia GeForce 7950GT SLi, 2GB PC3200 2-3-2-5, ABit AN8-SLi, Sound Blaster X-FI XtremeMusic
Kirby is offline   Reply With Quote
Old May 13th, 2004   #3 (permalink)
Administrator
 
Chrono Archangel's Avatar
 
Join Date: Dec 2001
Location: Montreal, Canada
Posts: 7,129
make a Module and declare it Public
Code:
Public Variable as Integer
And in properties change your start form to the Module

and in the module put
Code:
Sub Main()

Application.Run(New MainForm)

End Sub
//MainForm being the form you want to start with
Chrono Archangel is offline   Reply With Quote
Old May 13th, 2004   #4 (permalink)
Ataru Moroboshi Fan =)
 
Metalmurphy's Avatar
 
Join Date: Jun 2001
Location: Portugal, Oporto
Posts: 5,759
Well i rememberd that i didnt use any modules last time i did it! I just had to initialize the variable some way and they i only need to put <formname>.<variable>! Thks anyway
Metalmurphy is offline   Reply With Quote
Old May 13th, 2004   #5 (permalink)
Puchiko-nyu!
 
kairi00's Avatar
 
Join Date: Jul 2001
Location: 49° 11' N 123° 10' W
Posts: 2,854
Declare the variable as "public" at the beginning of the form.

Public strVal As String

Then you can access it by using formname.strVal
__________________
"Not every ejaculation deserves a name."

--- George Carlin
kairi00 is offline   Reply With Quote
Old May 13th, 2004   #6 (permalink)
Administrator
 
Chrono Archangel's Avatar
 
Join Date: Dec 2001
Location: Montreal, Canada
Posts: 7,129
yup like Kairi00 a said. thats how you can access then via fromain.variable
ive always worked with modules since its easier to know where the global variables are and it saves me from always writing formname. (usefull when you need to access alot the variables from alot of forms)
Chrono Archangel is offline   Reply With Quote
Old May 14th, 2004   #7 (permalink)
Ataru Moroboshi Fan =)
 
Metalmurphy's Avatar
 
Join Date: Jun 2001
Location: Portugal, Oporto
Posts: 5,759
Aye thats it! Thks guys
Metalmurphy is offline   Reply With Quote
Old May 28th, 2004   #8 (permalink)
Ataru Moroboshi Fan =)
 
Metalmurphy's Avatar
 
Join Date: Jun 2001
Location: Portugal, Oporto
Posts: 5,759
Ok guys i have a new problem I used a module to declare the Win32 function "sndPlaySound" like this:

Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

then whenever i wanted to play a sound i would call the function like this:

sndPlaySound App.Path & "\soms\tiro.wav", SND_ASYNC


The sound does play, however it stops the program untill the sound is finished. Is there anyway to play a sound in the background without freezing the program?

And another thing... anyof you know how to play a MIDI file in VB
Metalmurphy is offline   Reply With Quote
Old May 28th, 2004   #9 (permalink)
Administrator
 
Chrono Archangel's Avatar
 
Join Date: Dec 2001
Location: Montreal, Canada
Posts: 7,129
Quote:
Originally Posted by Metalmurphy
Ok guys i have a new problem I used a module to declare the Win32 function "sndPlaySound" like this:

Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

then whenever i wanted to play a sound i would call the function like this:

sndPlaySound App.Path & "\soms\tiro.wav", SND_ASYNC


The sound does play, however it stops the program untill the sound is finished. Is there anyway to play a sound in the background without freezing the program?

And another thing... anyof you know how to play a MIDI file in VB
havent made mouch test yet but you can try this for MidiFiles.
Attached Files
File Type: zip cd97783e9aMidiFile.zip (3.3 KB, 24 views)
Chrono Archangel is offline   Reply With Quote
Old May 28th, 2004   #10 (permalink)
Ataru Moroboshi Fan =)
 
Metalmurphy's Avatar
 
Join Date: Jun 2001
Location: Portugal, Oporto
Posts: 5,759
Thks for the help Chrono Archangel but that code only seems to work in VB.net! Im using VB 6.0! :/

*edit* I was able to play the midi file same way as used with the wave file... however samething happens! While the music is playing the program freezes!
Metalmurphy is offline   Reply With Quote
Old June 5th, 2004   #11 (permalink)
Banned
 
Join Date: May 2004
Posts: 151
You need to play the sound asynchronously, meaning along with everything else. Do it like this
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" ( ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

Const SND_ASYNC = &amp;H1
Const SND_NODEFAULT = &amp;H2

Private Sub Command1_Click()
sndPlaySound "mysound.wav", SND_ASYNC Or SND_NODEFAULT
End Sub


Also you could always just use the "Do Events" tag but that is annoying to a degree and much easier to just set up the sound to sync at the inital.
jaydawg is offline   Reply With Quote
Old June 5th, 2004   #12 (permalink)
Ataru Moroboshi Fan =)
 
Metalmurphy's Avatar
 
Join Date: Jun 2001
Location: Portugal, Oporto
Posts: 5,759
Thks jaydawg but i already saw it in a vb tutorial page! Thks anyway

Trying to figure out how to work with files now to save high-scores and stuff like that! But i think this website covers that!
Metalmurphy is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 23:14.

© 2006 - 2008 Emu Forums | About Emu Forums | Legal | A member of the Crowdgather Forum Community


Powered by vBulletin® Version 3.7.0 Release Candidate 3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5