473,772 Members | 2,448 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I turn variable created in function global so I can access in another function

2 New Member
I am developing a windows application in C#. I have a button that creates an array when pressed. How do I make it so I can use the created array in another function of the same program?
Dec 11 '12 #1
3 1911
zmbd
5,501 Recognized Expert Moderator Expert
That would have to deal with the scope of the array.
You will have to post your code dealing with the array.

Please use the <CODE/> button to format the posted code.

Please clearly describe your code, what it is, what it does, and what is not doing along with any errors your receive (include both the error number and the message details).

Also, please bear in mind that Bytes is not a code writting nor a homework service. We'll help you thru the problem.
Dec 11 '12 #2
rami16512
2 New Member
Expand|Select|Wrap|Line Numbers
  1. string[] Words = new string[] { "php", "html", "cplusplus", "csharp", "java", "oracle", "mysql", "python" };
  2.  
  3. public void Start_Click(object sender, EventArgs e)
  4. {
  5. Random R = new Random();
  6.             string word = Words[R.Next(0, 7)];
  7.             char[] charWord = word.ToCharArray();
  8.  
  9.             int count = charWord.Length;
  10.  
  11.             Label[] label = new Label[9] { label0, label1, label2, label3, label4, label5, label6, label7, label8 };
  12.             for(int j = 0  ; j < 9; j++ )         
  13.             {
  14.                 label[j].Text = "";
  15.             }
  16.  
  17.             for (int i = 0; i < count; i++)
  18.             {
  19.                 label[i].Text = charWord[i].ToString();
  20.             }
  21. }
I want to be able to use charWord[] in ANOTHER button that I have AFTER initiating it here.
Dec 12 '12 #3
Rabbit
12,516 Recognized Expert Moderator MVP
Initiate it in the function but declare it outside of the function.
Dec 12 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
1498
by: Bart Nessux | last post by:
I have 2 functions among others. One gets a URL and returns its, For example, it returns 'http://127.0.0.1' How can I pass this to another function? I've never worked with code that has lots of functions before. def receive_targets_url(): # This recievies the DDOS target's URL I = socket(AF_INET, SOCK_STREAM) I.bind((DDOS_ZOMBIE_IP, U_PORT)) I.listen(5) conn, addr = I.accept()
3
1429
by: uli | last post by:
Hi all, I've learned native C and I'm trying to write now in C++. I want to use a simple routine from the "Numerical Recipes in C" for using a Newton-Raphson Method within my c++ class. The Newton-Raphson function for finding roots is called: float rtsafe(void (*funcd)(float, float *, float *), float x1, float x2, float xacc) 'funcd' is the pointer to an external function as common in C. But since I want to use it with a member...
4
5028
by: Pushkar Pradhan | last post by:
I want a function to execute another function, which I pass to it, sometimes it may be mm_6r6c_6r6c, mm_2r2c_2r2c, ... etc. thus this style. double exec_basecase(void (*func)(double *a, double *b, double *c), double *a, double *b, double *c, int numRowsA, int numColsA, int numColsB) { ...../*other code*/ func(a, b, c); ..... }
5
1729
by: AK | last post by:
I'm writing a Windows Forms application in C++.NET. I've defined function F which takes 2 arguments a & b. I need to use the pointer of F inside another function G & I can't figure out how to do it properly. Here's what I have : U32 (*pf) (HANDLE, LPVOID); //declaring the function pointer U32 __stdcall F (HANDLE a, LPVOID b) //defining F
4
3889
by: tdick | last post by:
Does anyone know sql of the PV function in Access? (same function in Excel) In access the inputs are PV («rate», «nper», «pmt», «fv», «due») where rate = discount rate, nper = number of payments, pmt = payment) other two are not required. nper is allowed to be a number with decimals, not just an integer. Seeking sql code which will replicate the above, including nper with
2
1175
by: Phil | last post by:
Hi Can anybody tell me how to get a function to call another function once it has finished processing. That is, I have a function which I run, in its own thread, which does some processing. As soon as it is done, I would like it to call another member in the main form of the application. Can anybody give me some ideas on how to do this? I seem to recall reading something about a callback function (?) which may do the job? Is that right?
1
1351
by: dutzend | last post by:
Hi NG, i try to do the following: function Init() { alert('Anything'); } pushInit(alert('Anotherthing'));
5
1495
by: robbiesmith79 | last post by:
Hey fellow nerds, Take this code for example: class hello { function world() { echo "Hello"; } }
8
1512
by: arperidot | last post by:
Write a program which calculates the integral of the function f(x)=g(x)/n! , where g(x)=1+K*cos^n(n*x) on the interval from a to b (a<b). In the main program, scanf a non-negative integer value of n and double values of K, a, and b. Call the function Integ() to evaluate the integral. Your main program should be followed by four functions:
2
1519
by: lucas vidgen | last post by:
Hi, I am working on a google map where you can show lines on the map by checking checkboxes. Lines are displayed according to their category attribute in the xml file. The function that picks up the checkbox click is like this: function boxclick(box,category) { if (box.checked) { show(category); } else { hide(category); }
0
9619
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9911
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.