Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old August 1st, 2003, 02:13 AM
Wizard2003's Avatar
Wizard2003 Wizard2003 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 206 Wizard2003 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 29 m 24 sec
Reputation Power: 6
how 2 use public variables

Hi all,

I'm very new to VB and so it did not last long until the first question occured.
In the following code I want to display the four variables in the myFunction function.
In the cmdOK_Click routine all values are displayed.
In the myFunction function the message box is empty.
Thanks in advance

Code:
Public Function myFunction()
  MsgBox (val1 & val2 & val3 & val4)
End Sub

Private Sub cmdOK_Click()
  Public val1 As String
  Public val2 As String
  Public val3 As String
  Public val4 As String
  val1 = field1.Text
  val2 = field2.Text
  val3 = field3.Text
  val4 = field4.Text
  MsgBox (val1 & val2 & val3 & val4)
End Sub

Reply With Quote
  #2  
Old August 1st, 2003, 09:18 AM
Onslaught's Avatar
Onslaught Onslaught is offline
/(bb|[^b]{2})/
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2001
Location: Somewhere in the great unknown
Posts: 4,834 Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level)Onslaught User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 23 h 30 m 30 sec
Reputation Power: 88
Send a message via ICQ to Onslaught
To use public global variables, declare the variables at the top of the form, or in a module.

If you declare them public they will be available everywhere throughout your program, if you declare them private they will be available only in the module/form that you declared them in.

i.e.
Code:
Option Explicit

Public sVal1 As String
Public sVal2 as String
Public sVal3 as String
Public sVal4 as String

Public Sub anExample()
  MsgBox val1 & val2 & val3 & val4
End Sub

Private Sub cmdOK_Click()
  val1 = field1.Text
  val2 = field2.Text
  val3 = field3.Text
  val4 = field4.Text
  Call anExample
End Sub

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > how 2 use public variables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway