PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: question about doing simple math...  (Read 419 times)

veltesian

  • Little Newbie
  • *
  • Posts: 47
question about doing simple math...
« 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.
« Last Edit: August 18, 2020, 11:14:58 PM by veltesian »
Logged

raymw

  • Senior Member
  • ***
  • Posts: 409
Re: question about doing simple math...
« Reply #1 on: August 18, 2020, 11:14:33 AM »

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.
Logged

SeaVipe

  • Senior Member
  • ***
  • Posts: 369
  • Windows 10
Re: question about doing simple math...
« Reply #2 on: August 18, 2020, 01:31:04 PM »

Hi veltesian, Try this:
Code: [Select]
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
Logged
Clive Richey
*“You Either Have To Be Part Of The Solution, Or You’re Going To Be Part The Problem.” Eldridge Cleaver.
#StaySafe, Always  Keep A Safe #SocialDistance, #WashYourHands Often and please, #StayHome!

veltesian

  • Little Newbie
  • *
  • Posts: 47
Re: question about doing simple math...
« Reply #3 on: August 18, 2020, 01:53:42 PM »

a super big thanks goes out to SeaVipe & raymw for their help ... it is VERY appreciated. thank you * 1,000,000
Logged

Wilko Verweij

  • Junior Member
  • **
  • Posts: 166
  • PB10 - FF3.7 User; Win 10
    • CHEAQS
Re: question about doing simple math...
« Reply #4 on: August 18, 2020, 06:22:30 PM »

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.
Logged

veltesian

  • Little Newbie
  • *
  • Posts: 47
Re: question about doing simple math...
« Reply #5 on: August 18, 2020, 09:50:07 PM »

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.
« Last Edit: August 19, 2020, 01:32:25 AM by veltesian »
Logged

Wilko Verweij

  • Junior Member
  • **
  • Posts: 166
  • PB10 - FF3.7 User; Win 10
    • CHEAQS
Re: question about doing simple math...
« Reply #6 on: August 19, 2020, 04:25:14 PM »

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:
Code: [Select]
      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.
Logged

José Roca

  • Guru Member
  • *****
  • Posts: 3282
Re: question about doing simple math...
« Reply #7 on: August 19, 2020, 06:05:06 PM »

The main problem with these olf VB6 .ocx is that they only work with 32 bit.

José Roca

  • Guru Member
  • *****
  • Posts: 3282
Re: question about doing simple math...
« Reply #8 on: August 19, 2020, 08:56:05 PM »

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).

Code: [Select]
'#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

Johan Klassen

  • Junior Member
  • **
  • Posts: 107
  • FF3 User
Re: question about doing simple math...
« Reply #9 on: August 19, 2020, 09:24:39 PM »

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
« Last Edit: August 19, 2020, 09:26:13 PM by Johan Klassen »
Logged

Wilko Verweij

  • Junior Member
  • **
  • Posts: 166
  • PB10 - FF3.7 User; Win 10
    • CHEAQS
Re: question about doing simple math...
« Reply #10 on: August 20, 2020, 05:06:57 PM »

Does this help?

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/

 Did not dive into the details.
Logged