It is currently Thu Apr 27, 2017 5:28 pm



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: ezPenny - simple price/merchant database
Unread postPosted: Wed Mar 08, 2017 1:36 am 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 421
http://laughton.com/basic/programs/appl ... s/ezPenny/

This is just a simple item/merchant/price database that I am using to compare
prices from various stores and online merchants.

It uses only one SQLITE table and is pretty zippy to launch. You can probably replace the AskList$() function with a console SELECT if you want it even faster launching.

It obviously won't account for sales/coupons/inflation/varying sizes etc.. but it is kind of handy for keeping tabs on what you spend for frequently purchased items so you can go back to where you got the lowest price.

You can easily delete each outdated merchant price from inside each item by just tapping on the merchant name.

Image


Report this post
Top
 Profile  
 
 Post subject: Re: ezPenny - simple price/merchant database
Unread postPosted: Wed Mar 15, 2017 5:27 am 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 421
I made some nice changes:

The buttons are randomly colored now for appearance.

I incorporated the Parse() function by brochi, emile and roy into an html Calculator function
for much more useful entry..

I also added a standalone apk for the htmlCalc calculator so that people
can use it as a plugin for numerical entries in their own apps. (One limitation I still have is to learn how to use HTML POST better since the calculator screen redraws after each keypress.)

This is on the Play Store at: https://play.google.com/store/apps/deta ... enny&hl=en

ImageImage


Report this post
Top
 Profile  
 
 Post subject: Re: ezPenny - simple price/merchant database
Unread postPosted: Wed Mar 15, 2017 8:50 am 
Offline
User avatar

Joined: Sat Oct 04, 2014 5:45 am
Posts: 625
Hi Cterp,

The parse() function is a port by Brochi from VB by another. I claim no credit for it.
I however did my own thing with my recursive user function with error checking to
evaluate a math expression as per the code below.
Full listing of my calculator is here https://drive.google.com/open?id=0B0Hng ... FY1dk5wQk0

Usage is : Answer = Eval(Expression$)

Regards
Emile
Code:
INCFILES:
   BUNDLE.CREATE Nr1
   BUNDLE.PUT 1, "ErrMsg", "ok"

   FN.DEF TALLY(Src$, Cnt$)
      n = 1
      While IS_IN(Cnt$, Src$, n) > 0
         n++
      Repeat
      FN.RTN n
   FN.END

   FN.DEF Rinstr(source$, search$, start)
      !Reverse Instr function that also skips between braces   
      nn = start
      If nn > Len(source$) Then nn = Len(source$)-Len(search$)+1
         bopen = 0  % count of opening braces
         bclose = 0 % count of closing braces
         Do
            sign$ = Mid$(source$, nn, Len(search$))
            If (sign$ = search$) & (bopen = bclose) Then FN.RTN nn
            If Left$(sign$,1) = "(" Then bopen++
            If Left$(sign$,1) = ")" Then bclose++
            nn--
         Until (nn <= 0)
      FN.RTN 0
   FN.END

   FN.DEF IsOperator(expr$, op$, nnn)
      If op$ = "+" Then
         If Upper$(Mid$(expr$, nnn-1, 1)) = "E" Then
            If nnn > 2 Then
               If IS_IN(Mid$(expr$, nnn - 2, 1)), "1234567890.") > 0 Then FN.RTN 0
            End If            
         End If
         FN.RTN 1
      End If
   
      If op$ = "-" Then
         If nnn = 1 Then
            !Then it is unary -
            FN.RTN 0
         Else
            sign$ = Left$(expr$, nnn - 1)
            sign$ = Right$(Rtrim$(sign$), 1)
            If IS_IN(sign$, "+-/*^") > 0 Then FN.RTN 0           
            If Upper$(Mid$(expr$, nnn-1, 1)) = "E" & nnn > 2 Then
               If IS_IN(Mid$(expr$, nnn-2, 1), "1234567890.") > 0 Then FN.RTN 0
            End If
         End If
         FN.RTN 1
      End If
   
      !check if E position is operator
      If op$ = "E" | op$ = "e" Then
         If nnn = 1 Then FN.RTN 0
         If nnn = Len(expr$) Then FN.RTN 0
         If INSTR(MID$(expr$, nnn-1, 1), "1234567890.", ) = 0 Then FN.RTN 0
         If INSTR(MID$(expr$, nnn+1, 1), "1234567890.", ) = 0 Then FN.RTN 0
         FN.RTN 1
      End If
      FN.RTN 1
   FN.END

   FN.DEF IsValue(value$)
      For i = 1 to Len(value$)
         sign$ = Upper$(Mid$(value$, i, 1))       
         If IS_IN(sign$, "1234567890.-") = 0 Then FN.RTN 0
         !check for maximum 1 "." in math string
         If sign$ = "." Then               
            If IS_IN(".", value$, i+1) > 0 Then FN.RTN 0
         End If
         !check for correct use of minus: only at position 1
         If sign$ = "-" Then
            If i > 1 Then FN.RTN 0
         End If
      Next
      FN.RTN 1
   FN.END

   FN.DEF Eval(Expression$)
      BUNDLE.PUT 1, "ErrMsg", "ok"
      !just in case ==> remove spaces
      expr$ = REPLACE$(Expression$," ","")

      For n = 1 to 6
         !pick an operator in correct precedance
         operator$ = Mid$("-+*/^E", n, 1)
         pos = Rinstr(Upper$(expr$), operator$, 255)
         While pos > 0
            !Check if operator or unary minus
            If IsOperator(expr$, operator$, pos) > 0 Then

               !Split expression in two parts ==> calculate result
               part1$ = Left$(expr$, pos-1 )
               part2$ = Right$(expr$, Len(expr$)-pos)
               !Check for errors
               If Rtrim$(part1$)="" Then BUNDLE.PUT 1, "ErrMsg", "Syntax Error: Missing Value before operator" : FN.RTN 0
               If Rtrim$(part2$)="" Then BUNDLE.PUT 1, "ErrMsg", "Syntax Error: Missing Value after operator" : FN.RTN 0
               value1 = Eval(part1$)
               value2 = Eval(part2$)

               !return answer with applicable operator
               SW.BEGIN operator$
                  SW.CASE "-" : FN.RTN value1 - value2 : SW.BREAK
                  SW.CASE "+" : FN.RTN value1 + value2 : SW.BREAK
                  SW.CASE "/"
                        If value2 = 0 Then BUNDLE.PUT 1, "ErrMsg", "Syntax Error: Devide by zero" : FN.RTN 0  : SW.BREAK % Error ==> Devide zero
                        FN.RTN  value1 / value2 : SW.BREAK
                  SW.CASE "*" : FN.RTN value1 * value2 : SW.BREAK
                  SW.CASE "^" : FN.RTN value1 ^ value2 : SW.BREAK
                  SW.CASE "E" : FN.RTN value1 * 10 ^ value2 : SW.BREAK
               SW.END
            End If
           
            !Check operator false ==> if another operator is preceding
            If pos > 0 Then pos = Rinstr(Upper$(expr$), operator$, pos-1)
         Repeat
      Next
   
      !Is expression a function
      pos = IS_IN("(", expr$)
   
      If pos > 0 & Right$(expr$,1) = ")" Then
         !get function name ie "SIN COS TAN etc"
         function$ = Ltrim$(Left$(expr$, pos-1))       
         !get expr$ in braces and evaluate
         part2$ = MID$(expr$, pos+1, LEN(expr$)-pos-1)
         value2 = Eval(part2$)       

         SW.BEGIN Upper$(function$)
            SW.CASE ""     : FN.RTN value2 : SW.BREAK               
            SW.CASE "ABS"  : FN.RTN ABS(value2) : SW.BREAK
            SW.CASE "SQRT" : If value2 > 0 Then FN.RTN SQR(value2) : SW.BREAK
                             If value2 < 0 Then BUNDLE.PUT 1, "ErrMsg", "Syntax Error: Value for SQRT to be > 0" : FN.RTN 0 : SW.BREAK
            SW.CASE "SQ"   : FN.RTN (value2*value2) : SW.BREAK
            SW.CASE "LOG"  : FN.RTN LOG10(value2) : SW.BREAK
            SW.CASE "SIN"  : FN.RTN SIN(TORADIANS(value2)) : SW.BREAK
            SW.CASE "COS"  : FN.RTN COS(TORADIANS(value2)) : SW.BREAK
            SW.CASE "TAN"  : FN.RTN TAN(TORADIANS(value2)) : SW.BREAK
            SW.CASE "ASIN" : If value2 < 1 Then : FN.RTN TODEGREES(ASIN(value2)) : SW.BREAK
            SW.CASE "ACOS" : If value2 < 1 Then : FN.RTN TODEGREES(ACOS(value2)) : SW.BREAK
            SW.CASE "ATAN" : If value2 < 1 Then : FN.RTN TODEGREES(ATAN(value2)) : SW.BREAK
            SW.DEFAULT     : BUNDLE.PUT 1, "ErrMsg", "Syntax Error: Functions" : FN.RTN 0 : SW.BREAK
         SW.END
      End If   

      If Len(expr$) > 0 & IsValue(expr$) > 0 Then BUNDLE.PUT 1, "ErrMsg", "ok" : FN.RTN Val(expr$)  % return answer if expr$ is a value

      SW.BEGIN Upper$(expr$)
         SW.CASE "PI"   : FN.RTN 3.141592654
         SW.CASE "E"    : FN.RTN 2.718281828
      SW.END
   
      BUNDLE.PUT 1, "ErrMsg", "Syntax Error: General or unknown"
      FN.RTN 0
   FN.END
RETURN

_________________
Download and tutorial for RFODESIGNER
https://sites.google.com/site/rfodesigner/


Report this post
Top
 Profile  
 
 Post subject: Re: ezPenny - simple price/merchant database
Unread postPosted: Thu Mar 16, 2017 12:40 pm 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 421
Thanks Emile! Yes I think yours is much better. I tried it with the calculator and it works well.

I noticed however that there is a broken DO-UNTIL statement that the new version of BASIC! warned me about:

Code:
FN.DEF Rinstr(source$, search$, start)
  ...
         Do
   ...
            If (sign$ = search$) & (bopen = bclose) Then FN.RTN nn
      ....
         Until (nn <= 0)
      FN.RTN 0
   FN.END


I fixed it like this:

Code:
FN.DEF Rinstr(source$, search$, start)
  ...
         Do
   ...
            If (sign$ = search$) & (bopen = bclose)
            brk=1:D_U BREAK
            ENDIF
      ....
         Until (nn <= 0)
   if brk
    FN.RTN nn
   else
      FN.RTN 0
  endif
   FN.END


Seems to work well now... I put your code as eval.bas along with parse.bas depending on which one people want to use.

I actually used my app yesterday to compare prices of toilet paper per square ft. :lol:


Report this post
Top
 Profile  
 
 Post subject: Re: ezPenny - simple price/merchant database
Unread postPosted: Thu Mar 16, 2017 1:06 pm 
Offline
User avatar

Joined: Sat Oct 04, 2014 5:45 am
Posts: 625
Hi Chris

Thanks for catching that one and the repair of it.
I have not tested it too much. It was just a challenge to get a recursive function to work and I was surprised.
I got the idea from the net some time ago in C.
I then tried to port it but could not get it to work.
Then I just used the base idea and started from scratch. So there could be more flaws :lol:

cterp wrote:
Yes I think yours is much better

Don't know about that but maybe some testing/changing can do the trick

cterp wrote:
I actually used my app yesterday to compare prices of toilet paper per square ft. :lol:

Yes depending on the stomach the price of toilet paper could be a deciding factor hey :lol:

Regards
Emile

_________________
Download and tutorial for RFODESIGNER
https://sites.google.com/site/rfodesigner/


Report this post
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred