473,800 Members | 2,476 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

creating multiple variables with a loop

AMP
Hello,
I am trying to do the following with a loop because the amount of
channels can change.
uint Chan_1 = 0;
uint Chan_2 = 0;
uint Chan_3 = 0;
uint Chan_4 = 0;
uint Chan_5 = 0;
uint Chan_6 = 0;
uint Chan_7 = 0;
uint Chan_8 = 0;
uint Chan_9 = 0;
uint Chan_10 = 0;
uint Chan_11 = 0;
uint Chan_12 = 0;
uint Chan_13 = 0;
uint Chan_14 = 0;
uint Chan_15 = 0;
uint Chan_16 = 0;
Help?
Thanks
Mike
Jun 27 '08 #1
6 5635
"AMP" <am******@gmail .comwrote:
I am trying to do the following with a loop because the amount of
channels can change.
uint Chan_1 = 0;
uint Chan_2 = 0;
[...]
uint Chan_16 = 0;
using System.Collecti ons.Generic;

.. . .

List<uintchans = new List<uint>();

for (uint i = 0; i < 16; i++) // or however many
{
chans.Add(0);
}

Then access the list members with chans[0], chans[1], etc.

Eq.
Jun 27 '08 #2
On Apr 24, 9:09*am, AMP <ampel...@gmail .comwrote:
Hello,
I am trying to do the following with a loop because the amount of
channels can change.
uint Chan_1 = 0;
* * * * * * uint Chan_2 = 0;
* * * * * * uint Chan_3 = 0;
* * * * * * uint Chan_4 = 0;
* * * * * * uint Chan_5 = 0;
* * * * * * uint Chan_6 = 0;
* * * * * * uint Chan_7 = 0;
* * * * * * uint Chan_8 = 0;
* * * * * * uint Chan_9 = 0;
* * * * * * uint Chan_10 = 0;
* * * * * * uint Chan_11 = 0;
* * * * * * uint Chan_12 = 0;
* * * * * * uint Chan_13 = 0;
* * * * * * uint Chan_14 = 0;
* * * * * * uint Chan_15 = 0;
* * * * * * uint Chan_16 = 0;
Help?
Thanks
Mike
It's not clear what you want to do, you cuold simply have one variable
MaxNumberOfChan nels = 16. If you need to keep X differents values then
you use a List

Also, I recommend you to get a book of programming. One of the
programming for Dummies will be a good start
Jun 27 '08 #3
AMP
On Apr 24, 9:16*am, "Paul E Collins" <find_my_real_a ddr...@CL4.org>
wrote:
"AMP" <ampel...@gmail .comwrote:
I am trying to do the following with a loop because the amount of
channels can change.
uint Chan_1 = 0;
uint Chan_2 = 0;
[...]
uint Chan_16 = 0;

using System.Collecti ons.Generic;

. *. *.

List<uintchans = new List<uint>();

for (uint i = 0; i < 16; i++) // or however many
{
* *chans.Add(0);

}

Then access the list members with chans[0], chans[1], etc.

Eq.
Thanks
Thats working good so far but I ran into this:
for (int r = 0; r < 16; r++)
{
UInt32.TryParse ((multiArrayofD ata[x, 1, 0] +
multiArrayofDat a[x, 1, 1]),
System.Globaliz ation.NumberSty les.HexNumber, null, out chans[r]);
}

with this error:
A property or indexer may not be passed as an out or ref parameter.
How do I get arount this?
Jun 27 '08 #4
AMP
On Apr 24, 9:57*am, AMP <ampel...@gmail .comwrote:
On Apr 24, 9:16*am, "Paul E Collins" <find_my_real_a ddr...@CL4.org>
wrote:


"AMP" <ampel...@gmail .comwrote:
I am trying to do the following with a loop because the amount of
channels can change.
uint Chan_1 = 0;
uint Chan_2 = 0;
[...]
uint Chan_16 = 0;
using System.Collecti ons.Generic;
. *. *.
List<uintchans = new List<uint>();
for (uint i = 0; i < 16; i++) // or however many
{
* *chans.Add(0);
}
Then access the list members with chans[0], chans[1], etc.
Eq.

Thanks
Thats working good so far but I ran into this:
for (int r = 0; r < 16; r++)
* * * * * * * * {
* * * * * * * * * * * * * UInt32.TryParse ((multiArrayofD ata[x, 1, 0] +
multiArrayofDat a[x, 1, 1]),
System.Globaliz ation.NumberSty les.HexNumber, null, out chans[r]);

* * * * * * * * }

with this error:
A property or indexer may not be passed as an out or ref parameter.
How do I get arount this?- Hide quoted text -

- Show quoted text -
Paul, Thanks
Ignacio, Depending on the language you could create variables by using
Var+i .
PHP Example: $_POST['ref'.$x.'_emai l']
I was originnaly using a Array but Paul came up with a better Idea.
I write in 3 different languages every day and there are differences
that I dont always know about.
This is why I use the message boards, Not to tell me to get a book.
Mike
Jun 27 '08 #5
"AMP" <am******@gmail .comwrote:
UInt32.TryParse ((multiArrayofD ata[x, 1, 0] + multiArrayofDat a[x, 1,
1]), System.Globaliz ation.NumberSty les.HexNumber, null, out chans[r]);
with this error: A property or indexer may not be passed as an out or
ref parameter.
Well, chans[r] is an indexer (check the documentation if you aren't
familiar with that idea), and as it says you aren't allowed to do that.
I suppose it's because indexers are allowed to be read-only.

So just use a temporary variable instead.

uint temp = chans[r];
UInt32.TryParse ( .... out temp);
chans[r] = temp;

It does sound like you could benefit from a book or tutorial, because
these aren't very advanced C# topics.

Eq.
Jun 27 '08 #6
AMP
On Apr 24, 11:42*am, "Paul E Collins" <find_my_real_a ddr...@CL4.org>
wrote:
"AMP" <ampel...@gmail .comwrote:
UInt32.TryParse ((multiArrayofD ata[x, 1, 0] + multiArrayofDat a[x, 1,
1]), System.Globaliz ation.NumberSty les.HexNumber, null, out chans[r]);
with this error: A property or indexer may not be passed as an out or
ref parameter.

Well, chans[r] is an indexer (check the documentation if you aren't
familiar with that idea), and as it says you aren't allowed to do that.
I suppose it's because indexers are allowed to be read-only.

So just use a temporary variable instead.

uint temp = chans[r];
UInt32.TryParse ( .... out temp);
chans[r] = temp;

It does sound like you could benefit from a book or tutorial, because
these aren't very advanced C# topics.

Eq.
Actually,
This works fine:
chans[r]= UInt32.Parse((m ultiArrayofData[x, b, 0] +
multiArrayofDat a[x, b, 1]),
System.Globaliz ation.NumberSty les.HexNumber);
Mike
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
3235
by: shank | last post by:
I have a recordset that contains multiple records of product a user is purchasing. For clarity, I converted the recordset fields to variables. I need to take that entire recordset and insert it into another table on a remote server. The below code only inserts 1 record. How do I change the code to get all records inserted? thanks! <% Dim DataConn2 Set DataConn2 = Server.CreateObject("ADODB.Connection")
1
4675
by: Knocked Wood | last post by:
Hi, I looked around and can't find anything on this at all and can not get it to work for IE. I'm trying to loop multiple sounds on a game, with three unique variables, when a link is clicked. Something like... <Script Language="JavaScript"> <!-- function playSound(soundName, loops, timeLength){
6
4301
by: Ben Hallert | last post by:
Hi guys, I'm trying to figure out what bone headed mistake I made on something I put together. I've got a form (named 'context') that has a variable number of select-multiple inputs on it. Based on the number of variables passed through a GET string, I want to multiply the total number of selected items for each together to see how many possible combinations the selected items are generating. The following snippet of code...
2
1561
by: Dave Monk | last post by:
Hi, I'm reasonably proficient in PHP but have been asked how to do something which has got me stumped. Hence, my posting: I want to create a small number of variables, $pos1, $pos2 ... $pos5 within a loop and assign them values from an array, but creating the variable names with incrementing numbers, well I've no idea how the PHP syntax for it works.
2
6695
by: Thall | last post by:
Hey Gurus - I've seen a few solutions to this problem, but none of which I can do without a little help. Here's the situation The following code loops thru a sales report, using the sales rep ID as a filter so that multiple reports are created. This is now generating a PDF report, but I need to change it to RTF documents. My question is, since I can't create an RTF using open report, is there a way to use the strFilter with the OutputTo...
4
4035
neo008
by: neo008 | last post by:
Hi all, Finally gave up and putting it here. I am new to visual basic stucked up with an error- Run time errors.'-2147217887 (8004021)': Multiple-step operation generated errors. check each status value. Error comes at ADODC.RECORDSET.UPDATE command.
1
2490
by: joe_doufu | last post by:
I'm creating a page with multiple "widgets", each with its own XMLHttpRequest object, so the user can play with the widgets in parallel. The widgets are enclosed in divs with class "widget" and a unique ID which tells me the name of the PHP file for the widget. Each widget should be able to access its PHP file with GET and POST methods, and to re-draw its innerHTML on response. I am using a simple Ajax library called XHConn...
13
12805
by: jkimbler | last post by:
As part of our QA of hardware and firmware for the company I work for, we need to automate some testing of devices and firmware. Since not everybody here knows C#, I'm looking to create a new scripting language that makes writing automated tests simpler. Really, I'm looking to kind of abstract the power of the C# language into a simpler language that's easier to learn. The script files would be interpreted by a script interpreter...
10
58217
by: charlie.xia.fdu | last post by:
Hi C++ users, for(int i=0,int j=10 ; i<5&&j<10 ; i++ , j--) {} example from: http://www.tech-faq.com/iterations.shtml Is not valid in my eclipse cdt. Is there multiple initialization in C++? How can we use that? Thanks!
0
9690
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
9551
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
10251
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
10033
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
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
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();...
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
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.