PlanetSquires Forums
Support Forums => WinFBE - Code Editor and Visual Designer => Topic started by: veltesian on August 18, 2020, 09:25:14 AM
-
hello everyone ....
is there any chance someone could let me know how to get 2 text boxes or labels to
calculate simple math such as addition, subtraction, multiplication & division. i have
included an upload but its flawed.... it seems to always be some error SNAG that will
keep me from truely completing most projects.
-
I would suggest you single step through the calculation, assigning a variable for each value e.g. dim c as string c=cdbl(form1.text1.text You can then see where is fails, in which conversion. afaik cdbl is not a 2 way conversion, although the description sort of implies it.
-
Hi veltesian, Try this:
Function Form1_Button1_Click( ByRef sender As wfxButton, ByRef e As EventArgs ) As LRESULT
Dim v1 As Double = CDbl(Trim(Form1.t1.text)) ' Declare and assign
Dim v2 As Double = CDbl(Trim(Form1.t2.text))
Form1.Text = Str(v1 + v2) ' Convert sum to String
Function = 0
End Function
-
a super big thanks goes out to SeaVipe & raymw for their help ... it is VERY appreciated. thank you * 1,000,000
-
Loooong ago, I used the Eval() function in msscript.ocx. Basically you could feed it any math formula and it would return the outcome. I googled a bit and it seems it can still be used, but I did not dive into the details. If you want I can try te reconstruct how I used it.
-
hello wilko
i'm not even sure if *.ocx modules are/would be compatible with winfbe unless if it were converted
to winfbe's programming code & basically if one would recreate the msscript.ocx as per winfbe
standards? that would be great. i would certainly be interested in checking it out.... so now if
i could figure out how to link 2 GUI forms together ( parent/child ) that would be nice!! theres
many programmatic type ideas/PRJs i would like to complete/figure out.
-
Hi, I also have no idea whether you can use .ocx in FreeBasic. I guess José knows. Or Google. The code is used in VB was like this:
Set SC = CreateObject("ScriptControl")
SC.Language = "VBScript"
ResultOfCalculation = SC.Eval(StringToTest$)
Set SC = Nothing
and if I remember well the string had to be something between brackets like
StringToTest="(3*4)".
Maybe this helps.
-
The main problem with these olf VB6 .ocx is that they only work with 32 bit.
-
I have got it working, but using an old copy of msscript.ocx that did came with VB6 (in my Windows 10 system, there is a registered one in C:\Windows\SysWOW64\msscript.ocx, but for some reason unknown to me it it doesn't work).
'#CONSOLE ON
#define UNICODE
#INCLUDE ONCE "windows.bi"
#include once "Afx/AfxCOM.inc"
#include once "Afx/CVAR.inc"
using Afx
' // Dual interfaces - Forward references
TYPE IScriptControl AS IScriptControl_
CONST CLSID_ScriptControl = "{0E59F1D5-1FBE-11D0-8FF2-00A0D10038BC}"
CONST IID_IScriptControl = "{0E59F1D3-1FBE-11D0-8FF2-00A0D10038BC}"
' ########################################################################################
' Interface name: IScriptControl
' IID: {0E59F1D3-1FBE-11D0-8FF2-00A0D10038BC}
' Documentation string: Control to host scripting engines that understand the ActiveX Scripting interface
' Attributes = 4304 [&h000010D0] [Hidden] [Dual] [Nonextensible] [Dispatchable]
' Inherited interface = IDispatch
' Number of methods = 30
' ########################################################################################
#ifndef __IScriptControl_INTERFACE_DEFINED__
#define __IScriptControl_INTERFACE_DEFINED__
TYPE IScriptControlVTbl
QueryInterface AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL riid AS CONST IID CONST PTR, BYVAL ppvObj AS ANY PTR PTR) AS HRESULT
AddRef AS FUNCTION (BYVAL this AS IScriptControl PTR) AS ULONG
Release AS FUNCTION (BYVAL this AS IScriptControl PTR) AS ULONG
GetTypeInfoCount AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL pctinfo AS UINT PTR) AS HRESULT
GetTypeInfo AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL iTInfo AS UINT, BYVAL lcid AS LCID, BYVAL ppTInfo AS ITypeInfo PTR PTR) AS HRESULT
GetIDsOfNames AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL iTInfo AS UINT, BYVAL lcid AS LCID, BYVAL ppTInfo AS ITypeInfo PTR PTR) AS HRESULT
Invoke AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL dispIdMember AS DISPID, BYVAL riid AS CONST IID CONST PTR, BYVAL lcid AS LCID, BYVAL wFlags AS WORD, BYVAL pDispParams AS DISPPARAMS PTR, BYVAL pVarResult AS VARIANT PTR, BYVAL pExcepInfo AS EXCEPINFO PTR, BYVAL puArgErr AS UINT PTR) AS HRESULT
get_Language AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL rhs AS BSTR PTR) AS HRESULT
put_Language AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL rhs AS BSTR PTR) AS HRESULT
get_State AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL rhs AS ANY PTR) AS HRESULT
put_State AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL rhs AS ANY PTR) AS HRESULT
put_SitehWnd AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL rhs AS LONG) AS HRESULT
get_SitehWnd AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL rhs AS LONG PTR) AS HRESULT
get_Timeout AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL rhs AS LONG PTR) AS HRESULT
put_Timeout AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL rhs AS LONG) AS HRESULT
get_AllowUI AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL rhs AS VARIANT_BOOL PTR) AS HRESULT
put_AllowUI AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL rhs AS VARIANT_BOOL) AS HRESULT
get_UseSafeSubset AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL rhs AS VARIANT_BOOL PTR) AS HRESULT
put_UseSafeSubset AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL rhs AS VARIANT_BOOL) AS HRESULT
get_Modules AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL rhs AS ANY PTR PTR) AS HRESULT
get_Error AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL rhs AS ANY PTR PTR) AS HRESULT
get_CodeObject AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL rhs AS ANY PTR) AS HRESULT
get_Procedures AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL rhs AS ANY PTR PTR) AS HRESULT
_AboutBox AS FUNCTION (BYVAL this AS IScriptControl PTR) AS HRESULT
AddObject AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL Name AS BSTR, BYVAL Object AS ANY PTR, BYVAL AddMembers AS VARIANT_BOOL = 0) AS HRESULT
Reset AS FUNCTION (BYVAL this AS IScriptControl PTR) AS HRESULT
AddCode AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL Code AS BSTR) AS HRESULT
Eval AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL Expression AS BSTR, BYVAL rhs AS VARIANT PTR) AS HRESULT
ExecuteStatement AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL Statement AS BSTR) AS HRESULT
Run AS FUNCTION (BYVAL this AS IScriptControl PTR, BYVAL ProcedureName AS BSTR, BYVAL Parameters AS ANY PTR, BYVAL rhs AS VARIANT PTR) AS HRESULT
END TYPE
TYPE IScriptControl_
lpVtbl AS IScriptControlVTbl PTR
END TYPE
' ########################################################################################
#endif
CoInitialize(NULL)
DIM pSC AS IScriptControl PTR
'pSC = AfxNewCom("MSScriptControl.ScriptControl") ' The installed msscript.ocx in Win10 does not work
pSC = AfxNewCom(Exepath & "\" & "msscript.ocx", CLSID_ScriptControl, IID_IScriptControl)
IF pSC = NULL THEN END
DIM hr AS HRESULT
DIM cbsLanguage AS CBSTR = "VBScript"
hr = pSC->lpVtbl->put_Language(pSC, cbsLanguage)
DIM cvRes AS CVAR
DIM cbsExpr AS CBSTR = "(3*4)"
hr = pSC->lpVtbl->Eval(pSC, cbsExpr, cvRes.vptr)
print cvRes
AfxSafeRelease(pSC)
CoUninitialize
PRINT
PRINT "Press any key..."
SLEEP
-
hello José Roca
I changed pSC = AfxNewCom(Exepath & "\" & "msscript.ocx", CLSID_ScriptControl, IID_IScriptControl)
to pSC = AfxNewCom("msscript.ocx", CLSID_ScriptControl, IID_IScriptControl)
and it works, but as you said only on 32-bit
-
Does this help?
https://social.msdn.microsoft.com/Forums/en-US/7b04ca15-7139-433a-ad3c-934a02175a5b/msscriptocx-with-64-bit-platforms (https://social.msdn.microsoft.com/Forums/en-US/7b04ca15-7139-433a-ad3c-934a02175a5b/msscriptocx-with-64-bit-platforms)
They claim ( at the end) they got it working. Did not test it myself. And at this website they present an alternative for the msscript.ocx:
https://helloacm.com/inconsistent-behavior-of-scriptcontrol-64-bit-to-the-msscript-ocx/ (https://helloacm.com/inconsistent-behavior-of-scriptcontrol-64-bit-to-the-msscript-ocx/)
Did not dive into the details.