473,545 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
+ 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 FindValuesButto n_Click(System: :Object * sender,
System::EventAr gs * e)
{
string fileLoc ;
fileLoc= CD_location->Text->ToString();
.......
}

I am getting error-

'initializing' : cannot convert from 'System::String __gc *' to
std::basic_stri ng<_Elem,_Trait s,_Ax>'
with
[
_Elem=char,
_Traits=std::ch ar_traits<char> ,
_Ax=std::alloca tor<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 6077
Hi rachit,

<ra**********@g mail.comwrote in message
news:11******** **************@ k70g2000cwa.goo glegroups.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 FindValuesButto n_Click(System: :Object * sender,
System::EventAr gs * e)
{
string fileLoc ;
fileLoc= CD_location->Text->ToString();
......
}

I am getting error-

'initializing' : cannot convert from 'System::String __gc *' to
std::basic_stri ng<_Elem,_Trait s,_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 StringToHGlobal Ansi and StringToCoTaskM emAnsi.
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**********@g mail.comwrote in message
news:11******** **************@ k70g2000cwa.goo glegroups.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 FindValuesButto n_Click(System: :Object * sender,
System::EventAr gs * e)
{
string fileLoc ;
fileLoc= CD_location->Text->ToString();
......
}

I am getting error-

'initializing' : cannot convert from 'System::String __gc *' to
std::basic_stri ng<_Elem,_Trait s,_Ax>'
with
[
_Elem=char,
_Traits=std::ch ar_traits<char> ,
_Ax=std::alloca tor<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_stri ng<wchar_t>... I'm a bit rusty but I would try
something along the lines of the following

std::basic_stri ng<wchar_tfileL oc;
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
15700
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 Record button is clicked. The code checks the table for the highest value and then assigns 1 and inserts the value. I have a second text box which...
2
3077
by: Grey | last post by:
I want to assign a value to HMTL textbox with id "txtABC" in ASP.NET with C#
1
3008
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 their corrs values. Anybody?? Code snippet: <% int y = 7; %>
8
7386
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 assign value form the object to text Box it gives error 'Object required' Dim strResponse As String strResponse = strResponse & "<script...
7
2098
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 following: (TextBox)UserPrefix=(TextBox)e.Item.Cells.Controls; string strUserPrefix=UserPrefix.Text; I keep getting the following error and I...
0
1775
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 State() As String Get Return Me.ddlState.SelectedValue End Get Set(ByVal Value As String)
6
2252
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 = ds.Tables("mmsSpecRecord").Rows(0)("Q1") txtQ2.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q2") ..... txtQ10.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q10") ------code ------- Dim...
7
9761
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 a loop: static code: txtQ1.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q1") txtQ2.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q2") ........
5
6041
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 into VB text box, but i fail to do so. I can pass value with using: <form id="form1" runat="server">. however I' not able to do so, as i already use...
0
7475
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...
0
7921
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7771
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...
1
5343
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...
0
4958
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...
0
3465
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...
0
3446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
720
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...

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.