global variable

Reply

Join Date: Dec 2009
Posts: 13
Reputation: cabsjonel is an unknown quantity at this point 
Solved Threads: 0
cabsjonel cabsjonel is offline Offline
Newbie Poster

global variable

 
0
  #1
Dec 25th, 2009
hi! folks merry christmas and happy new year to all of you
ahhm! i have problem in using the .bas module i mean declaring global varibles from it, I try several times to use the variable that i declared in .bas module but did not work so can you help me.. and give some example program from it

hoping for your kindness


God bless all
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 543
Reputation: selvaganapathy is an unknown quantity at this point 
Solved Threads: 97
selvaganapathy's Avatar
selvaganapathy selvaganapathy is offline Offline
Posting Pro
 
0
  #2
Dec 25th, 2009
Hi, Happy Christmas and Happy New Year.

Lets come to the discussion,
Use Public keyword declare a public variable in a module so that all other modules and forms can access it.

Ex:-
  1. 'In a module
  2. Public sUserName As String

'In a Form (Form1 )
' - Draw a Button (Command Button - cmdSetUser)
' >> Add Form (Form2)
' - Draw a Button (Command Button - cmdShowUser)
  1. 'In Form1
  2. Option Explicit
  3.  
  4. Private Sub cmdSetUser_Click()
  5. sUserName = "ABCD"
  6. Form2.Show
  7. End Sub

  1. 'In Form2
  2. Option Explicit
  3.  
  4. Private Sub cmdShowUser_Click()
  5. MsgBox sUserName
  6. End Sub

But avoid often using global variables.
Last edited by selvaganapathy; Dec 25th, 2009 at 6:08 am.
Selva
Reply With Quote Quick reply to this message  
Join Date: Dec 2009
Posts: 13
Reputation: cabsjonel is an unknown quantity at this point 
Solved Threads: 0
cabsjonel cabsjonel is offline Offline
Newbie Poster
 
0
  #3
Dec 25th, 2009
hey! thanks brother ur such a generous person now i know how to use it ahhm! bro why do you say that avoid often using global variable is it cause a lot of memory but thanks anyway,
but bro i have a big problem about my project its a lending system
our teacher give this kind of project and he told us to self study only
and you know i have only 1 week to finish it and i dont know what to do bro can you help me pls
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 543
Reputation: selvaganapathy is an unknown quantity at this point 
Solved Threads: 97
selvaganapathy's Avatar
selvaganapathy selvaganapathy is offline Offline
Posting Pro
 
0
  #4
Dec 25th, 2009
When u use global variable, u may face some problems .
See this site for detail. It is common for all the languages. So dont use it often.

Dont worry about your project.

Just try out your project, if u have any doubt u post it here.
Definitely not only myself, any one can help you .. but try from your side is very important .. Do well.
Selva
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 634
Reputation: abu taher is an unknown quantity at this point 
Solved Threads: 43
abu taher's Avatar
abu taher abu taher is offline Offline
Practically a Master Poster
 
0
  #5
Dec 26th, 2009
nice. what kind of problem u faced u not mentioned. so tell it clearly.
I like sword. Attack or Defense.
my web
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 564 | Replies: 4
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC