ccalculation of variables
i have three variables
a=100
b="/"
c=5
now i want to calulate as
d = abc && as d = 100 / 5
to get an answer
d=20
any idea how it can be done.
Web Development
i have three variables
a=100
b="/"
c=5
now i want to calulate as
d = abc && as d = 100 / 5
to get an answer
d=20
any idea how it can be done.
by tclere
Using VB:
a = 100
b = "/"
c = 5
Select Case b
Case "/"
d = a / b
Case "*"
d = a * b
Case "-"
d = a - b
Case "+"
d = a + b
End Select
I do not think use the operand in variable format on its own.
by sallo
by royce_blanks
In SQL you would do this like:
declare @a int, @b char(1), @c int, @d int, @cmd varchar(20)
set @a = 100
set @b = '/'
set @c = 5
set @cmd = 'select ' + convert(char(3), @a) + @b + convert(char(1), @c)
exec (@cmd)
by sallo
by sallo
Hi Saleem
There's nothing native in VB to do this, but if you go here
You can get the Microsoft Script Control which has an Eval() function.
To use you first set a reference tothe control - Project | References.
Then
Function Demo(Num1 As String, Num2 As String, Action As String)
Dim sc As ScriptControl
Dim Formula As String
Set sc = New ScriptControl
sc.Language = "vbscript"
Formula = Num1 & Action & Num2
Demo = sc.Eval(Formula)
Set sc = Nothing
End Sub
regards
Ian
by sallo
by sallo
Hi Saleem
There's nothing native in VB to do this, but if you go here
You can get the Microsoft Script Control which has an Eval() function.
To use you first set a reference tothe control - Project | References.
Then
Function Demo(Num1 As String, Num2 As String, Action As String)
Dim sc As ScriptControl
Dim Formula As String
Set sc = New ScriptControl
sc.Language = "vbscript"
Formula = Num1 & Action & Num2
Demo = sc.Eval(Formula)
Set sc = Nothing
End Sub
regards
Ian
by sallo
This discussion is closed to new replies.
Sort by Trending