|
Hello,
How can i declare a string in a loop that the name of the variable will be changed for example according the index of the loop. For example if i will do:
for(i=1;i<5;i++)
string k[i]="something";
it will make me 4 string variables:
k1,k2,k3,k4
I mean the name itself will be changed.
I can't use arrays instead.
|
|
|
|
|
You can't, variable names are declared at compile time.
Why you can't use an array?
|
|
|
|
|
because i want to use it as adding columns to a datagridview.
And i need it to be in loop because i take those variables from a regkeys i save before.
Can i save antire array as regkey , then read it from the registry and then add it as column names to the datagridview?
|
|
|
|
|
Use a dictionay instead.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
If what you want to do is set the name of the column, or set its headertext then you can do this in the way you first suggested.
string columnBaseName =
for (int i = 1; i < 3; i++)
{
DataGridViewTextboxColumn newColumn = new DataGridViewTextboxColumn();
newColumn.Name = columnNameBase + i.ToString();
newColumn.HeaderText = columnNameBase + i.ToString();
this.dataGridView1.Columns.Add(newColumn);
}
Hope this helps.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Or a dictionary...
Dictionary<int, string> getString;
for access using the int value, or
Dictionary<string, string> getString;
for access using a name (e.g. "myName"+i.tostring() )
There are three kinds of people in the world - those who can count and those who can't...
|
|
|
|
|
there is another ways to do that for example :
System.Collections.ArrayList arr = new System.Collections.ArrayList();
for (int i = 0; i <= 10; i++)
{
arr.Add(i);
}
Console.WriteLine(arr[3]);
I know nothing , I know nothing ...
|
|
|
|
|
If it's always the same object type that's being put in the array list and you're using 2.0 or above, then better to use a generic list List<T> where T is the type of the object i.e. List<string> .
ArrayList involves unboxing/boxing which isn't a great idea.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Noted , Thank you.
I know nothing , I know nothing ...
|
|
|
|
|
Hi there!
I have a client/server program that work properly at the Internet, but with computers that have valid IP. Really I want to make a connection between two computer at the Internet that haven't valid IP, like computers that connect to internet with ISPs, that have a local IP and another IP on Internet (their server IP).
Please see below picture to understand me.
See Here
In the picture, left PC (192.168.20.14) can connect to right ISP (86.110.112.34) easily, but I want to connect to right PC (200.100.114.45). To do this, I think I have to use Port Forwarding technique. Can someone help me please?
Thanks all.
|
|
|
|
|
That is the job of router. You must set port forwarding of your router.
For example, just set port TCP:100 to IP 192.168.20.14.
In that case, if you make a connection to 86.110.112.34:100, it will
be forwarded to 192.168.20.14.
|
|
|
|
|
Thanks a lot.
but I think you mean, "if you make a connection to 92.124.210.110, it will be forwarded to 192.168.20.14".
|
|
|
|
|
"92.124.210.110" <- you don't mention it before.
probably you have a dynamic IP from your ISP.
|
|
|
|
|
I need to use some sort of pointer or other way for a variable to contain the name of another variable, it is a bit difficult to explain but the following (not correct) code will give the idea.
string varName;
string myVar;
myVar = "varName";
&myVar = "Whatever";
Now Variable varName contains "Whatever"
Any ideas or directions ?
Thanks
|
|
|
|
|
You're referring to unsafe code. Yes, you can. It's not recommended because of the potential for memory leaks, but it's possible. You wrap the code using pointers in an unsafe block, like so:
unsafe
{
}
Then you have to coerce VS into compiling it. Project properties->Build->Allow unsafe code
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Actually re-reading it I see I explained it wrongly.
What I need is an evaluations something like below is often used in scripting languages.
string varName;
string myVar;
myVar = "varName";
eval(myVar) = "Whatever";
Now Variable varName contains "Whatever"
Basically I have an array with 2 columns, 1st column has the variable name and the second has the value.
I do not want to have something like
for(x = 0; x < arrayRows; x++;)
{
if(array[x,0] = "myVar1") {myVar1 = array[x,1]}
if(array[x,0] = "myVar2") {myVar2 = array[x,1]}
..
..
}
I would like something like
for(x = 0; x < arrayRows; x++;)
{
eval(array[x,0]) = array[x,1]}
}
Of course eval does not exist in C#
Any ideas or directions ?
Thanks
|
|
|
|
|
As CG said below, you may want to use a class to store these values, using Reflection (namespace System.Reflection) to get their names and get and set their values dynamically
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
You need to learn some C# basics. You can do this by creating a class to store your variable. And I'm not sure you can do what you want with pointers in C#, C# pointers are pretty limited.
Christian Graus
Driven to the arms of OSX by Vista.
Please read this[ ^] if you don't like the answer I gave to your question.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
|
|
|
|
|
Hello everybody,
First of all thanks a lot for all of yours' support on forums, blogs and dev networks with the help of which development becomes very easy and motivating.
I've developed an addin for Outlook 2003 using VSTO SE and VS 2005 (C#). By referring to the articles regarding deployment I was able to manage to create its MSI installer from setup and deployment project in the solution. The addin gets properly installed on other machines having Outlook 2003 and works there fine. All the security policies are granted properly as well. I am using SetSecurity project for granting trust to assemblies. For that I had referred to articles
Deploying Visual Studio 2005 Tools for Office Solutions Using Windows Installer Part 1 & 2 (http://msdn.microsoft.com/en-us/library/aa537173(office.11).aspx) (http://msdn.microsoft.com/en-us/library/aa537179.aspx)
Now I want to deploy the same addin for Windows Vista. I am aware of the issues faced due to UAC. The major issue is regarding admin access to installer and need of presence of registry keys in HKLM when UAC is turned off. In my installer project I can add those additional registry keys in Registry view. Now my questions are (finally ...)
1. I want to know whether it is possible to use a single installer for Windows XP and Windows Vista. If yes, how can I determine OS version in my Custom Actions or Launch Conditions?
2. If answer to previous question is positive then are there any changes required in method of granting trust to assemblies For Windows Vista? I've already stated that I'm using modified version of SetSecurity project for that.
3. How can determine in Windows Vista whether the UAC has been turned on or off? How can I set a registry launch condition for that so that I can register additional keys in HKLM hive. I'm anyways going to add keys in HKCU for both XP as well as Vista.
4. How can I add those registry keys if I find that it's Windows Vista and UAC is turned off?
I've read articles. They say all about where to change in the registry of Windows Vista, but not how to change it.
* Deploying Application Level Addins (http://msdn.microsoft.com/en-us/library/ms269007(VS.80).aspx)
* Deploying Visual Studio 2005 Tools for the Office System SE Solutions Using Windows Installer (Part 1 of 2) (http://msdn.microsoft.com/en-us/library/bb332051.aspx)
* Deploying Visual Studio 2005 Tools for the Office System SE Solutions Using Windows Installer: Walkthroughs (Part 2 of 2) (http://msdn.microsoft.com/en-us/library/bb332052.aspx)
Thanks a lot once again for your appreciation. Awaiting the reply.
regards,
Chaitanya
|
|
|
|
|
Chaitanya Joshi wrote: how can I determine OS version in my Custom Actions or Launch Conditions?
See here[^]
Chaitanya Joshi wrote: How can I add those registry keys if I find that it's Windows Vista and UAC is turned off?
See here[^] ( Also notice where this page is in MSDN (see the location links at the top ), it's in the Windows Installer Documentation. You may find many answers here, like this one, if you just look )
|
|
|
|
|
Thanks Led...
Very precious links.
But word about MSDN links... I was not investigating what registry keys were to be added but where to add them as in which section of VS Setup & Deployment Project by checking the necessary conditions.
Thanks for help though...
|
|
|
|
|
Chaitanya Joshi wrote: which section of VS Setup & Deployment Project
I don't know what that means. Windows Installer has tables, I don't know what "section" means.
|
|
|
|
|
Hi
i have access db as client db and sql server db as web db. all structures of two database is same except PKs, in sql server PK is uniqueidentifier and in access, PK is Text (with 255 max Length).
in client app i want to send some data from client to web(access to sql) via SqlBulkCopy class, to do this, i use this code to transfer data :
this.personsTableAdapter1.Fill(this.testDataSet1.Persons);
DataTable dtImported = this.testDataSet1.Persons.Clone();
dtImported.Columns["PersonID"].DataType = typeof(Guid);
foreach (TestDataSet.PersonsRow row in this.testDataSet1.Persons.Rows)
{
Guid g = new Guid(row.PersonID);
dtImported.Rows.Add(new object[] { g, row.PersonName });
}
System.Data.SqlClient.SqlBulkCopy bc = new System.Data.SqlClient.SqlBulkCopy(Properties.Settings.Default.TestSqlConnectionString);
bc.DestinationTableName = "Persons";
bc.WriteToServer(dtImported);
but at runTime the following error show me in above line of code:
Cannot set column 'PersonID'. The value violates the MaxLength limit of this column.
where does my problem and how to solve it ?
Thanks
|
|
|
|
|
hdv212 wrote: The value violates the MaxLength limit of this column
Doesn't the error message explain the reason.
The length of the PersonID you specified in the Access and SQL Server are different. Infact, SQL Server has lesser size thn that of in the Access.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Hi Manas
yes, hence i change max length from 255 to 16 in DataSet Designer(in visual stduio), but the problem was not solved.
|
|
|
|