Recent Posts
HTML | 9 sec ago
None | 35 sec ago
None | 37 sec ago
Make | 42 sec ago
None | 57 sec ago
None | 1 min ago
None | 2 min ago
None | 2 min ago
None | 2 min ago
C | 2 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By KnifeySpooney on the 10th of Feb 2010 12:53:28 AM Download | Raw | Embed | Report
  1. 'Copyright 2010 Jared K (itsjareds@yahoo.com)
  2.  
  3. 'Simple calculator
  4. 'Solves a simple string calculation
  5. 'in form a+b, a-b, a*b, a/b
  6.  
  7. 'This program is free software: you can redistribute it and/or modify
  8. 'it under the terms of the GNU General Public License as published by
  9. 'the Free Software Foundation, either version 3 of the License, or
  10. '(at your option) any later version.
  11.  
  12. 'This program is distributed in the hope that it will be useful,
  13. 'but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. 'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. 'GNU General Public License for more details.
  16.  
  17. 'You should have received a copy of the GNU General Public License
  18. 'along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19.    
  20.     Function simpCalc(ByVal str As String) As Integer
  21.         Dim i As Integer
  22.         Dim idx As Integer
  23.         Dim subs As String
  24.         Dim nums(1) As String ' two numbers to calculate
  25.        Dim opType As Integer = -1 ' 0=add,1=sub,2=mult,3=div
  26.        While str.Length > 0
  27.             idx = IIf(opType > -1, 1, 0) ' returns 1 for index if on second num
  28.            subs = Microsoft.VisualBasic.Left(str, 1)
  29.             If Val(subs) > 0 Then
  30.                 nums(idx) &= subs
  31.             ElseIf idx = 0 Then
  32.                 If (subs = "+") Then
  33.                     opType = 0
  34.                 ElseIf (subs = "-") Then
  35.                     opType = 1
  36.                 ElseIf (subs = "*") Or (subs = "x") Then
  37.                     opType = 2
  38.                 ElseIf (subs = "/") Or (subs = "\") Then
  39.                     opType = 3
  40.                 End If
  41.             Else
  42.                 End While
  43.             End If
  44.         str = str.Substring(1)
  45.         End While
  46.         Select Case (opType)
  47.             Case 0
  48.                 i = Val(nums(0)) + Val(nums(1))
  49.             Case 1
  50.                 i = Val(nums(0)) - Val(nums(1))
  51.             Case 2
  52.                 i = Val(nums(0)) * Val(nums(1))
  53.             Case 3
  54.                 i = Val(nums(0)) / Val(nums(1))
  55.             Case Else
  56.                 i = 0
  57.         End Select
  58.         Me.txtDebug.Text = nums(0) & " " & nums(1)
  59.         Return i
  60.     End Function
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: