|
Thank you for your reply!
Sorry, that was a typo on my part. I had ["+ GD +"]. GD doesn't show up in the popup but the name of the second form does (GetDelimiter). I used this as well but it throws the error:
GetDelimiter is a 'type' but is used like a 'variable'.
When I use GD it throws the error:
GD does not exist in the current context.
What am I doing worng here?
Thank you!
|
|
|
|
|
If I understand you correctly, you want to get a value from the second Form in the first?
If so, create a public property or method in the second Form, and call that from the first using the instance of the second Form.
string specialText = form2.TextIWant
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)
|
|
|
|
|
Yes, that is correct. I want to capture the value from the second form and use it in the first.
in the second form I have this:
public void textBox1_TextChanged(object sender, EventArgs e)
{
string GD;
GD = textBox1.Text;
}
then I am calling it in the first form with this:
String comString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetDirectoryName(FilePath) + @";Extended Properties=""text;HDR=YES;FMT=Delimited("+ GD +")";
Both methods were made public before posting. Should have mentioned that.
When I declare another string in the first it only allows me to write:
string GDS = GetDelimiter.GD
This throws an error:
Doesn't contain a definition for GD.
|
|
|
|
|
Keep a reference to the second form when you instanciate it and use that reference.
A simple example. Button on Form1, TextBox on Form2:
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private Form2 form2;
public Form1()
{
InitializeComponent();
form2 = new Form2();
form2.Show();
}
private void button1_Click(object sender, EventArgs e)
{
if (form2 != null)
MessageBox.Show(form2.GD);
}
}
}
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
GD = textBox1.Text;
}
public string GD
{
get;
set;
}
}
}
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)
|
|
|
|
|
Having a problem with get and set. The error I receive for:
public void textBox1_TextChanged(object sender, EventArgs e)
{
GD = textBox1.Text;
}
public string GD
{
get;
set;
}
Error: get and set must declare a body because it is not marked abstract or extern.
I tried adding some code to get and set and I received this error:
public void textBox1_TextChanged(object sender, EventArgs e)
{
//GD = textBox1.Text;
}
public string GD
{
get { return GD; }
set { GD = value; }
}
Error:Make sure you do not have an infinite loop or infinite recursion.
Any ideas?
|
|
|
|
|
The problem is caused by your new public property. Change the case of the field references.
Change:
public string GD
{
get { return GD; }
set { GD = value; }
}
to:
public string GD
{
get { return gd; }
set { gd = value; }
}
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.”
|
|
|
|
|
Sorry, I'm not following. As you can guess I am not a very good programmer. Just starting out and I thank you for your patience. I do not have any private fields in the second form. Do I need to declare gd as private? Something like:
public void textBox1_TextChanged(object sender, EventArgs e)
{
GD = textBox1.Text;
gd = GD;
}
private string gd;
public string GD
{
get { return gd; }
set { gd = value; }
}
|
|
|
|
|
Almost right. Well worked out!
just a small change
public void textBox1_TextChanged(object sender, EventArgs e)
{
GD = textBox1.Text;
gd = GD;
}
private string gd;
public string GD
{
get { return gd; }
set { gd = value; }
}
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.”
|
|
|
|
|
All right, it works!!! One more issue though. I placed a messageBox in the code on the first form and I am getting the correct string delimiter. So I know GD is storing this, however, when I go to call GetDelimiter.GD for the in the connection I get an ArgumentException was unhandled error:
Format of the initialization string does not conform to specification starting at index 85.
Here is the connection string:
String comString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetDirectoryName(FilePath) + @";Extended Properties=""text;HDR=YES;FMT=Delimited["+ GetDelimiterForm.GD +"]";
The error occures at:
OleDbConnection conTXT = new OleDbConnection(comString);
I know it has something to do with FMT=Delimited["+ GetDelimiterForm.GD +"]"; because if I hard code it it has no problems (FMT=Delimiter(TAB)""";). I have tried replacing "[" with "(" and that doesn't work. Any ideas on this one?
|
|
|
|
|
When you hard code it you are using slightly different syntax
Hard coded: FMT=Delimiter(TAB)
Using GetDelimiterForm: FMT=Delimited[......
Delimiter and Delimited, or is that just a typo?
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.”
|
|
|
|
|
I apologize, it was a typo. What I meant was
Hard Coded: FMT=Delimited(TAB) \\This works
Using GetDelimiterForm: FMT=Delimited["+ GetDelimiterForm.GD +"]\\This throws the error
|
|
|
|
|
It is the double quote thing for Extended Properties that is causing the problem.
In order to get a quotation mark within a literal string you have to 'escape them'
This means that the double quotes in the middle have to look like \"\", for them to be recognised as quotes within a string.
When this is all over look up Escape Characters for a better explanation.
In the mean time take a look at ADO Connection Strings[^], for some examples. Search in the article for 'Extended Properties' and you'll see what I mean.
Have a play.
Good Luck!
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.”
|
|
|
|
|
Thank you Henry for all your help. I will look into this today.
|
|
|
|
|
Hi Henry,
I have read a couple articles on escape sequences and have tried to include the same line of code(just modified to fit what I need) and I still get errors. Maybe I am looking in the wrong place but when I try and use
Extended Properties=\"\"text;HDR=Yes;FMT=Delimited(" + gds + ");\"\";"; it says I need to add ";". But when I add one it tells me I need to add another. However, if I were to plug the line of code above into the code found in the Code Project page it seems fine. I think what is happening is that there is something wrong with the first part of the connection string, maybe the Source.
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetDirectoryName(FilePath) + @";
Could you look at this one more time for me and point me in the right direction when you have time please? Here is the entire connection string:
String comString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetDirectoryName(FilePath) + @";Extended Properties=\"\"text;HDR=Yes;FMT=Delimited(" + gds + ");\"\";";
Thank you,
Brenton
|
|
|
|
|
I have found an article that is doing what I think you are trying to do.
Read text file (txt, csv, log, tab, fixed length)[^], it only uses one \" instead of two.
Have a look and see if it 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.”
|
|
|
|
|
That did it Henry. Thank you so much. Is there something I need to do is far as closing this out or giving you a rating? Let me know and I will come back.
|
|
|
|
|
Thanks for the thanks!
If you would just vote one of my posts as a 5, then people will know that your question has been answered.
Good luck!
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.”
|
|
|
|
|
Sorry, I was using automatic properties which may not be available in the version that you're working with.
Follow Henry's advice and use a private member variable that the property getter and setter accesses.
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)
|
|
|
|
|
There are two layers in my project. one is business layer,and the other is UI layer.
In UI layer, i invoke the method 'SaveInfo' of business layer. by the way ServiceActivator.GetService.
But i can't get 'newInfo' in UI layer.
and if i remove 'throw ex;' in 'SaveInfo' method. i could get it.
i don't know why.
do you know? how could i get newInfo if i want to throw Exception to UI layer.
pls. ths.
'SaveInfo' in Business layer:
public void SaveInfo(ref StudentInfo info,ref List<studentinfodetail> detailList,string strType)
{
try
{
...
info = newInfo;
detailList = newDetailList;
throw new MyException("Information already exist.");
...
}
catch(Exception ex)
{
throw ex;
}
}
the invoke code in UI layer:
try
{
...
mMyDs.SaveInfo(ref curInfo,ref curList,"Add");
...
]
catch(MyException mex)
{
textBox1.text = curInfo.Name;
}
catch(Exception ex)
{
}
MSN:msnadair@hotmail.com
Skype:skyadair
modified on Tuesday, May 12, 2009 8:52 PM
|
|
|
|
|
I have to say that returning to a calling process by throwing an exception is not the normal way to do it.
It would be better to give SaveInfo() a return type of bool and instead of throw new MyException use return true; .
Then in your calling code use
if (mMyDs.SaveInfo(ref curInfo,ref curList,"Add"))
{
}
else
{
}
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.”
|
|
|
|
|
No,i can't. i need to do this.
i should return the latest data from database if the info already exist. and the info may have different status, i should throw out the hint.
MSN:msnadair@hotmail.com
Skype:skyadair
|
|
|
|
|
I have a serial ports list. I declared it like this:
<br />
private List<SerialPort> lstSerialPorts;<br />
<br />
for (int i = 1; i<=cont; i++)<br />
{<br />
SerialPort tempPort = new SerialPort("COM" + cont.ToString(), 2400);<br />
lstSerialPorts.Add(tempPort);<br />
lstSerialPörts[i].DataReceived += SerialDataReceivedEventHandler(TEST_FUNCTION);<br />
}<br />
My TEST_FUNCTION is empty so far:
<br />
<br />
void TEST_FUNCTION(object sender, SerialDataReceivedEventArgs e)<br />
{<br />
throw new NotImplementedException();<br />
}<br />
As you can see, all serial ports have the same handler function. How could I check which serial port triggered the TEST_FUNCTION? It would be great something like this:
<br />
void TEST_FUNCTION(object sender, SerialDataReceivedEventArgs e)<br />
{<br />
Console.WriteLine("This function was triggered by: {0}",anUnknownVariable);<br />
}<br />
Parameter "e" does not have any useful property or function
Any help would be apreciated and excuse me about my English if I made a mistake
Ivan
|
|
|
|
|
You've looked at the e parameter - now try the other one!
The clue is in the name 'sender'. Cast it to a SerialPort from object and you now have the object that raised the event.
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)
|
|
|
|
|
Use the sender object, cast it to SerialPort and you will get the object who triggered the function.
Sincerely Samer Abu Rabie
Imagination is more important than knowledge !
|
|
|
|
|
If 'e' is not a lot of use, have you considered looking at 'sender', by any chance?
If you expand it in the debugger, you may find it is a SerialPort object.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|