By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,513 Members | 1,791 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,513 IT Pros & Developers. It's quick & easy.

Getting values from a combobox?

P: 4
Hello

I want to use a combobox to select which COM port on the pc my interface uses.

at the moment i'm using this (which dose not work)
private: System::Void button6_Click(System::Object * sender, System::EventArgs * e)
{
char com[4];

for(int k=0;k<comboBox1->Text->Length;k++)
com[k]=comboBox1->Text->Chars[k];
SerialPort.Open(com, 19200);
}

i get the warning message: conversion from '__wchar_t' to 'char', possible loss of data.

in the combobox drop down bit is "COM1,COM2,COM3,COM4,COM5,COM6,COM7,COM8"

Is there a way to make this work in c++??
May 31 '07 #1
Share this Question
Share on Google+
5 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
Any reason this cannot be a wchar_t array?

Expand|Select|Wrap|Line Numbers
  1. char com[4];
  2.  
If memory serves, you aren't supposed to use char around COM.
May 31 '07 #2

P: 4
[quote=weaknessforcats]Any reason this cannot be a wchar_t array?

Expand|Select|Wrap|Line Numbers
  1. char com[4];
  2.  
nope. thanks for that, i was trying to make too complicated as usual

I'll give it a go, but will let know if there are any other problems
May 31 '07 #3

P: 4
i think it maby dose need to be a char array
because i did as you said and got this
error C2664: 'CComPort::Open' : cannot convert parameter 1 from 'wchar_t [4]' to 'char *'


unless there is a way to convert wchar_t to char?
May 31 '07 #4

P: 3
i think it maby dose need to be a char array
because i did as you said and got this
error C2664: 'CComPort::Open' : cannot convert parameter 1 from 'wchar_t [4]' to 'char *'


unless there is a way to convert wchar_t to char?
hah! it would be better to just make it a char array, or maybe use an intermediate variable for conversion purposes.
Jun 1 '07 #5

P: 4
hah! it would be better to just make it a char array, or maybe use an intermediate variable for conversion purposes.
What is a "intermediate variable" and how would I use it for conversion purposes?
Jun 1 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.