HELP!!!!!! Vbasic6 
Author Message
 HELP!!!!!! Vbasic6

HELP!!!!!! I need to know how to convert a text string into a formula. This
info is needed badly!!!!!
ANY input from fellow programmers would help allot!

Please send info to:

Thank you
Sean

--
HSI Telecommunications Inc.
Webmaster
Operations Supervisor
Broadband Applications Division
Seattle WA


web page located at
http://www.*-*-*.com/



Mon, 24 Nov 2003 11:04:15 GMT  
 HELP!!!!!! Vbasic6
Some examples would be good.


Quote:
> HELP!!!!!! I need to know how to convert a text string into a formula.
This
> info is needed badly!!!!!
> ANY input from fellow programmers would help allot!

> Please send info to:

> Thank you
> Sean

> --
> HSI Telecommunications Inc.
> Webmaster
> Operations Supervisor
> Broadband Applications Division
> Seattle WA


> web page located at
> http://www.hsi-Telecom.com



Mon, 24 Nov 2003 20:55:24 GMT  
 HELP!!!!!! Vbasic6
?



Quote:
> Some examples would be good.



> > HELP!!!!!! I need to know how to convert a text string into a formula.
> This
> > info is needed badly!!!!!
> > ANY input from fellow programmers would help allot!

> > Please send info to:

> > Thank you
> > Sean

> > --
> > HSI Telecommunications Inc.
> > Webmaster
> > Operations Supervisor
> > Broadband Applications Division
> > Seattle WA


> > web page located at
> > http://www.hsi-Telecom.com



Tue, 25 Nov 2003 05:26:19 GMT  
 HELP!!!!!! Vbasic6
VB Scripting has an Eval function, if that's what you are looking for.
Alternatively, if a function that will evaluate a string containing
mathematical expressions (without variables) will do you then you could use
the following code:

Mike

In a Form:

Private Sub Command1_Click()
Dim Tempstring As String, result As Double, check As Single
Tempstring = Text1.Text
check = e_eval(Tempstring, result)
If check = False Then
MsgBox "Unable to evaluate that expression", 48
Else
Print result
End If
End Sub

. . .  and in a Module:

Option Explicit
Dim e_input As String
Dim e_OrigEval$
Dim e_tok As String
Dim e_spelling As String
Dim e_error As Integer

Private Function e_CurrEval$()
  Dim a$
  a$ = Left$(e_OrigEval$, Len(e_OrigEval$) - Len(e_input))
  e_CurrEval$ = vbCrLf & vbCrLf & "Current Eval String: " _
  & Chr$(171) & " " & a$ & " " & Chr$(187) & vbCrLf & _
  "Remainder: " & Chr$(171) & " " & e_input & " " & Chr$(187)
End Function

Function e_eval(ByVal s As String, Value As Double) As Integer
   e_error = 0
   e_input = s: e_OrigEval$ = s
   Call e_nxt
   Value = e_prs(1)
   If e_tok <> vbNullString And Not e_error Then
     MsgBox "Syntax error, token = ' " + e_spelling + " '" _
    & e_CurrEval$()
     e_error = -1
   End If
   e_eval = Not e_error
End Function

Function e_function(fun As String, arg As Double) As Double
   Dim n As Double
   On Error GoTo FuncError
   Select Case LCase$(fun)
   Case "abs": n = Abs(arg)
   Case "atn": n = Atn(arg)
   Case "cos": n = Cos(arg)
   Case "exp": n = Exp(arg)
   Case "fix": n = Fix(arg)
   Case "int": n = Int(arg)
   Case "log"
     If arg <= 0 Then
       MsgBox "Log of Zero or Negative Number: [" & Str$ _
       (arg) & "]" & e_CurrEval$()
       e_error = -1
     Else
       n = Log(arg)
     End If
   Case "rnd": n = Rnd(arg)
   Case "sgn": n = Sgn(arg)
   Case "sin": n = Sin(arg)
   Case "sqr"
     If arg < 0 Then
MsgBox "Square Root of Negative Number: [" & Str$(arg) & "]" _
      & e_CurrEval$()
       e_error = -1
     Else
       n = Sqr(arg)
     End If
   Case "tan": n = Tan(arg)
   Case Else
      If Not e_error Then
    MsgBox "Undefined function '" + fun + "'" & e_CurrEval$()
         e_error = -1
      End If
   End Select
   e_function = n
FuncExit:
   Exit Function
FuncError:
   MsgBox "Function Error: [ " & fun & " ]" & e_CurrEval$()
   e_error = -1
   Resume FuncExit
End Function

Sub e_match(token As String)
   If Not e_error And e_tok <> token Then
      MsgBox "Expected '" + token + "', got '" + e_spelling _
      + "'" & e_CurrEval$()
      e_error = -1
   End If
   Call e_nxt
End Sub

Sub e_nxt()
   Dim is_keyword As Integer
   Dim C As String
   Dim is_id%
   e_tok = vbNullString
   e_spelling = vbNullString
   Do
      C = Left$(e_input, 1)
      e_input = Mid$(e_input, 2)
Loop While C = " " Or C = Chr$(9) Or C = Chr$(13) Or C = Chr$(10)
   Select Case LCase$(C)
   Case "0" To "9", "."
      e_tok = "num"
      Do
         e_spelling = e_spelling + C
         C = Left$(e_input, 1)
         e_input = Mid$(e_input, 2)
      Loop While (C >= "0" And C <= "9") Or C = "."
      e_input = C + e_input
   Case "a" To "z", "_"
      e_tok = "id"
      Do
         e_spelling = e_spelling + C
         C = LCase$(Left$(e_input, 1))
         e_input = Mid$(e_input, 2)
         is_id% = (C >= "a" And C <= "z")
         is_id% = is_id% Or C = "_" Or (C >= "0" And C <= "9")
      Loop While is_id%
      e_input = C + e_input
      is_keyword = -1
      Select Case LCase$(e_spelling)
         Case "and"
         Case "eqv"
         Case "imp"
         Case "mod"
         Case "not"
         Case "or"
         Case "xor"
         Case Else: is_keyword = 0
      End Select
      If is_keyword Then
         e_tok = LCase$(e_spelling)
      End If
   ' Check for <=, >=, <>.
   Case "<", ">"
      e_tok = C
      C = Left$(e_input, 1)
      If C = "=" Or C = ">" Then
         e_tok = e_tok + C
         e_input = Mid$(e_input, 2)
      End If
   Case Else
      e_tok = C
   End Select
    If e_spelling = vbNullString Then
       e_spelling = e_tok
   End If
End Sub

Function e_prs(p As Integer) As Double
   Dim n As Double, tmp As Double
   Dim fun As String
   If e_tok = "num" Then
      n = Val(e_spelling)
      Call e_nxt
   ElseIf e_tok = "-" Then
      Call e_nxt
      n = -e_prs(11)
   ElseIf e_tok = "not" Then
      Call e_nxt
      n = Not e_prs(6)
   ElseIf e_tok = "(" Then
      Call e_nxt
      n = e_prs(1)
      Call e_match(")")
   ElseIf e_tok = "id" Then
      fun = e_spelling
      Call e_nxt
      Call e_match("(")
      n = e_prs(1)
      Call e_match(")")
      n = e_function(fun, n)
   Else
      If Not e_error Then
    MsgBox "Syntax error, token = '" + e_spelling + "'" & _
         e_CurrEval$()
         e_error = -1
      End If
   End If
Do While Not e_error
  If 0 Then
  ElseIf p <= 11 And e_tok = "^" Then Call e_nxt: n = n ^ e_prs(12)
  ElseIf p <= 10 And e_tok = "*" Then Call e_nxt: n = n * e_prs(11)
  ElseIf p <= 10 And e_tok = "/" Then
   Call e_nxt
   tmp = e_prs(11)
   If tmp = 0 Then
     MsgBox "Division by zero: " & e_CurrEval$()
     e_error = -1
   Else
     n = n / tmp
   End If
  ElseIf p <= 9 And e_tok = "\" Then
    Call e_nxt
    tmp = e_prs(10)
    If tmp = 0 Then
      MsgBox "Division by zero: " & e_CurrEval$()
      e_error = -1
    Else
      n = n \ tmp
    End If
  ElseIf p <= 8 And e_tok = "mod" Then Call e_nxt: n = n Mod e_prs(9)
  ElseIf p <= 7 And e_tok = "+" Then Call e_nxt: n = n + e_prs(8)
  ElseIf p <= 7 And e_tok = "-" Then Call e_nxt: n = n - e_prs(8)
  ElseIf p <= 6 And e_tok = "=" Then Call e_nxt: n = n = e_prs(7)
  ElseIf p <= 6 And e_tok = "<" Then Call e_nxt: n = n < e_prs(7)
  ElseIf p <= 6 And e_tok = ">" Then Call e_nxt: n = n > e_prs(7)
  ElseIf p <= 6 And e_tok = "<>" Then Call e_nxt: n = n <> e_prs(7)
  ElseIf p <= 6 And e_tok = "<=" Then Call e_nxt: n = n <= e_prs(7)
  ElseIf p <= 6 And e_tok = ">=" Then Call e_nxt: n = n >= e_prs(7)
  ElseIf p <= 5 And e_tok = "and" Then Call e_nxt: n = n And e_prs(6)
  ElseIf p <= 4 And e_tok = "or" Then Call e_nxt: n = n Or e_prs(5)
  ElseIf p <= 3 And e_tok = "xor" Then Call e_nxt: n = n Xor e_prs(4)
  ElseIf p <= 2 And e_tok = "eqv" Then Call e_nxt: n = n Eqv e_prs(3)
  ElseIf p <= 1 And e_tok = "imp" Then Call e_nxt: n = n Imp e_prs(2)
  Else
    Exit Do
  End If
 Loop
 e_prs = n
End Function


Quote:
> ?



> > Some examples would be good.



> > > HELP!!!!!! I need to know how to convert a text string into a formula.
> > This
> > > info is needed badly!!!!!
> > > ANY input from fellow programmers would help allot!

> > > Please send info to:

> > > Thank you
> > > Sean

> > > --
> > > HSI Telecommunications Inc.
> > > Webmaster
> > > Operations Supervisor
> > > Broadband Applications Division
> > > Seattle WA


> > > web page located at
> > > http://www.hsi-Telecom.com



Tue, 25 Nov 2003 05:51:54 GMT  
 HELP!!!!!! Vbasic6
Thanks Guys Robert has solved the problem! (he sent us email)
Thanks Again,
Sean


Quote:
> VB Scripting has an Eval function, if that's what you are looking for.
> Alternatively, if a function that will evaluate a string containing
> mathematical expressions (without variables) will do you then you could
use
> the following code:

> Mike

> In a Form:

> Private Sub Command1_Click()
> Dim Tempstring As String, result As Double, check As Single
> Tempstring = Text1.Text
> check = e_eval(Tempstring, result)
> If check = False Then
> MsgBox "Unable to evaluate that expression", 48
> Else
> Print result
> End If
> End Sub

> . . .  and in a Module:

> Option Explicit
> Dim e_input As String
> Dim e_OrigEval$
> Dim e_tok As String
> Dim e_spelling As String
> Dim e_error As Integer

> Private Function e_CurrEval$()
>   Dim a$
>   a$ = Left$(e_OrigEval$, Len(e_OrigEval$) - Len(e_input))
>   e_CurrEval$ = vbCrLf & vbCrLf & "Current Eval String: " _
>   & Chr$(171) & " " & a$ & " " & Chr$(187) & vbCrLf & _
>   "Remainder: " & Chr$(171) & " " & e_input & " " & Chr$(187)
> End Function

> Function e_eval(ByVal s As String, Value As Double) As Integer
>    e_error = 0
>    e_input = s: e_OrigEval$ = s
>    Call e_nxt
>    Value = e_prs(1)
>    If e_tok <> vbNullString And Not e_error Then
>      MsgBox "Syntax error, token = ' " + e_spelling + " '" _
>     & e_CurrEval$()
>      e_error = -1
>    End If
>    e_eval = Not e_error
> End Function

> Function e_function(fun As String, arg As Double) As Double
>    Dim n As Double
>    On Error GoTo FuncError
>    Select Case LCase$(fun)
>    Case "abs": n = Abs(arg)
>    Case "atn": n = Atn(arg)
>    Case "cos": n = Cos(arg)
>    Case "exp": n = Exp(arg)
>    Case "fix": n = Fix(arg)
>    Case "int": n = Int(arg)
>    Case "log"
>      If arg <= 0 Then
>        MsgBox "Log of Zero or Negative Number: [" & Str$ _
>        (arg) & "]" & e_CurrEval$()
>        e_error = -1
>      Else
>        n = Log(arg)
>      End If
>    Case "rnd": n = Rnd(arg)
>    Case "sgn": n = Sgn(arg)
>    Case "sin": n = Sin(arg)
>    Case "sqr"
>      If arg < 0 Then
> MsgBox "Square Root of Negative Number: [" & Str$(arg) & "]" _
>       & e_CurrEval$()
>        e_error = -1
>      Else
>        n = Sqr(arg)
>      End If
>    Case "tan": n = Tan(arg)
>    Case Else
>       If Not e_error Then
>     MsgBox "Undefined function '" + fun + "'" & e_CurrEval$()
>          e_error = -1
>       End If
>    End Select
>    e_function = n
> FuncExit:
>    Exit Function
> FuncError:
>    MsgBox "Function Error: [ " & fun & " ]" & e_CurrEval$()
>    e_error = -1
>    Resume FuncExit
> End Function

> Sub e_match(token As String)
>    If Not e_error And e_tok <> token Then
>       MsgBox "Expected '" + token + "', got '" + e_spelling _
>       + "'" & e_CurrEval$()
>       e_error = -1
>    End If
>    Call e_nxt
> End Sub

> Sub e_nxt()
>    Dim is_keyword As Integer
>    Dim C As String
>    Dim is_id%
>    e_tok = vbNullString
>    e_spelling = vbNullString
>    Do
>       C = Left$(e_input, 1)
>       e_input = Mid$(e_input, 2)
> Loop While C = " " Or C = Chr$(9) Or C = Chr$(13) Or C = Chr$(10)
>    Select Case LCase$(C)
>    Case "0" To "9", "."
>       e_tok = "num"
>       Do
>          e_spelling = e_spelling + C
>          C = Left$(e_input, 1)
>          e_input = Mid$(e_input, 2)
>       Loop While (C >= "0" And C <= "9") Or C = "."
>       e_input = C + e_input
>    Case "a" To "z", "_"
>       e_tok = "id"
>       Do
>          e_spelling = e_spelling + C
>          C = LCase$(Left$(e_input, 1))
>          e_input = Mid$(e_input, 2)
>          is_id% = (C >= "a" And C <= "z")
>          is_id% = is_id% Or C = "_" Or (C >= "0" And C <= "9")
>       Loop While is_id%
>       e_input = C + e_input
>       is_keyword = -1
>       Select Case LCase$(e_spelling)
>          Case "and"
>          Case "eqv"
>          Case "imp"
>          Case "mod"
>          Case "not"
>          Case "or"
>          Case "xor"
>          Case Else: is_keyword = 0
>       End Select
>       If is_keyword Then
>          e_tok = LCase$(e_spelling)
>       End If
>    ' Check for <=, >=, <>.
>    Case "<", ">"
>       e_tok = C
>       C = Left$(e_input, 1)
>       If C = "=" Or C = ">" Then
>          e_tok = e_tok + C
>          e_input = Mid$(e_input, 2)
>       End If
>    Case Else
>       e_tok = C
>    End Select
>     If e_spelling = vbNullString Then
>        e_spelling = e_tok
>    End If
> End Sub

> Function e_prs(p As Integer) As Double
>    Dim n As Double, tmp As Double
>    Dim fun As String
>    If e_tok = "num" Then
>       n = Val(e_spelling)
>       Call e_nxt
>    ElseIf e_tok = "-" Then
>       Call e_nxt
>       n = -e_prs(11)
>    ElseIf e_tok = "not" Then
>       Call e_nxt
>       n = Not e_prs(6)
>    ElseIf e_tok = "(" Then
>       Call e_nxt
>       n = e_prs(1)
>       Call e_match(")")
>    ElseIf e_tok = "id" Then
>       fun = e_spelling
>       Call e_nxt
>       Call e_match("(")
>       n = e_prs(1)
>       Call e_match(")")
>       n = e_function(fun, n)
>    Else
>       If Not e_error Then
>     MsgBox "Syntax error, token = '" + e_spelling + "'" & _
>          e_CurrEval$()
>          e_error = -1
>       End If
>    End If
> Do While Not e_error
>   If 0 Then
>   ElseIf p <= 11 And e_tok = "^" Then Call e_nxt: n = n ^ e_prs(12)
>   ElseIf p <= 10 And e_tok = "*" Then Call e_nxt: n = n * e_prs(11)
>   ElseIf p <= 10 And e_tok = "/" Then
>    Call e_nxt
>    tmp = e_prs(11)
>    If tmp = 0 Then
>      MsgBox "Division by zero: " & e_CurrEval$()
>      e_error = -1
>    Else
>      n = n / tmp
>    End If
>   ElseIf p <= 9 And e_tok = "\" Then
>     Call e_nxt
>     tmp = e_prs(10)
>     If tmp = 0 Then
>       MsgBox "Division by zero: " & e_CurrEval$()
>       e_error = -1
>     Else
>       n = n \ tmp
>     End If
>   ElseIf p <= 8 And e_tok = "mod" Then Call e_nxt: n = n Mod e_prs(9)
>   ElseIf p <= 7 And e_tok = "+" Then Call e_nxt: n = n + e_prs(8)
>   ElseIf p <= 7 And e_tok = "-" Then Call e_nxt: n = n - e_prs(8)
>   ElseIf p <= 6 And e_tok = "=" Then Call e_nxt: n = n = e_prs(7)
>   ElseIf p <= 6 And e_tok = "<" Then Call e_nxt: n = n < e_prs(7)
>   ElseIf p <= 6 And e_tok = ">" Then Call e_nxt: n = n > e_prs(7)
>   ElseIf p <= 6 And e_tok = "<>" Then Call e_nxt: n = n <> e_prs(7)
>   ElseIf p <= 6 And e_tok = "<=" Then Call e_nxt: n = n <= e_prs(7)
>   ElseIf p <= 6 And e_tok = ">=" Then Call e_nxt: n = n >= e_prs(7)
>   ElseIf p <= 5 And e_tok = "and" Then Call e_nxt: n = n And e_prs(6)
>   ElseIf p <= 4 And e_tok = "or" Then Call e_nxt: n = n Or e_prs(5)
>   ElseIf p <= 3 And e_tok = "xor" Then Call e_nxt: n = n Xor e_prs(4)
>   ElseIf p <= 2 And e_tok = "eqv" Then Call e_nxt: n = n Eqv e_prs(3)
>   ElseIf p <= 1 And e_tok = "imp" Then Call e_nxt: n = n Imp e_prs(2)
>   Else
>     Exit Do
>   End If
>  Loop
>  e_prs = n
> End Function



> > ?



> > > Some examples would be good.



> > > > HELP!!!!!! I need to know how to convert a text string into a
formula.
> > > This
> > > > info is needed badly!!!!!
> > > > ANY input from fellow programmers would help allot!

> > > > Please send info to:

> > > > Thank you
> > > > Sean

> > > > --
> > > > HSI Telecommunications Inc.
> > > > Webmaster
> > > > Operations Supervisor
> > > > Broadband Applications Division
> > > > Seattle WA


> > > > web page located at
> > > > http://www.hsi-Telecom.com



Thu, 27 Nov 2003 03:32:34 GMT  
 HELP!!!!!! Vbasic6

Quote:
> Thanks Guys Robert has solved the problem! (he sent us email)
> Thanks Again,
> Sean

. . . and what was the solution? Or is it a secret !

Mike



Thu, 27 Nov 2003 10:54:38 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. MSSQL & VBASIC6

2. VBA to VBasic6.0

3. VBA to VBasic6.0

4. I Want to write a CD Ripper(convert to MP3) in VBasic6 - any clues how it's done

5. help,help,help,help,help,help,help,help,help,help,help,help,help,

6. Help,Help,Help,Help,Help,Help,Help,Help,Help,Help,Help,Help,Help,Help,Help,Help,Help,Help,

7. Help, Help, Help, Help, Help, Help, Help, Help, Help, Help, Help, Help, Help, Help, Help, Help, Help,

8. HELP HELP HELP HELP HELP HELPHELP HELP HELPHELP HELP HELP

9. PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP,

10. HELP HELP HELP HELP HELP HELP HELP HEL P HELP HE LP HELP HELP HEL P HELP HELP

11. Help Help Help Help Help Help !!!!!

12. HELP HELP HELP Set document name of print job from VB HELP HELP HELP

 

 
Powered by phpBB® Forum Software