my WEAK LOGIC

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by TronDoc.

I know this is my fault;
I'm sure a problem with
nesting my loops:

For each value in array DAIZ$(DAYS)
I need to compare it to four bytes
in file 365A.txt and if found
print the offset where
it was found.

My poor logic included below keeps
getting stuck in the REPEAT:UNTIL
loop... I also tried WHILE:WEND
using instead of = with
similar bad results.

help?

Code: Select all

DAYS = 366
Dim DAIZ$(DAYS)
Dim OffSet$(DAYS)
CR$ = Chr(13)      ;define a carriage return
LF$ = Chr(10)      ;define a line feed
CRLF$ = CR$ + LF$  ;doi
SP$ = Chr(32)      ;define a space
EXC$ = "!"

OpenConsole()
;Print ("today?")
;today$= Input()

If ReadFile(0, "365A.TXT")

  Offset=0
  FileSeek(Offset)
  While Offset 

elecTRONics DOCtor
{registeredPB}
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by El_Choni.

I'm not sure, but maybe offset should be increased by four instead of one? Would need the txt file to figure something else.

Bye,

El_Choni
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

Code: Select all

Dim OffSet$(DAYS)
I thought OffSet should be a number,
not a string.
A simple "Offset.l" will do it...
no DIM needed here.

Code: Select all

    For DAY = 1 To 366
      Read DAIZ$(DAY)
      Repeat
        FileSeek(Offset)
        byte1 = ReadByte()
        byte2 = ReadByte()
        byte3 = ReadByte()
        byte4 = ReadByte()
        all$=Chr(byte1)+Chr(byte2)+Chr(byte3)+Chr(byte4)
        Offset = Offset + 1
      Until DAIZ$(DAY)=all$
1st Loop:
Offset is 0, Day is 1

1.) You read a string (for example "0001")
2.) You set offset again to 0
3.) You read 4 bytes and combine it into the string all$

Now it looks like DAIZ$(1) and all$ are the same, so
Until DAIZ$(DAY)=all$
exits here and the program is over.

cya,
...Danilo


(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Pupil.

You should probably include one more condition in your repeat:until loop in case something goes wrong...

Code: Select all

Repeat
  ...
Until DAIZ$(DAY)=all$ Or Offset=Lof()-4
This will prevent you application to go into an endless loop if the searched value isn't found in your file.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by TronDoc.
You should probably include one more condition in your repeat:until loop in case something goes wrong...

Code: Select all

Repeat
  ...
Until DAIZ$(DAY)=all$ Or Offset=Lof()-4
This will prevent you application to go into an endless loop if the searched value isn't found in your file.
Pupil: I thought you had the answer when I read your post...
...but I tried it and it didn't help. Thanks for trying...

I GOT IT !!!! Until DAIZ$(DAY)=all$ Or Offset>=Lof()-4
{notice the > sign!?} Thanks Pupil! -jb

Edited by - TronDoc on 14 February 2002 02:36:24
Post Reply