Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VARIANT question...

Status
Not open for further replies.

Hylsan

Programmer
Mar 20, 2002
43
SE
Hi
Got a little problem with the line below, i cant understand what i should put after the ",".

SendEvent(LPCTSTR bstrNodeName, VARIANT *pvarNodeValue)

The NodeValue should be "1", but
SendEvent("nodename",1)
doesnt work, giving me the following error;

error C2664: 'SendEvent' : cannot convert parameter 2 from 'const int' to 'struct tagVARIANT *'

Thanks in advance!
/Hylsan
 
you need to do something like

tagVariant tv;
tv = 1;
SendEvent("nodename",&tv)
Matt
 
nope...tried that...and im getting this error;

error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'const int' (or there is no acceptable conversion)

/Hylsan
 
the variant type should have some member variables. You would need to set them specifically if there are not acceptable conversions. Look at the tagVariant struct and see what it has for member vars. Then set the appropriate type. If the variant type has member funcitons, there should be one that will coincide with the value type. Also, there may be other ways of accessing the variant type. I vaguely remember when I used automation in my program there was a funciton that I called that set the variant type for me.

Matt
 
Well...i finally solved it...somehow :)

It should look like this (for those interested)

tagVARIANT NodeValue;
nisse.boolVal=true;
m_eon1.SendEvent("data_in", &NodeValue);

Thanks for your quick response.

/Hylsan
 
I got the same problem with Hylsan, but I don't understand how you solve the problem. what's the meaning of
nisse.boolVal = true;

*Janus*
 
oh im sorry....this is how it should be;

tagVARIANT NodeValue;
NodeValue.boolVal=true;
m_eon1.SendEvent("data_in", &NodeValue);

if its a integer you want to transfer it should look like this;

tagVARIANT NodeValue;
NodeValue.intVal=int;

for a float;

tagVARIANT NodeValue;
NodeValue.fltVal=float;

need any more help feel free to reply.

/Hylsan
 
Hello Hylsan,

Need some help on tagVARIANT. The example you used is to set the value for tagVARIANT. How do we go about reading the value from a tagVARIANT?

Thanks,
Sie
 
well...i dont know if any of this will help you, tho this is how the function looks like in my testprogram.
I can recommend looking up "COleVariant" in help/msdn. that looks like a much better way than with tagVariant.

Code:
void CAxtestDlg::OnOnEventEonx1(LPCTSTR bstrNodeName, VARIANT FAR* pvarNodeValue)
{
	tagVARIANT test=*pvarNodeValue;
	CString intext=test.bstrVal;

	MessageBox(intext);
}

/Hylsan
 
Hyslan,

From the above I was able to solve my own Variant problem when getting data from the MSComm activeX control which throughs out data in the variant form. Hope this helps others.

Code:
void CPortComDlg::OnOnCommMSComm()
{
  tagVARIANT test = m_ctlMSCommPort.GetInput();
  CString intext = test.bstrVal;
  CEdit* pGpsOutputBox = (CEdit*)GetDlgItem(IDC_GPS_OUTPUT_BOX);
  pGpsOutputBox->SetWindowText(intext);
}
NB I had to increase the RThreshold of the port to an appropriate level - say 10 . The above then puts the string data into my edit box for viewing.

The only thing that I need to do now is figure out how to grab the strings I want as they come in various lengths and represent different types of info. Well here's to hoping, but I think that it is pub time!

Cheers[2thumbsup][cheers]

Richard
 
There's also a _variant_t, which is there to make living with VARIANTs a bit less painfull...


Greetings,
Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top