Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - JohnUKresults

Pages: [1]
1
QB64 Discussion / Maths accuracy
« on: May 26, 2021, 07:18:59 am »
Hi all

Trying to do this (although with figures from an array rather than directly programmed numbers - getting the same result):
Code: QB64: [Select]
  1. finishseconds! = 39818.38
  2. startseconds! = 34200.77
  3. PRINT finishseconds! - startseconds!

I should get 5617.61 but for some reason I'm getting 5617.609.

Why and how can I be sure to get the exact result I need? Should I use a different type of number?

I'm using type ! because the numbers could possibly go up to 86400 (number of seconds in 24 hours) and I need 2 decimal point accuracy (as that's what my timing system outputs).

Is there a better option, or alternatively, how can I make sure the answer always comes back rounded up to 5617.61?

Thanks

2
QB64 Discussion / Dynamic Random Access Field creation
« on: May 24, 2021, 01:38:50 pm »
Hi folks

I'm trying to figure out how to set up a random access file where I don't know the overall record size at the outset.

The purpose is to store a number of times for laps of a race. Each race will have its own number of laps which may be (for example) as few as 3 or as many as 12.

The first couple of fields will be of fixed size (4 characters each) to store a race number and also a record number pointer, to access a linked file. The remaining fields will store an 11 character content, which will be a time down to 2 decimal places, such as 01:14:23.21. However, the program needs to be able to set up the RA file on the fly, depending on the number of laps.

It's simple enough to define the total record size (8 plus (laps*11)) but I'm having a problem getting my head round how to set up the FIELD instruction for the file when I don't know how many separate fields will be within the file.

I could make the record size as big as I might ever need (e.g. 96 for 8 laps or 118 for 10 laps) but that seems a bit inefficient and also won't help if I then get a 20 lap race, without rewriting that part of the program.

Has anyone overcome this sort of problem previously?

I'm sure there's a relatively simple solution staring me in the face. If not, I'll go with the 20 lap option even though I may never get that many....

So you know, the number of laps is fixed at the outset of the program, after user input of the value. It's stored in a variables file so won't change after setup, and is read when that file is opened.

Thanks for your time and any input.

3
QB64 Discussion / Is there some magic about the number 1?
« on: May 14, 2021, 12:31:19 pm »
Hi folks

I have a short piece of code within a large program which is driving me mad!! It works fine if I run it as a stand alone bit of code but not when I have it within the program.

The object of the code is to set up some csv files with fixed data fields, the number and names of the files are "lap" plus the lap number. When I run as the separate little program, it correctly installs lap1, lap2 etc. but when I am running it within the main program, even though the inkeys pause shows the correct file name of lap1 having been strung together, it never opens a lap1 file. Frustratingly, if I set the loop to start at 0 it will open a lap 0, then skip lap1 and go to lap 2 - all subsequent lap files open just fine.

I can't see where it's going wrong. Why should it skip file 1 in the main program?

Ignore all the While inkey$="":wend bits - I just put those in so I could see the variables and file names.

Here are the code snippets - the first is the stand-alone version, modified slightly as it's not using a file name string or looking up in a separate random access file:
Code: QB64: [Select]
  1. REM *** create lap files ***
  2.  
  3. FOR x% = 1 TO 5
  4.     x$ = _TRIM$(STR$(x%))
  5.     PRINT x%, x$: WHILE INKEY$ = "": WEND
  6.     lapfile$ = "c:\race\rrclaps\test2\" + "lap" + x$ + ".csv"
  7.     PRINT lapfile$: WHILE INKEY$ = "": WEND
  8.     filenum% = 10 + x%
  9.     OPEN lapfile$ FOR OUTPUT AS filenum%
  10.     FOR y% = 1 TO 10
  11.         WRITE #filenum%, _TRIM$(STR$(y%)), "00:00:00.000", "00:00:00.000", "00:00:00.000"
  12.     NEXT y%
  13.  
  14. NEXT x%
  15.  
  16.  

This is the same code but within the main program, fil$ being the current file name and laps% being the number of laps to be run. File 5 stores a list of race numbers, test2 is the filename for testing, so it's hard-coded into the short program for clarity, but uses fhe fil$ name to point to the right folder in the main program:
Code: QB64: [Select]
  1.  
  2.             REM *** create lap files ***
  3.             FOR x% = 1 TO laps%
  4.                 x$ = _TRIM$(STR$(x%))
  5.                 PRINT x%, x$: WHILE INKEY$ = "": WEND
  6.                 lapfile$ = "c:\race\rrclaps\" + fil$ + "\" + "lap" + x$ + ".csv"
  7.                 PRINT lapfile$: WHILE INKEY$ = "": WEND
  8.                 filenum% = 10 + x%
  9.                 OPEN lapfile$ FOR OUTPUT AS filenum%
  10.                 FOR y% = 1 TO loaded%
  11.                     GET 5, y%
  12.                     WRITE #filenum%, _TRIM$(num$(1)), "00:00:00.000", "00:00:00.000", "00:00:00.000"
  13.                 NEXT y%
  14.             NEXT x%
  15.  

Anyone got any thoughts?

4
QB64 Discussion / vWatch64
« on: August 24, 2020, 01:26:37 pm »
hi Fellippe

I had a quick look at your vwatch program from your repository.

Malwarebytes viewed it as ransomware and quarantined it when I ran your try-me progam in it! :-(

Very odd!!

5
QB64 Discussion / adding/subtracting times
« on: July 26, 2020, 03:53:07 pm »
Hi

Someone out there must have come across this before.

I need to subtract one time from another, to work out an elspased time.

The times are stored in the format hh:mm:ss.dd so are always the same length (time of day stored to 2 decimal places)

Anyone got some code which can do this?

I'll need to have the result stored in (a) the same format (i.e. to 2 decimal places) and also (b) as a number of seconds rounded up to the next full second (anything after the deimal point rounds up, not just to the nearest second), but I can probably figure that out once I've got the subtraction worked out.

It will save me having to write some convoluted code (as I'm not exactly smart with this stuff)

Many thanks for your time.

John

6
QB64 Discussion / Printing to Zebra thermal printers
« on: July 19, 2020, 11:44:20 am »
Hi.

Anyone had any success printing to Zebra or similar thermal printers from QB64?

I know you can't use printer control codes as in the "olden days of escape characters", but I just want to print some plain text and don't want to spend the best part of £300 on a printer only to find I can't do it!

It's just to do quick printouts for people at race events, to confirm finish times and positions etc, so no fancy graphics required.

Thanks for any tips.

John

7
QB64 Discussion / Long Hex number to decimal
« on: April 06, 2020, 09:31:34 am »
Just starting a small project simply to keep my brain ticking over during lockdown.

To save me reinventing the wheel, does anyone have some code for converting a long hex number (mainly 7 hex digits but optional at 12 digits as well) from hex to decimal?

Also the reverse may prove useful at some point.

I can provide some sample codes to save you making them up if that would help.

Thanks

Pages: [1]