IonicWind Software

IWBasic => General Questions => Topic started by: Andy on March 11, 2016, 01:09:03 AM

Title: Percent symbol
Post by: Andy on March 11, 2016, 01:09:03 AM
I was looking at a bit of code that was posted a good while ago, but it has me confusded (an easy thing to accomplish!).

What is the percentage symbol actually doing here... as I can't understand the return values.

I'm using a value of say 20 (decimal), and want the answer in binary (base 2).

I get the following print values....

1 20 2
1 10 2
2 5 2
1 2 2
2 1 2

Whats happening with the 20, 10, 5, 2 and 1??

Confused.
Andy.
???


openconsole
print
print
print " ",ToBase(val("20"),2)
print
print
waitcon
end

Sub ToBase(intValue As Int,Base As Int),String
   Dim result As String
   Dim i As Int
   result = ""
   If (base >= 2) & (base <= 36)
      While intValue > 0
         i = (intValue % base) + 1

         print " values ",i,intvalue,base

         intValue = intValue / base
         result = Mid$("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",i,1)+result
      EndWhile
   EndIf
   
   print
   Return result
EndSub



Title: Re: Percent symbol
Post by: LarryMc on March 11, 2016, 01:41:36 AM
Those print outs are not the answer, they are just the troubleshooting printout.
The answer is 10100.

What is confusing you? The % sign is the MOD operator BTW.
Title: Re: Percent symbol
Post by: LarryMc on March 11, 2016, 01:46:57 AM
I tell you what;
I'll talk you through the whole example going through the entire loop and you'll see how easy it is for any base.

It'll all be in my next post.
Title: Re: Percent symbol
Post by: LarryMc on March 11, 2016, 02:21:51 AM
Since we are dealing in one base at a time we don't need the if statement about our base and we're really just dealing with this while loop:
we're wanting to convert 20 base10 to base2
so we pass inValve=20  and base=2 to the subroutine
   result=""
      While intValue > 0         :1st time here its 20
         i = (intValue % base) + 1      :intValue[20] %base[2] which is 20/2 with no remainder=0+1 so i=1

         print " values ",i,intvalue,base   :1,20,2
                     :what we just solved for was least significant bit of answer
         intValue = intValue / base       :20/2=10
   since i=1 this pass
         result = Mid$("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",i,1)+result
         result="0"
   goto next pass -see below
      EndWhile

      While intValue > 0         :2nd time here its 10
         i = (intValue % base) + 1      :intValue[10] %base[2] which is 10/2 with no remainder=0+1 so i=1

         print " values ",i,intvalue,base   :1,10,2
                     :what we just solved for was 2nd least significant bit of answer
         intValue = intValue / base       :10/2=5
   since i=1 this pass
         result = Mid$("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",i,1)+result
         result="00"
   goto next pass -see below
      EndWhile

      While intValue > 0         :3rd time here its 5
         i = (intValue % base) + 1      :intValue[5] %base[2] which is 5/2 with remainder=1+1 so i=2

         print " values ",i,intvalue,base   :2,5,2
                     :what we just solved for was 3d least significant bit of answer
         intValue = intValue / base       :5/2=2
   since i=2 this pass
         result = Mid$("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",i,1)+result
         result="100"
   goto next pass -see below
      EndWhile

      While intValue > 0         :4th time here its 2
         i = (intValue % base) + 1      :intValue[2] %base[2] which is 2/2 with remainder=0+1 so i=1

         print " values ",i,intvalue,base   :1,1,2
                     :what we just solved for was 4th least significant bit of answer
         intValue = intValue / base       :2/2=1
   since i=1 this pass
         result = Mid$("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",i,1)+result
         result="0100"
   goto next pass -see below
      EndWhile

      While intValue > 0         :5th time here its 1
         i = (intValue % base) + 1      :intValue[1] %base[2] which is 1/2 with remainder=1+1 so i=2

         print " values ",i,intvalue,base   :2,1,2
                     :what we just solved for was 4th least significant bit of answer
         intValue = intValue / base       :1/2=0
   since i=2 this pass
         result = Mid$("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",i,1)+result
         result="10100"
   since intValue is 0 exit loop -see below
      EndWhile
     20 base 10 = 10100 base 2

That should do it if I didn't make a typo
Title: Re: Percent symbol
Post by: Andy on March 11, 2016, 03:55:25 AM
Larry,

Thanks for the detailed and concise answer to that!

So essentially % (mod) is doing this...

11 % 3

3 goes into 11   
3 times (giving 9) - any more and it would be 12 which is greater than 11.

So we take our number (11) and subtract the "sum up" of multiples of 3 (9)
11 - 9 = 2

So 2 is the answer.
( 11 % 3 = 2).

If the mod number - here 4 goes exactly into the original number we get 0 (zero).

12 % 4 = 0

The code is very clever!

Thanks for the Maths lesson Larry!!

Andy.
:)


Title: Re: Percent symbol
Post by: LarryMc on March 11, 2016, 04:30:17 AM
https://en.wikipedia.org/wiki/Modulo_operation
Title: Re: Percent symbol
Post by: Bill-Bo on March 11, 2016, 06:28:07 AM
andy and LarryMc,

I sure do like this program. Plus, LarryMc, your detailed explanation. I have taken the liberty of modifying it to convert decimal numbers to the base 2 to 36. But, for the life of me, I forget the code to give you the chose of running the program again, or not. Could PLEASE help out on that?

Here is what I have done:

openconsole
dim Dec$ as string
dim base as int
print "Convert a decimal number to a base from 2 to 36."
print
input "Enter the decimal number: ", Dec$
input "Enter the base: ", base
print " ",ToBase(val(Dec$),base)
print
print
waitcon
end

Sub ToBase(intValue As Int,Base As Int),String
   Dim result As String
   Dim i As Int
   result = ""
   If (base >= 2) & (base <= 36)
      While intValue > 0
         i = (intValue % base) + 1

         print " values ",i,intvalue,base

         intValue = intValue / base
         result = Mid$("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",i,1)+result
      EndWhile
   EndIf
   
   print
   Return result
EndSub



On an aside. In my programming, I have used binary, decimal, and hexadecimal numbers. And in the old days, even octal. Even with my interest in math, I have not had call to use other than the bases 2, 8, 10, and 16. So, looking at the program, I wondered, andy, why in the MID$ you have 0 thru Z, instead of 0 thru F. After my modification, I played around with some different numbers. I came across decimal 60 to base 35, with a result of 1P. Now I know why.

BTW Shouldn't there be a CLOSECONSOLE? Also, for some reason, when I post the code in the codebox, the keywords are in lower case?

I sure do like it, and I will use it a lot. Just hope, Larry, that you can help me out.

Thanks, again, for a very interesting program,

Bill
Title: Re: Percent symbol
Post by: Andy on March 11, 2016, 07:19:56 AM
Bill,

Thanks for the code, I will have a look at it as soon as I can.

I did not write the code posted, my one brain cell won't let me write something so good.

I was working on converting ascii to hex, and then hex to binary, that's why I was looking at the code I posted hence my question on the percent operator..

Andy.
Title: Re: Percent symbol
Post by: LarryMc on March 11, 2016, 09:32:25 AM
openconsole
dim Dec$ as string
dim base as int
DEF key$:STRING
label start
print "Convert a decimal number to a base from 2 to 36."
print
input "Enter the decimal number: ", Dec$
input "Enter the base: ", base
print " ",ToBase(val(Dec$),base)
print
print

PRINT "Press <Q> to end program"
PRINT "Press any other keys to re-run"
DO
    key$ = INKEY$
UNTIL key$  <> ""
If key$="q" or key$="Q"
CLOSECONSOLE
end
else
cls
goto start
endif


Sub ToBase(intValue As Int,Base As Int),String
   Dim result As String
   Dim i As Int
   result = ""
   If (base >= 2) & (base <= 36)
      While intValue > 0
         i = (intValue % base) + 1

        ' print " values ",i,intvalue,base

         intValue = intValue / base
         result = Mid$("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",i,1)+result
      EndWhile
   EndIf
   
   print
   Return result
EndSub

Title: Re: Percent symbol
Post by: Bill-Bo on March 11, 2016, 10:11:45 AM
LarryMc,

Thanks a lot. Works great.

Bill
Title: Re: Percent symbol
Post by: Andy on March 13, 2016, 07:24:08 AM
Thought I would try this with large decimal numbers, so to do it I have written in a few more functions
to my StringMap library.

I've included the sub routine (commented out) so you can see the difference.

This now also gives me the possibility to add more maths functions and to work with different base numbers.

Have a look, you can give a large number such as 123456789012345 (decimal) etc...

You will see a delay of a few seconds, but remember it does work with large numbers.

Unzip to a folder
Copy the .lib folder to your IWBDev / libs folder
Compile and run

Have fun - please let me know if it works for you or you have a problem.

Thanks as always,
Andy.
:)
Title: Re: Percent symbol
Post by: Bill-Bo on March 13, 2016, 06:11:09 PM
andy,

Something is wrong. I get zeroes for all results.

Hey, I went back and re-ran it. I did decimal 45 to base 2 and got 000001; 60 to base 35, got 00 (should be 1P); back to 45 to base 2 and this time got 00000. If I re-run, it does the same thing. This is weird.

Bill
Title: Re: Percent symbol
Post by: Andy on March 13, 2016, 11:49:17 PM
Bill,

That's very strange....

I ran 45 (dec) to base 2 and got 101101
and  60 (dec) to base 35 and got 1P,
I went back and then did 45 (dec) to base 2 and got 101101 again.

I even downloaded the zip file to a new folder, copied the lib file over to my IWBDev /libs folder, compiled the new downloaded ToBase.iwb and it again worked correctly.

The results are correct on my machine.

I wonder why It's not correct on your machine?  ???

Andy.


Title: Re: Percent symbol
Post by: Andy on March 14, 2016, 04:11:04 AM
Bill,

I found one string which I had not declared ("groan"), and I have amended that in this new zip file.

Could you please download it and have another go.

But that said, the origional program did still work for me with no problems.

Thanks,
Andy.

Title: Re: Percent symbol
Post by: Bill-Bo on March 14, 2016, 06:17:28 AM
andy

I do not understand. It does the same thing. I'm going to try something. Get back with you later.

I'm back. I tried the old inc and lib. No good, would not compile. Reloaded the lib and still would not compile. I reloaded the file LarryMc did for me above. It compile and ran just fine, again.

I have attached the files IWBasic created yesterday when it compiled your update. Also, a screenshot of dec 45 to base 2 being 00001. The Output Window.txt is the error info when I tried to recompile.

Bill
Title: Re: Percent symbol
Post by: Egil on March 14, 2016, 10:56:28 AM
Bill,

First I got the same error message as you, when trying to compile Andy's latest code.
Then I noticed that Andy also included an updated version of the file "StringMap.lib".
When this lib-file was copied into IWB's lib-folder (replacing an older version), the code compiled ok, and produced the same results as in Andy's examples when the exe was run.

Title: Re: Percent symbol
Post by: Bill-Bo on March 14, 2016, 12:45:29 PM
Egil,

Okay, I rebuilt with the new lib. I ran it and it still has the same problem. Just like my attached screenshot. When I close the program and restart, I get all zeroes for everything.

Bill
Title: Re: Percent symbol
Post by: Andy on March 14, 2016, 01:08:40 PM
Egil,

Thanks for checking me (great to hear from you again by the way!).

Bill,

Attached are screenshots from my results - they are correct - I still cannot work out why It's wrong for you.

Andy.
:)
Title: Re: Percent symbol
Post by: Bill-Bo on March 14, 2016, 09:31:47 PM
andy,

I cannot get it to operate properly. I made sure that only the files in your BaseV2.zip were in my IWBDev3 directory. I do not understand what's going on. Why everybody else can compile and run it okay; just me that's having the problems. But the thing is I can load to program above that LarryMc modified for and build and run just fine.

Bill
Title: Re: Percent symbol
Post by: Andy on March 15, 2016, 01:29:28 AM
Bill,

Reading back Egil had the same problem but realised that he was using an old verison of the .lib file.

So I've amended the library file so it can display what version I have set it to (which is currently version 7)

Bill, can we go back to basics please?

1. Please delete StringMap.lib from your C:\Program Files\IWBDev3\Libs folder.
2. Please delete StringMap.inc from your C:\Program Files\IWBDev3\include folder (if it exists there).
3. Create a new folder on your C: drive.
4. Download the attached file to the new folder.
5. Unzip it.
6. Copy the StringMap.lib file to C:\Program Files\IWBDev3\Libs folder.
7. Copy the StringMap.inc file to C:\Program Files\IWBDev3\include folder.
8. Go back to the new folder you created.
9. Compile and run ToBase.iwb

You should see it says - StringMap Library version 7 at the top of the console.

I have followed the above step by step instructions and the program works correctly.

Please let me know how you get on as I would like to understand why you have had problems.

Thanks,
Andy.



 
Title: Re: Percent symbol
Post by: Bill-Bo on March 15, 2016, 06:30:50 AM
andy,

I had already did what you suggested yesterday before my previous post. Here is what I did this morning. You will find this interesting, plus, confusing.

First off, the laptop I currently use is a Windows 8.1 64-bit. I put the zip on one of my memory sticks and put it on one of my other laptops; Windows 7 64-bit. On it I have IWBasic 2.5. I did the program on it and it ran just fine. I copied it to the stick and ran the tobase.exe. It did not work correctly. I restarted my computer and it did the same. So I figure it must be something to do with Windows 8.1.

Bill
Title: Re: Percent symbol
Post by: Andy on March 15, 2016, 06:37:35 AM
Bill,

That's very interesting, thanks for trying out what you did, I know it must have taken some time!!!

I'm on Win 7 32 bit here, it would be interesting to see if whatever it is has been fixed in Windows 10.

Could someone with windows 10 please try it out for me please and let me know.

Also, I wonder why it doesn't work on Win 8.1  ???

I've put a lot of work into my StringMap library, (for my own enjoyment) and for now, I know most users probably don't need it, but I know at some point it will save someone a lot of work - It's becoming almost a language "inside" another one - IWB.

I would edge towards it being a fault with 8.1 rather than IWB - maybe that's why they want everyone to jump to Win 10 now???

Curious!

Thanks,
Andy.
:)
Title: Re: Percent symbol
Post by: Egil on March 15, 2016, 07:54:09 AM
Quote from: Bill-Bo on March 15, 2016, 06:30:50 AM
So I figure it must be something to do with Windows 8.1.

When I bought the 64 bits tabletop I'm using right now, it came with Windows 8.1. None of the code I compiled with IWB, EB or MiniBASIC would ever work. Most of them did compile though, but the EXE-files did not work as expected.
I was told my Micro$oft in Oslo to turn off the UAC. But the only difference was that I then got warnings when trying to run my own programs. And then they "froze".
So I purchased and installed Windows 7 Pro instead, and all my trouble was gone.

Last summer I backed up the Win7 setup, and installed Windows 10 instead. But the result was that the problems I had with Windows 8.1 returned. And in addition none of my multimedia editing software (which I use a lot) would ever work.

So finally I had to roll back the new install, and use Windows 7 instead. Therefore, if they do not fix Windows 10 in such a way  that my homemade programs are accepted by the system, something that I am convinced will NEVER happen, the setup I use right now will be my last Windows system ever.

Now I am exploring how to use Linux instead, and when I find the right language/compiler package, I'll change whithout hesitation because I do not need Micro$soft any more. Or maybe I'll do as my oldest grandson. He has a lot of fun, using a 30 dollars RaspberryPI hooked to a cheap "smart-TV". Doing pretty much the same with that setup as I do with mine 2000 dollars setup.

If anyone contact me by PM, I'll answer and tell them where to put both Micro$oft and their Windows systems.... >:(
Title: Re: Percent symbol
Post by: billhsln on March 15, 2016, 08:45:15 AM
Egil, just curious, what anti-virus program do you use?  I am running windows 10 Pro and have no problems with any of the programs I have written.  I use Eset Nod 32 for my Anti-Virus program and have not had that many problems.  Most of the time when I get the big error, it is due to memory problems (like doing a read into a string variable when I should be using ISTRING defined much larger than 255).  I have also run into it when there was a bug in the program.

Bill
Title: Re: Percent symbol
Post by: Andy on March 15, 2016, 08:54:31 AM
Bill,

Any chance you could download the last zip file and try it for me (BaseVer.zip) ?

It would really help me to understand what works on what and what doesn't.

P.S. I have had problems with Avast A/V myself lately.

Thanks,
Andy.
:)
Title: Re: Percent symbol
Post by: Egil on March 15, 2016, 09:29:03 AM
Quote from: billhsln on March 15, 2016, 08:45:15 AM
Egil, just curious, what anti-virus program do you use?  I am running windows 10 Pro and have no problems with any of the programs I have written.  I use Eset Nod 32 for my Anti-Virus program and have not had that many problems.  Most of the time when I get the big error, it is due to memory problems (like doing a read into a string variable when I should be using ISTRING defined much larger than 255).  I have also run into it when there was a bug in the program.

Bill

I tried Windows 10 Pro, using the Microsoft Live Essentials (same as Microsoft Security Essentials for Windows 7 Pro)  for antivirus protection.
Never had problems with that package when using Windows 7.
The problems I had with win8 and win10, are very common with computers running norwegian language and keyboards. No problems on tablets and smart phones using Windows, but as soon it is used on a regular pc, there are great problems with all programs not sold by Microsoft. 

And still they do not understand why the sales of new operating systems in Norway has dropped more than 75 percent on both Win 8 and Win 10, compared to win 7. Seems it is  difficult for them to understand  that their customers want something that actually works, regardless of who made the program.
Title: Re: Percent symbol
Post by: LarryMc on March 15, 2016, 10:24:11 AM
For the record it works fine on my Win7 Home Premium 64-bit machine compiled in 32 bit mode
And I'm using AVG Free for my anti-virus.
Title: Re: Percent symbol
Post by: Bill-Bo on March 15, 2016, 12:49:19 PM
andy,

It the BaseVer.zip that I did this morning. As in my last post, it would run right in Win 8.1.

I install IWBasic 3.03 on my Win 7 laptop and do my program there. I HATE Win 8.1, and I haven't really heard anyghing great about 10. Another basic I use, QB64, has problems with 10, and lengthy discussions about it. The only reason I don't use my Win 7 laptop much, is a couple years ago, IE and FireFox would no longer connect to the internet.
Even though the Wi-Fi and all that says it is, the two browser will not run. Even after re-installs.

Anyway, I guess it's my other laptop for IWBasic.

I sure appreciate all the help in trying to get this solved.

BTW This is the first program that has done this. Nothing like this, until, andy, you change you subroutine code at the bottom of the program. All previous ones built and ran okay Win 8.1. Win 8.1 must not like that part of the code.

Thanks,

Bill
Title: Re: Percent symbol
Post by: Andy on March 15, 2016, 11:35:08 PM
Hi Bill,

It is strange that this sub routine should cause you problems.

I made available my StringMap calculator not long ago, although It's only a very basic calculator with +, - *, and / functions, these functions are used to create the new SMMod function like this:

1. I take a decimal number say 88
2. Divide 88 by the base number say 3
3. 88 / 3 = 29.333333333333
4. Because 88 / 3 doesn't go exactly (the .33333333 bit) I do the next steps:
5. I take the 29 part of the answer and multiply it by the base
6. 29 * 3 = 87
7. Now take the original decimal number (88) and subtract the multiplication
8. 88 - 87 = 1
9. 1 is the mod of 88 with base 3.

If the division goes exactly (no decimal point) I return a zero.

I found (point 3) that division was quicker than addition - in other words you can accomplish the same thing by counting how many times you can add 3 to itself before the number is greater than 88 - but on very large numbers say 1,000,000,000,000 you can imagine how long it would take simply adding 3 to itself before the number became greater than 1,000,000,000,000.

What still has me really confused is why the StringMap library works with these functions (+,-,*,/) on your machine but the mod sub routine - which is only a combination of these functions does not.

This is the mod sub routine in the library:

sub SMMod(string SMAStringIn,int SMAStringMod),string  
   SMAstringA = ""
   SMAstringB = ""
   SMAstringC = ""
   SMAstringD = ""
   SMAStringA = "0"

   SMcallfrommod = 1

   if SMAStringMod = 0
      return "Cannot modulate by zero."
   endif  

   SMAstringB = ""
   SMAStringB = SMDivideNumBlockX(SMAStringIn,ltrim$(str$(SMAStringMod)))

if instr(SMAStringB,".")
SMAStringC = mid$(SMAStringB,1,instr(SMAStringB,".")-1)
SMAStringD = SMMultiplyNumBlockX(SMAStringC,ltrim$(str$(SMAStringMod)))
SMAStringA = SMSubNumBlockX(SMAStringIn,SMAStringD)
return SMAStringA
else
return "0"
endif

SMcallfrommod = 0

return "0"
endsub


As you can see I'm simply following the above steps to return the mod.

So, the StringMap functions in use in the mod routine are:

SMDivideNumBlockX - divide a number by another one
SMMultiplyNumBlockX - multiply a number by another one
SMSubNumBlockX - subtract a number from another one

Maybe we will never know why it doesn't work on your machine?

I have attached a version of the ToBase program, here I have put the base conversion program in as a local sub routine - I have removed the StringMap mod function call and replaced it with the built in IWB mod function (%) instead.

It would be interesting to see Bill, if this one works on your machine...

If it does - then I am completely lost as to the problem.
If it does not work - then the problem must be in one of the other functions.

BTW - Bill attached is a small guide to try and get your wifi working (Debug.txt) - it may help - you can always PM me for more help if needed.

Thanks,
Andy.




Title: Re: Percent symbol
Post by: Bill-Bo on March 16, 2016, 07:08:22 AM
andy

This worked just fine. BTW I added a couple PRINT statements before the time print out so it'd be two lines down from the result. I will check out the Wi-Fi thing later today or tomorrow.

Thanks very much!!

Bill
Title: Re: Percent symbol
Post by: Andy on March 16, 2016, 07:47:24 AM
Bill,

Glad that worked for you, so some reason your machine does not my mod sub routine - I may never find out why....

Anyway, good look with your wifi, don't forget you can pm me anytime you need help with it.

Andy.
:)
Title: Re: Percent symbol
Post by: Bill-Bo on March 16, 2016, 09:17:30 AM
Andy,

Briefly on the other matter. I tried QtWeb browser (latest is from 2013) and that latest version of Opera. Neither would connect to the internet.

Again, thanks for all the help. And that includes everyone.

Bill
Title: Re: Percent symbol
Post by: LarryMc on March 16, 2016, 04:26:01 PM
Andy,
Just for kicks try relocating your mod code as early in your library file as possible and see if it makes any difference for Bill.
Title: Re: Percent symbol
Post by: Andy on March 17, 2016, 12:55:09 AM
Thanks Larry for that idea.

Bill, I have amended the lib file as Larry suggested - if you want to try it then It's attached here.

I have put in three lines in the .iwb file (lines 37, 38, and 39)

The first print line uses the library completely
The second one uses the library completely - but it is a local sub routine
The third is a local sub routine that uses all the library functions except the mod function

Just comment each one in turn to try.

BTW - Bill, download and setup on your machine Malwarebytes (just google it) - on setup untick "try professional version" - install and run it - if it finds anything - tell it to remove  / quarenteen them.

After that, do the same with Superantispyware - let me know how you get on.

Thanks,
Andy.

Title: Re: Percent symbol
Post by: Bill-Bo on March 17, 2016, 08:54:27 AM
Andy

I installed the new lib and inc. It would build, but it's back to the same old problem (00001 for 45 base 2). I tried the three(3) lines individually. None of the three(3) lines printed anything.

The malware stuff, do you mean my Win 7 machine or my Win 8.1?

Bill
Title: Re: Percent symbol
Post by: Andy on March 17, 2016, 11:31:56 AM
Bill,

I meant for your machine that will not connect to the Internet.

Cannot understand why non of them work. At least the last one should if nothing else, I think something is very wrong on your machine.

All worked for me.  ???

Andy.


Title: Re: Percent symbol
Post by: Bill-Bo on March 17, 2016, 04:29:22 PM
Andy,

I am in the process of restoring my Toshiba 64-bit Vista machine using the recovery disks that came with it. I was luck. I was getting some stuff out of my old house yesterday and found them. I hasn't booted up right in 3 or 4 years. After I get my software back on it, I see what happens there.

Bill
Title: Re: Percent symbol
Post by: Andy on March 18, 2016, 02:18:57 AM
Bill,

I think that is a good idea about the Vista machine.

My PC can dual boot so I dropped into XP and ran the the versions of the .exe file - this is what I found:

1. The fully native .exe that uses all the StringMap functions for the mod exercise produced an error.

45 to base 2 = 101901 (wrong should be 101101)
45 to base 8 = 50 (wrong should be 55)
45 to base 16 = 2D (correct)

2. The .exe file which used the local sub routine (but all StringMap functions) produced the same results.

3. The .exe file which used all the StrngMap functions except the mod (i.e. replaced with the IWB % command) worked.

So the question is why? and why does it work for me on Win7 32 bit?

My XP is also 32 bit.

I decided to try something...

I added these four istrings to the start of the program

istring SMAstringA[5000]
istring SMAstringB[5000]
istring SMAstringC[5000]
istring SMAstringD[5000]

And then added the StringMap mod routine to the iwb code

sub SMLocalMod(string SMAStringIn,int SMAStringMod),string  
   SMAstringA = ""
   SMAstringB = ""
   SMAstringC = ""
   SMAstringD = ""
   SMAStringA = "0"

   if SMAStringMod = 0
      return "Cannot modulate by zero."
   endif  

   label SMaddupagain
   SMAstringB = ""
   SMAStringB = SMDivideNumBlockX(SMAStringIn,ltrim$(str$(SMAStringMod)))

if instr(SMAStringB,".")
SMAStringC = mid$(SMAStringB,1,instr(SMAStringB,".")-1)
SMAStringD = SMMultiplyNumBlockX(SMAStringC,ltrim$(str$(SMAStringMod)))
SMAStringA = SMSubNumBlockX(SMAStringIn,SMAStringD)
return SMAStringA
else
return "0"
endif

return "0"
endsub


I changed the SMDecToBaseLocal to call this local mod routine

SMii = val(SMLocalMod(SMMyStartValue,SMBaseIn))

and compiled an exe.

Now in XP,
45 to base 2 was correct
45 to base 8 was correct
45 to base 16 incorrect
60 to base 35 doesn't print anything

I have checked that all the routines use individual strings and INT's.

I installed IWB (latest version) in XP, copied all the files needed and then re-built the .lib file (native to XP).

Compiled the base program (native to XP) and now get this...
45 to base 2 correct
45 to base 8 incorrect
45 to base 16 correct
60 to base 35 doesn't print anything

I feel like Alice going down the rabbit hole with this one...

Andy.


Title: Re: Percent symbol (Windows 10)
Post by: Andy on March 20, 2016, 05:09:49 AM
Well,

I decided to "upgrade" the laptop (Win7 32 bit) to the new Windows 10 (32 bit) so I could give the library file a go in that.

I found the following:

1. The exe files for the conversion to base (using my library) program works correctly in Win 10.
2. I installed IWB on the laptop, re-created the lib file and exe (in Win 10) - all worked correctly.
3. The lib file tested on the maths functions are running much faster.
4. It took 2.56 minutes to multiply 50 x 50 digits as opposed to nearly 5 minutes.

Bill, it would be interesting to see how you get on in Vista.

Thanks,
Andy.
:)



Title: Re: Percent symbol
Post by: Bill-Bo on March 20, 2016, 09:32:22 AM
Andy,

Finally got around this morning to checking things out on the Vista.

First, I did the older ToBase. For 45 base 2 on the 1st run: 121101. On the 2nd and thereafter: 12112B. 60 base 35: 1P, every time it's supposed to.

Second, I did the BaseBill. Same thing happened.

Now, here's something interesting. The BaseBill has a larger base2.iwb than the previous one. I put the previous base2.iwb on the Vista, but did not change the lib and inc from BaseBill. I built it and It runs just fine. What gives?

Bill
Title: Re: Percent symbol
Post by: Andy on March 20, 2016, 02:45:59 PM
Bill,

Thanks for giving vista a go.

I have access to a vista pc and win 8.1, it will take a couple of days before I can test the program.

All I can say for now is the individual functions of the mod routine (division, addition and subtraction) work okay themselves in XP.

And other functions of the library use these functions together just as the mod function does okay.

I will let you know how I get on when I have the results.

BTW, the basebill.iwb is bigger because it has three sub routines, just for testing purposes.

Thanks,
Andy.
Title: Re: Percent symbol
Post by: Andy on March 21, 2016, 08:01:48 AM
Bill,

I tried all variations I could think of on vista home basic 32 bit today.

I even rebuilt the lib file in vista and recompiled the programs.

They all worked correctly.

Only the XP os was out.

As I said before I am on 32 bit systems, Larry stated it was alright for him on win 7 64 bit compiled in 32 bit mode.

So, what "gives", I don't know?

I will continue testing.

Andy.

Title: Re: Percent symbol
Post by: Andy on March 22, 2016, 10:04:19 AM
Today I tested them in win 8.1 32 bit and again everything was okay.

Andy.
Title: Re: Percent symbol
Post by: Brian on March 22, 2016, 10:54:01 AM
Andy,

I've got a bit lost with the versions - can you post your latest and greatest, please?

Brian
Title: Re: Percent symbol
Post by: Andy on March 23, 2016, 12:48:43 AM
Brian,

Thanks for replying.

Attached is the latest version (aka basebill.zip posted earlier).

In the base2.iwb you will note lines 37, 38, and 39.

Line 37: (SMDecToBase)
Calls the library SMDecToBase function which in turn uses the following internal lirbray subs -

   SMGreaterThanEquals - checks if one number is >= to another number
   SMGreaterThan - checks if one number is > than another number
   SMDivideNumBlockX - divides one number by another number
   SMMod - returns the mod value


Line 38: (SMDecToBaseLocal)
Calls a local version of the SMDecToBase function and uses (calls) all of the above library functions.

Line 39: (SMDecToBaseLocalIWB)
Is the same as line 38, except it does not use the SMMod function - it is replaced with the standard IWB % command.

Now, with the exception of XP - I have tried Windows Vista, 7, 8.1 and 10 (all 32 bit) and line 37 (call to use the native SMDecToBase library function) returns the correct results.

The base2.iwb in this zip file is larger simply so you can experiment between the three calls - i.e. you can comment / uncomment each line in turn for testing purposes.

I would like it if you could have a go and try the following (and this is what you should get):

45 to base 2 = 101101
45 to base 16 = 2D
60 to base 35 = 1P

Thanks,
Andy.




Title: Re: Percent symbol
Post by: Brian on March 23, 2016, 04:53:39 AM
Thanks, Andy,

I will give it a go sometime tonight. For the record, I have Windows 10 64-bit Pro, so anything could happen!

Brian
Title: Re: Percent symbol
Post by: Bill-Bo on March 23, 2016, 11:49:36 AM
Andy,

Here's what happened on the Win 8.1 lap-top:

 45 to base 2 = 000001 (on the 1st run, 000000 on the 2nd)
 45 to base 16 = 00
 60 to base 35 = 00

On the Vista:

 45 to base 2 = 121101 (on the 1st run, 12112B on the 2nd)
 45 to base 16 = 2D
 60 to base 30 = 1P

Bill
Title: Re: Percent symbol
Post by: Andy on March 23, 2016, 12:08:01 PM
Bill,

Thanks for keep trying, I just cannot recreate what you get on vista, 7, 8.1, or win 10.

Just waiting for Brian to send his results in.

Andy.
Title: Re: Percent symbol
Post by: Brian on March 23, 2016, 03:11:22 PM
Andy,

Just tried your code as requested, and can report all three subroutines (in turn)
returned the values you expected

Is that progress for you?

Brian
Title: Re: Percent symbol
Post by: Andy on March 23, 2016, 09:34:34 PM
Brian,

Thanks for testing the mod function.

You get the same correct results as I do, that leaves me with two puzzles:

1. Why does it not work for Bill?
2. Why does it not work in XP, but works on all other operating systems.

On my old XP system, I noticed I still had EB and IWB2.5 installed as well as IWB3.03 - so I found an old hard drive, installed a fresh copy of XP Pro 32 bit.

Installed IWB3.03 and copied all the files I needed to build the StringMap library in XP - which I did.

Drum roll.... it worked correctly in XP!

Attached are the two builds, I used to compare with  - the Win7 lib build is slightly bigger because I put a few print tracers in (which I have now commented out). The Win7 build project produces a String7.lib file which I renamed and I also amended the inc file $use line to match.

Both .exe files (one in each zip file) should produce correct results.

So the XP problem I had was my fault - as I believe you should only have one copy of IWB installed - but I only use XP so infrequently now - I clean forgot about the other EB / IWB versions being there.

That leaves me with the one remaining puzzle - why is Bill not getting correct results when the rest of us are?

Bill - I hope you don't get too fed up with this, as you can see I'm working hard to find ananswer to the above question.

BTW - I started all this around 6am (having woken up at "silly o'clock" - 4.30), It's now about 12:30 - that was some testing!!

Thanks,
Andy.



Title: Re: Percent symbol
Post by: Bill-Bo on March 24, 2016, 08:40:16 AM
Andy,

I have what I believe is good news. From the stringmapBuild7.zip file, on my Win 8.1 lap-top, I ran the basel.exe with correct results. But, to double check that it's not my computer that has the problem in building most of your latter tries, I install the inc and lib files, and re-built. Guess what; runs fine. What do you think?

Bill

P.S. Haven't tried anything on the XP, yet.
Title: Re: Percent symbol
Post by: Andy on March 24, 2016, 09:02:09 AM
Bill,

Thanks for trying that!

Yes that's good news, why we should have had a problem in the first place is beyond me.

The only thing I changed was a rename of one of the Istrings, as that string was holding the return value of the base result. I.e. 101101

I noticed that it was almost like the sub was not running fast enough,  and the sub calling it was not waiting for the result.

I know that statement might not make any logical sense, but that was my gut feeling.

As long as it is working now for you then that makes me pleased.

I will however still experiment, and see if I can now re-create the error and what causes it to happen.

Thanks Bill for all your testing!

Andy.