study, study, study....PLEASE HELP!

Just starting out? Need help? Post your questions and find answers here.
Uncle B
User
User
Posts: 82
Joined: Mon Jan 12, 2004 11:28 am
Location: the Netherlands

study, study, study....PLEASE HELP!

Post by Uncle B »

Hello again, good evening/morning/afternoon to you all,
using purebasic for a few months now, i finally got into the more difficult programming, so I started to study examples instead of copying the helpfile. a few days ago I found this piece of code on purearea and have been studying it for the last few evenings in a row.

beeing a rookie like me I did learn a lot from it, like how linkedlists work and stuff like that, but this particular piece of code doesn't get to me.

Code: Select all

;-Unpack
;Gepackte Datei aussuchen und wieder entpacken: 
NewList DateienEntpacken.s() ;Liste zum Entpacken erstellen 
Pfad$ = "C:\" 

;Auswahlfenster für die gepackte Datei 
PackDatei$ = OpenFileRequester("Dateien auswählen", Pfad$, "Gepackte Dateien (*.pac)|*.pac", 0) 
If OpenPack(PackDatei$)                                 ;Gepackte Datei öffnen. 
  *SpeicherAdresse = NextPackFile()                     ;Die erste Datei in eine Speicheadresse schreiben. 
  Groesse = PackFileSize()                              ;Die Groesse der Datei feststellen. 
  ;Die Datei auslesen lassen, damit man die Namen der gepackten Dateien erhält und in die Liste schreiben. 
  For Schleife = 1 To Groesse                            
    String$ = PeekS(*SpeicherAdresse, Groesse) 
    Position = FindString(String$, Chr(13), Schleife) 
    AddElement(DateienEntpacken()) 
    Laenge = Position - Schleife 
    DateienEntpacken() = Mid(String$, Schleife, Laenge) 
    Schleife = Schleife + Laenge + 1 
  Next Schleife    
Else 
  End 
EndIf 


now can someone please explain me what is happening behind the scenes here...

e.g.
- what does the "*" mean (*GepackteDatei), think it has something to do whith the memory, but i'm not sure.
- What is happening in the part with the PeekS thing and all that stuff. (The helpfile tells me that i should stay out of there and, believe me, i would if it wasn't nescessary).

the orriginal piece of code at the codearchief is "Files_Pack&UnPack.pb", I also found another one that looked somewhat eazier but all of the comments were in frensh, really can't make sence out of that language, german is allready on the edge..., that one was named "PackUnpack_with-Filenames.pb" by the way...

well i hope i made my point clear here, thanks in advance,

your faithfull student, Bart
:roll:
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

don't let the "*" fool you.. it hasn't got any special function...
we normally just use them to underline that the variable is a pointer
(it contains a memory address to something else, usually given by the "@" sign..)

one thing to note though: "*my_var" is NOT the same variable as "my_var"..
just thought I'd let you know, so you don't go wondering about that...

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

lars, not entirely true, when dealing with structs the * has some effect...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

blueznl wrote:lars, not entirely true, when dealing with structs the * has some effect...
I was trying not to confuse the guy!! :P

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post by freedimension »

LarsG wrote:
blueznl wrote:lars, not entirely true, when dealing with structs the * has some effect...
I was trying not to confuse the guy!! :P
Now you did :twisted:
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

freedimension wrote:
LarsG wrote:
blueznl wrote:lars, not entirely true, when dealing with structs the * has some effect...
I was trying not to confuse the guy!! :P
Now you did :twisted:
I'm evil, ain't I?!? :twisted:

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

When you declare a variable with an '*', it's a pointer, which means it will be always the size of the CPU address mode (4 bytes on 32 bits CPU and 8 bytes on 64 bits one for example). When you attach a structure to a pointer (for example *MyPoint.Point) it allows to access any memory address in a structured way. For example:

Code: Select all

   Point1.Point
   Point2.Point
  *CurrentPoint.Point = @Point1
  *CurrentPoint\x = 10 ; 10 is affected to Point1
  *CurrentPoint.Point = @Point2
  *CurrentPoint\x = 10 ; 10 is affected to Point2
I hope it will help a bit :)
Uncle B
User
User
Posts: 82
Joined: Mon Jan 12, 2004 11:28 am
Location: the Netherlands

Post by Uncle B »

Well thanks for not confusing me, and for the replies so far, time to study again.. :D
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

jo uncle, on my website there's a little sample proggy that shows the difference of structs with real pointers and regular vars
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply