|
Hi all,
i m working on vc++ and i have no idea of vb,i saw a vb application and want to do same functioning in my vc++
these are some function please help me to convert it in vc++
Shared Function Encode7Bit(ByVal Content As String) As String
'Prepare
Dim CharArray As Char() = Content.ToCharArray
Dim c As Char
Dim t As String
For Each c In CharArray
t = CharTo7Bits(c) + t
Next
'Add "0"
Dim i As Integer
If (t.Length Mod 8) <> 0 Then
For i = 1 To 8 - (t.Length Mod 8)
t = "0" + t
Next
End If
'Split into 8bits
Dim result As String
For i = t.Length - 8 To 0 Step -8
result = result + BitsToHex(Mid(t, i + 1, 8))
Next
Return result
End Function
Shared Function CharTo7Bits(ByVal c As Char) As String
If c = "@" Then Return "0000000"
Dim Result As String
Dim i As Integer
Dim ij As Integer
For i = 0 To 6
ij = Asc(c)
If (Asc(c) And 2 ^ i) > 0 Then //how write it in vc++
Result = "1" + Result
Else
Result = "0" + Result
End If
Next
Return Result
End Function
Shared Function BitsToHex(ByVal Bits As String) As String
'Convert 8Bits to Hex String
Dim i, v As Integer
For i = 0 To Bits.Length - 1
v = v + Val(Mid(Bits, i + 1, 1)) * 2 ^ (7 - i)
Next
Dim result As String
result = Format(v, "X2")
Return result
End Function
Shared Function EncodeUCS2(ByVal Content As String) As String
Dim i, j, v As Integer
Dim Result, t As String
For i = 1 To Content.Length
v = AscW(Mid(Content, i, 4))
t = Format(v, "X4")
Result += t
Next
Return Result
End Function
thanks in advance
modified on Thursday, January 27, 2011 5:24 AM
|
|
|
|
|
Why don't you start yourself by going line by line? All what I see are only 'Dim' and 'For' statements you need to parse. In VB 'Dim' is to declare a variable.
|
|
|
|
|
What do you really need to do?
Might be easier coding directly your C++ functions (i.e. based just on requirements) instead of mimic the ugly VB .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
Conceptually you should not try to do this. If you want to create a button in WIN32 application you should see the CreateWindow API
I am a HUMAN. I have that keyword in my name........
_AnsHUMAN_
|
|
|
|
|
CButton is a MFC class, so you can't use it in a Win32 without MFC. You will need to create a MFC project if you want to use it.
|
|
|
|
|
You shouldn't.
In other words, you need MFC in order to use a CButton , but, do you really want to bloat with MFC your neat Win32 application just for using CButton ? You may use plain Win32 API function for dealing with buttons.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
hi friends,
i have have a MDI Application. when i close a document using onclosedocument. my document handle remains active though the members used in document are set to null. so i cannot check this condition
if(doc)
as it returns true. whereas in the if block it cannot access the members so app crashes
eg.
<pre>
if(doc) //handle =FAEX000
{
doc->getprivatevariable_or_functions(); // the application crashes here
}
</pre>
thanking in anticipation
REgards
Samir
|
|
|
|
|
How did you allocated the "document" ? I mean how did you create the pointer doc (it seems it is a pointer, right?).
When you release your document (for instance by deleting the memory), you also always have to assign null to it, so that you can check whether it has been deallocated. If you do that, then your code will work properly (the if segment won't be entered since doc is NULL).
|
|
|
|
|
You may override CDocument::OnCloseDocument for marking your document as invalid (you may set a custom property for the purpose) and then check for document validity before any access.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi pallini Sir,
i have main document which has child documents. so in main document i have overridden the function document:oncloseDocumenet() and called ColeDocument:CloseDocument.
Thanks For reply Sir.. but prob still not resolved
Regards
Samir
|
|
|
|
|
See my answer to your reposted question.
I must get a clever new signature for 2011.
|
|
|
|
|
Hello everyone, I have recently joined so I am a newbie. I only have taken one C++ course but am mostly self-taught by you wonderful people in the forums. I used forums to teach myself VBE so now I am using them to get better at C++. Just to be clear, my programming can be akin to a caveman putting a square peg in a round hole, i.e. it won't be pretty but eventually it will get there.
Question I have is, with the following code I kind of expected a zero value to be passed to x when the else part and the if-else was triggered, but it returns an abnormally huge value. This is a .dll being called from VBE.
Please forgive me if I have posted wrong, it is my first post.
<pre></pre>
#include <iostream>
using namespace std;
#include <cmath>
double __stdcall Ts_P(double &arg)//psia input, DegF output
{
double h_reg_1;
double h_reg_2;
double h_reg_3;
double h_reg_4;
double x;
double vl_reg1[10] = {1167.0521452767, -724213.16703206, -17.073846940092, 12020.82470247,-3232555.0322333, 14.91510861353, -4823.2657361591, 405113.40542057, -0.23855557567849, 650.17534844798};
double p = (arg * 0.0068947572); //convert psia to MPa
double beta = pow(p,0.25);
if(p >= 0.000611657 && p <= 22.06495)
{
h_reg_1 = pow(beta,2) + vl_reg1[2] * beta + vl_reg1[5];//IFC 97 E term
h_reg_2 = vl_reg1[0] * pow(beta,2) + vl_reg1[3] * beta + vl_reg1[6];//IFC 97 F term
h_reg_3 = vl_reg1[1] * pow(beta,2) + vl_reg1[4] * beta + vl_reg1[7];//IFC 97 G term
h_reg_4 = (2 * h_reg_3) / ((-1*h_reg_2) - (pow((pow(h_reg_2,2) - 4 * h_reg_1 * h_reg_3), 0.5)));//IFC 97 D term
x = (((vl_reg1[9] + h_reg_4 - pow((pow((vl_reg1[9] + h_reg_4),2) - 4 * (vl_reg1[8] + vl_reg1[9] * h_reg_4)),0.5)) / 2) - 273.15) * (1.8) + 32;
return(x);
}
else{
x=0;
return(x);
}
}
</pre>
|
|
|
|
|
First, if it's returning a large value, then my suggestion as that 'p' is between 0.000611657 && 22.06495.
On the other hand, how do you know that x was assigned '0'?
Second, for programming clarity, may I suggest one of the following: (my preference is #2)
1. getting rid of the two returns and have only one return after the closing brace ({) of the else,
if (a)
{
...
b = 1
}
else
{
b = 2
}
return b;
2. OR, remove the else
if (a)
{
b = 1;
return b;
}
b = 2;
return b;
"If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
|
|
|
|
|
Thank you for your reply. Actually what the code computes is the steam saturation temperature given pressure. The abnormally large value comes in when the p is not between the 0.000611657 and 22.06495. I had no luck with your modification, I am assumin it is in the syntax but have had no luck thus far.
|
|
|
|
|
you posted
if(p >= 0.000611657 && p <= 22.06495)
which fixed up reads:
if(p >= 0.000611657 && p <= 22.06495)
so that means p would be between 0.000611657 && 22.06495
if you want p to be outside that range, then change it to read
if(p < 0.000611657 || p > 22.06495)
"If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
|
|
|
|
|
I may not be clear on the code. p must be between these ranges for the calculation to execute, if it is outside of these ranges then the calculation does not apply and I want a 0 or a -1 returned.
|
|
|
|
|
ah ok, then my question still is, how do you know that x is being assigned 0? or that p is NOT in the desired range?
"If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
|
|
|
|
|
Only in that from the Excel spreadsheet where I am entering the variable p into the function I can set it so that it is outside of the range of the if statement parameters. The value is returns when this is so is something like 1.7878e+308.
|
|
|
|
|
Try throwing in some MessageBox's so you can so the values in the method and the logic flow...
"If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
|
|
|
|
|
I played with the code, this returns the values I need:
double __stdcall Ts_P(double &arg)//psia input, DegF output
{
double h_reg_1;
double h_reg_2;
double h_reg_3;
double h_reg_4;
double x;
double vl_reg1[10] = {1167.0521452767, -724213.16703206, -17.073846940092, 12020.82470247,-3232555.0322333, 14.91510861353, -4823.2657361591, 405113.40542057, -0.23855557567849, 650.17534844798};
double p = (arg * 0.0068947572); //convert psia to MPa
double beta = pow(p,0.25);
if(p >= 0.000611657 && p <= 22.06495)
{
h_reg_1 = pow(beta,2) + vl_reg1[2] * beta + vl_reg1[5];//IFC 97 E term
h_reg_2 = vl_reg1[0] * pow(beta,2) + vl_reg1[3] * beta + vl_reg1[6];//IFC 97 F term
h_reg_3 = vl_reg1[1] * pow(beta,2) + vl_reg1[4] * beta + vl_reg1[7];//IFC 97 G term
h_reg_4 = (2 * h_reg_3) / ((-1*h_reg_2) - (pow((pow(h_reg_2,2) - 4 * h_reg_1 * h_reg_3), 0.5)));//IFC 97 D term
x = (((vl_reg1[9] + h_reg_4 - pow((pow((vl_reg1[9] + h_reg_4),2) - 4 * (vl_reg1[8] + vl_reg1[9] * h_reg_4)),0.5)) / 2) - 273.15) * (1.8) + 32;
return(x);
}
else
{
x=-1;
}
return(x);
}
|
|
|
|
|
congratulations! good for you!
"If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
|
|
|
|
|
Thank you very much for your help.....in troubleshooting this I realize that I need to figure out how to operate the debugger. I can attach it to Excel and add the breakpoints, however it seems to do nothing. Again, thank you so much...
|
|
|
|
|
also, have you tried attaching the code to a debugger and stepping through to see what actually happens?
if you can't do that, then try using some tracing statements to see what the values are and where the logic actually flows.
"If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
|
|
|
|
|
(please reformat your code).
Have you use the debugger to check the values and the code flow ?
Watched code never compiles.
|
|
|
|
|