473,473 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to assign TextBox value to string

Hi All,
I am using .net first time.In my windows form VC7 application, on a
click of button, I am assigning text of TextBox to STL string varibale.
Using this code-

private: System::Void FindValuesButton_Click(System::Object * sender,
System::EventArgs * e)
{
string fileLoc ;
fileLoc= CD_location->Text->ToString();
.......
}

I am getting error-

'initializing' : cannot convert from 'System::String __gc *' to
std::basic_string<_Elem,_Traits,_Ax>'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]

I think this is due to manage class problem. Could anyone tell me, how
can I assign text box value to STL string. Can I use STL string in
VC++.net application.

Regards,
Rachit

Sep 15 '06 #1
2 6063
Hi rachit,

<ra**********@gmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
Hi All,
I am using .net first time.In my windows form VC7 application, on a
click of button, I am assigning text of TextBox to STL string varibale.
Using this code-

private: System::Void FindValuesButton_Click(System::Object * sender,
System::EventArgs * e)
{
string fileLoc ;
fileLoc= CD_location->Text->ToString();
......
}

I am getting error-

'initializing' : cannot convert from 'System::String __gc *' to
std::basic_string<_Elem,_Traits,_Ax>'
<snip/>
I think this is due to manage class problem. Could anyone tell me, how
can I assign text box value to STL string. Can I use STL string in
VC++.net application.
Have a look at System.Runtime.InteropServices.Marshal
You'll find StringToHGlobalAnsi and StringToCoTaskMemAnsi.
That gives you a native char* pointer you can assign to std::string
instances.
Do not forget to call FreeHGlobal or FreeCoTaskMem to release the memory.

--
SvenC

Regards,
Rachit

Sep 16 '06 #2

<ra**********@gmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
Hi All,
I am using .net first time.In my windows form VC7 application, on a
click of button, I am assigning text of TextBox to STL string varibale.
Using this code-

private: System::Void FindValuesButton_Click(System::Object * sender,
System::EventArgs * e)
{
string fileLoc ;
fileLoc= CD_location->Text->ToString();
......
}

I am getting error-

'initializing' : cannot convert from 'System::String __gc *' to
std::basic_string<_Elem,_Traits,_Ax>'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]

I think this is due to manage class problem. Could anyone tell me, how
can I assign text box value to STL string. Can I use STL string in
VC++.net application.

Regards,
Rachit
Rachit,

I believe you can use the properties Char and Length of System::String
to pull out the individual characters and place them in a wchar_t array then
assign your STL string to the array. However note 2 things: First, you will
need to append an '\0' character to the end of the wchar_t array; Second,
from your listing of the error, the STL string template is using <charbut
the System::String is made up of unicode characters. Try declaring your
string as std::basic_string<wchar_t>... I'm a bit rusty but I would try
something along the lines of the following

std::basic_string<wchar_tfileLoc;
wchar_t buffer[255]; //size it appropriately
for(int i = 0; i < CD_location->Text->Length; ++i)
{
buffer[i] = CD_location->Text->Char[i];
}
buffer[CD_location->Text->Length] = wchar_t('\0');
fileLoc = buffer;

HTH - M
Sep 17 '06 #3

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

Similar topics

2
by: dskillingstad | last post by:
I'm trying to assign a custom value to a textbox. Here's what I have. I've created a module and "default value" code for a textbox which generates a custom auto-number (yyyy-0000) when a New...
2
by: Grey | last post by:
I want to assign a value to HMTL textbox with id "txtABC" in ASP.NET with C#
1
by: Shilpi Chaudhry | last post by:
I have a forloop which I use to create textboxes - but unfortunately all of them have the same ids - I need to assign different ids to these textboxes creeated in the loop so that I can retrieve...
8
by: Sergei | last post by:
Hi, I am displaying modal dialog and passing values from the main form to the modal dialog and back. It works fine but if I used the following syntax on Page_Load(just for testing) in VB to...
7
by: I am Sam | last post by:
I have a DataGrid that is passing information to a stored procedure properly but the parameters aren't being casted properly. I was woundering if anyone can tell me how I should properly cast the...
0
by: JJ_377 | last post by:
The following doesn't assign value to the dropdownlist - WHY? ___________________________________________________________________ In a user control (ascx named USACustomer) : Public Property...
6
by: david | last post by:
I try to use "for" loop to retrieve and assign values in web form. The code is in the following. But it can not be compiled. What I want to do is: txtQ1.Text =...
7
by: david | last post by:
I try to use "for" loop to assign textbox control ID to a textbox variable in server side codebehind for a web form. But I met some problem. What I want to do is solving the following-like code by...
5
by: lianping | last post by:
Hi, I have a problem to assign a value into text box, below will be my script. Before view my script, let me hv quick explain on what is my problem: I would like to assign Java script value...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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,...
0
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...
0
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...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.