MFC CString to integer weird problems
Hi there!
I need help with conversion from CString to int.
I've already tried the _ttoi function, but it returns
characters (such as: a, d, G, ? ,( etc...). What's the problem.
I use MS VC++ 6.0 compiler. here's the bit of the code causing problems.
I'm trying to get a percent of two values.
void MyBaseClass::OnMyMessage()
{
CString str1;
CString str2;
int i1;
int 12;
int percent;
str1=("100");
str2=("1000");
i1 = _ttoi(str1);
i2 = _ttoi(str2);
percent = ((i1) / (i2) * 100);
output.SetPos(percent);
}
[611 byte] By [
DragonArt] at [2007-11-11 7:44:40]

# 7 Re: MFC CString to integer weird problems
try using this DragonArt
CString String_Name_X,String_Name_XX; \\string name setup
int x = 10; \\interger setup
long double xx= 10.01;\\long double setup
String_Name_X.Format("%d",x);\\CString to int
int x_string_int = atof(String_Name);\\int now equals string
String_Name_XX.Format("%d",xx);\\CString to int
long double xx_string_double = atof(String_Name_XX);\\int now equals string
String_Name_X.Format("%d", String_Name_X);\\CString to display int
String_Name_XX.Format("%4.2f",String_Name_XX);\\CString to display int
MessageBox("The output of the int is: " + String_Name_X + "\nThe output of the long double is: " + String_Name_X);
# 8 Re: MFC CString to integer weird problems
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14) [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '='.
<%@LANGUAGE="VBSCRIPT"%>
<%
const action_add="add"
const action_view="view"
const action_delete="del"
const action_edit="edit"
const validate_yes="y"
const norecordselected=-9999
%>
<html>
<LINK rel=stylesheet href=menu.css type=text/css>
<script language=JavaScript src=content1.js></script>
<script language=JavaScript src=menu.js></script>
<body topmargin="0" leftmargin="0">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="780" height="110">
<param name="movie" value="toplinks.swf">
<param name="quality" value="high">
<embed src="toplinks.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="780" height="110"></embed></object>
<br>
<div id="Layer1" style="position:absolute; width:313px; height:22px; z-index:1; left: 461px; top: 112px;">
<div align="right"><font color="#00FFFF" face="Comic Sans MS">Bangalore Division</font></div>
</div>
<img src="pagehead.gif" width="780" height="28"> </body>
<!--#include file="database.asp"-->
<!--#include file="adovbs.inc"-->
<%
'Main Processing loop
sub main()
dim straction
dim blnisvalidation
dim stn
%>
<body>
<h5 align="right">
<%
response.write "<a href=""list.asp""><font face='Arial' size='2' color='blue'>Back</a>"
%> -
<a href="login.asp?out=logout"><font face="Arial" size="2" color="blue">Logout</a>
</h5>
<%
tn=request("tn")
set objrs=server.CreateObject("adodb.recordset")
strsql="select * from sbcswrtds where tn=" & tn [B] --> Error comes here
objrs.open strsql,objconn,3,3
%>
<table align="center">
<tr><td height="25"><font size=3 face="Verdana, Arial, Helvetica, sans-serif" color="blue"><b>Are you sure to delete "<%=objrs("tn")%>"</b></font></td></tr>
</table>
<form name="form1" method=post action="deletetn1.asp" onSubmit="return validate();" >
<p>
<table align="center">
<tr>
<td></td>
<td height="80">
<input type="submit" name="submit1" value="Delete" ></td></tr>
</table>
</p>
</form>
<h5 align="right">
<%
response.write "<a href=""list.asp""><font face='Arial' size='2' color='blue'>Back</font></a>"
%> -
<a href="login.asp?out=logout"><font face="Arial" size="2" color="blue">Logout</font></a>
</h5>
<%
end sub
'Code begins executing here
call main
%>
</body>
</html>