Seite 1 von 2

(Mehr)- oder (Zwei)Dimensionales Array?

Verfasst: 11.08.2005 22:06
von Blackskyliner
[Titel]

Ist das irgendwie machbar?
weil ich will sowas in der arti wie eine Session Bauen....
Ich will die ClientID und einen String in ein 2 Dim. Stopfen...
Damit ich sagen kann wenn Klient 1 dann string "Hallo" und wenn Klient2 dann string "Test?"

Danke für jede Hilfe!

Verfasst: 11.08.2005 22:10
von MVXA
Nutz dafür lieber eine Linked List. 2 Dimensionale Arrays bekommst du mit
[c]Dim Array(2, 2) [/c]hin.

Verfasst: 11.08.2005 22:12
von Blackskyliner
1. Danke
2. Wie verwende ich das 2Dim. Array dann?
3. Wie greife ich dann auf das 2Dim Array zu?
4. LinkedList? wie geht das.... :D

Danke. :allright:

Verfasst: 11.08.2005 22:15
von MVXA
eine mehr dimensionale Array nutzt du wie eine ein dimensionale Array.

Code: Alles auswählen

Dim Array.l(5,5)
Array(0, 2) = 4
Zu den Linked Lists. PB hat auch eine Hilfe, in der sehr viel drine steht.
Ich kann natürlich nicht von dir erwarten, dass du die gesamte Hilfe aus-
wendig kennst aber ab und an mal rein schauen ersparrt dir so manches
Fragen. Hier ein Beispiel aus der Hilfe:

Code: Alles auswählen

;
; ------------------------------------------------------------
;
;   PureBasic - Linked list example file
;
;    (c) 2003 - Fantaisie Software
;
; ------------------------------------------------------------
;

Structure BasicStructure 
    Field1.b
    Field2.w
    Field3.l
EndStructure

Structure ComplexStructure
    Field1.b
   *Basic.BasicStructure              ; Pointer to a BasicStructure object
    Basic2.BasicStructure             ; Creation of the BasicStructure object inside this structure
   *Next.ComplexStructure             ; Pointer to another ComplexStructure object
EndStructure

NewList TestList.BasicStructure()

;
;-------- Add Elements and TestLists --------
;

AddElement(TestList())
TestList()\Field2 = 1

AddElement(TestList())
TestList()\Field2 = 2

AddElement(TestList())
TestList()\Field2 = 3

AddElement(TestList())
TestList()\Field2 = 4

;
;-------- MessageRequester("Number of elements in the list:", Str(TestList()\Field2), 0) --------
;

MessageRequester("Number of elements in the list:", Str(CountList(TestList())), 0)

; First way to list all the elements
;
ResetList(TestList())               ; Reset the list index before the first element.

While NextElement(TestList())       ; Process all the elements...
  MessageRequester("List elements :", "Field2 value : "+Str(TestList()\Field2), 0)
Wend

; Second way, with the help of ForEach
;
ForEach TestList()       ; Process all the elements...
  MessageRequester("List elements :", "Field2 value : "+Str(TestList()\Field2), 0)
Next


SelectElement(TestList(), 2)  ; Go directly to the 3rd element
MessageRequester("3rd Element", "Field2 value : "+Str(TestList()\Field2), 0)


MessageRequester("Linked List - Example", "Finished", 0)

End

Verfasst: 11.08.2005 22:17
von Laurin
Zweidimensionales Array:

Code: Alles auswählen

Dim Array.s(4, 2)

For Wert1 = 1 To 4
  For Wert 2 = 1 To 2
    Array(Wert1, Wert2) = "Wert 1: " + Str(Wert1) + " Wert 2: " + Str(Wert2)
  Next
Next

For Wert1 = 1 To 4
  For Wert 2 = 1 To 2
    Debug Array(Wert1, Wert2)
  Next
Next
Klar?

Verfasst: 11.08.2005 22:24
von Blackskyliner
[edit]
@Laurin: jo das ist einleuchtend
[/edit]
[edit2]
@Laurin: wie sähe das in meinem beispiel aus?
[/edit2]

Versteh ich irgendwie nicht....

also der macht ne struktur.... namens Basic Structure
danach macht der so ne linked list zu der basic structure
danach macht der 4 dinger alle namens Field2 und füllt diese mit werten...
fazit

Field2 => 1

...... wie kann ich dem jetzt aber sagen:

Field2 => 1 => "Hallo"

oder hab ich das jettzt missversanden? :D :freak:

wenn ich das missverstanden hab kann mir dass dann mal einer auf mein obriges beispiel machen?? büdde... ich blick da irgendwie grad nich durch :cry:

Danke.

Verfasst: 11.08.2005 22:45
von MVXA
Du musst dir eine Linked List wie einen Eimer vorstellen.
[c]newlist Eimer.s()[/c]

Wir speichern jetzt mal einen Haufen Namen von Obstsorten in diesem
Eimer. Hier als Beispiel nehmen wir ein Tischtennisball als "Symbol" für
ein Element in der Linked List.
[c]AddElement(Eimer())[/c]
Eimer() representiert bei einer Zuweisung oder bei einer Wertübergabe
immer das aktuelle Element. Ansonsten representiert es die Linked List.

Auf dem Tischtennisball schreiben wir jetzt "Banane" und werfen diesen
in unseren Eimer.
[c]Eimer() = "Banane"[/c]

Das gleiche machen wir dann nochmal mit einem Apfel, einer Traube, einer Ananas und einer Pfirsich.

Code: Alles auswählen

AddElement(Eimer()): Eimer() = "Apfel"
AddElement(Eimer()): Eimer() = "Traube"
AddElement(Eimer()): Eimer() = "Ananas"
AddElement(Eimer()): Eimer() = "Pfirsich"
Jetzt haben wir doch schon eine ganze Menge an Bällen in unserem Eimer.
Um jetzt herauszufinden wie viele Bälle wir haben können wir die Funktion
[c]CountList()[/c] nutzen.

Code: Alles auswählen

Debug "Bälle:" + str(CountList(Eimer())
Um jetzt herauszufinden was auf welchem Ball steht müssen wir jeden
einzelnen Ball aus dem Eimer nehmen und den Wert dann ablesen.

Code: Alles auswählen

ForEach Eimer()
    Debug str(ListIndex(Eimer())) + ": " + Eimer()
Next
Ist doch ein schönes Tutorial geworden :D.

Verfasst: 11.08.2005 22:54
von Blackskyliner
Danke so hab ichs verstanden.... und du hast hinter dem Debug ne Klammer vom Str() vergessen... ist echt reif für das CodeArchiv oder ech ne Robsite Tut! Fünf daumen hoch! :allright: :allright: :allright: :allright: :allright:

Verfasst: 12.08.2005 00:07
von Blackskyliner
Hab das zwar kapiert aber das Funktioniert nicht.... ich will das der das der festen NetworkID zuweist.... hab das nun so gemacht aber der kann trotzdem noch das ausgeben.... ist das ein bug oder was??? PB 3.93 Release
Der Ignoriert entwerder die IF oder ich hab en fehler gemacht...

Code: Alles auswählen

    If Server = #True
      SEvent.l = NetworkServerEvent() 
      If SEvent 
        ClientID.l = NetworkClientID() 
        Select SEvent 
          Case 1  ; When a new client has been connected... 
          Case 4  ; When a client has closed the connection... 
          Default 
            RequestLength.l = ReceiveNetworkData(ClientID, *Buffer, 2000) 
            a$ = PeekS(*Buffer) 
            
            MaxPosition = FindString(a$, Chr(13), 5) 
            Position = FindString(a$, " ", 5) 
            If Position < MaxPosition 
              RequestedFile$ = Mid(a$, 6, Position-5)      ; Automatically remove the leading '/' 
              RequestedFile$ = Trim(RequestedFile$) 
            Else 
              RequestedFile$ = Mid(a$, 6, MaxPosition-5)   ; When a command like 'GET /' is sent.. 
            EndIf 
            
            If RequestedFile$ = "" 
              RequestedFile$ = DefaultPage$ 
            EndIf 
            
            Abschnitt.s = StringField(RequestedFile$, 1, "?")
            
            If Abschnitt = ""
              Abschnitt = "index"
            EndIf 
            
            If ClientLoggedIN = 0;
              
              html_output$ = "<head><meta http-equiv='cache-Control' content='no-cache'><style type='text/css'> input {font-family: verdana, arial, san-serif, helvetica; color: black; font-size: 10;} body {font-family: verdana, arial, san-serif, helvetica; color: black; font-size: 10;} table {font-family: verdana, arial, san-serif, helvetica; color: black; font-size: 10; border-collapse: collapse; border-color: black} td{font-family: verdana, arial, san-serif, helvetica; color: black; font-size: 10; border-collapse: collapse; border-color: black} a:link {text-decoration: none; color: black} a:visited {text-decoration: none; color: black} a:active {text-decoration: none; color: black} a:hover {text-decoration: underline; color: black} </style></head>" + #CRLF$  
              html_output$ = html_output$+"<form action='"+Abschnitt+"' method='post'><table width='100%' height='100%'><tr><td align='center'><table cellpadding='1' cellspacing='1' border='1'><tr bgcolor='#cccccc'><td align='center'>Login</td></tr><tr bgcolor='#cccccc'><td><input name='pw'></td></tr><tr bgcolor='#cccccc'><td align='center'><input type='submit' Value='Login'></td></tr></table></td></tr></table></form>"+ #CRLF$
              
              Post.s = Right(a$, Len(a$)-FindString(a$, #CRLF$+#CRLF$, 1)-3)
              
              
              vorne.s = StringField(Post, 1, "=")
              hinten.s = StringField(Post, 2, "=")
              
              If hinten = "test"
                ClientLoggedIN = 1
                NewList ClientID.l() 
                AddElement(ClientID()): ClientID() = NetworkClientID() 
                
                NewList ClientLoggedIN.l() 
                AddElement(ClientLoggedIN()): ClientLoggedIN() = ClientLoggedIN 
              EndIf
              
              StringLength.l = Len(html_output$)
              
              *FileBuffer   = AllocateMemory(StringLength+200) 
              *BufferOffset = BuildRequestHeader(*FileBuffer, StringLength, "text/html") 
              PokeS(*BufferOffset,html_output$,StringLength)
              
              SendNetworkData(ClientID, *FileBuffer, *BufferOffset-*FileBuffer+StringLength) 
              FreeMemory(*FileBuffer) 
            EndIf
            ;If ClientLoggedIN = 1
            ;  ForEach ClientID() 
            ;    If ClientID
            ;      If ClientLoggedIN() = 1
            ;        LoggedIN = 1
            ;        ClientLoggedIN = 0
            ;      EndIf
            ;    EndIf 
            ;  Next
            ;EndIf
            Debug NetworkClientID()
            
            ;If ClientLoggedIN=1
            ;  ForEach ClientID() 
            
            ;  Next
            ;EndIf 
            If ClientLoggedIN = 1
              ForEach ClientID() 
                
                Debug Str(ListIndex(ClientID())) + ": " + Str(ClientID()) + " - " + Str(ClientLoggedIN())
                Debug Str(NetworkClientID()) +" - "+Str(ClientID())
                
                If NetworkClientID() = ClientID()
                  If ClientLoggedIN() = 1
                    html_output$ = "<head><meta http-equiv='cache-Control' content='no-cache'><style type='text/css'> input {font-family: verdana, arial, san-serif, helvetica; color: black; font-size: 10;} body {font-family: verdana, arial, san-serif, helvetica; color: black; font-size: 10;} table {font-family: verdana, arial, san-serif, helvetica; color: black; font-size: 10; border-collapse: collapse; border-color: black} td{font-family: verdana, arial, san-serif, helvetica; color: black; font-size: 10; border-collapse: collapse; border-color: black} a:link {text-decoration: none; color: black} a:visited {text-decoration: none; color: black} a:active {text-decoration: none; color: black} a:hover {text-decoration: underline; color: black} </style></head>"+ #CRLF$ 
                    
                    Select Abschnitt
                      Case "index"
                        html_output$ = html_output$+"<center>Willkommen auf der Weboberfläche vom BlackMP3-Player Version: 1.1 Beta3"+br$+ #CRLF$
                        html_output$ = html_output$+"<a href='index'>Zum Refreshen bitte hier Klicken</a></center>"+br$+br$+ #CRLF$
                        
                        If Str(Lied) <> Str(0)
                          
                          Post.s = Right(a$, Len(a$)-FindString(a$, #CRLF$+#CRLF$, 1)-3)
                          
                          
                          vorne.s = StringField(Post, 1, "=")
                          hinten.s = StringField(Post, 2, "=")
                          
                          Select vorne
                            Case "item"
                              GetDataAlone.s = StringField(Post, 1, "&")
                              item.s = StringField(GetDataAlone, 2, "=")
                              GetDataAlone.s = StringField(Post, 2, "&")
                              aktion.s = StringField(GetDataAlone, 1, "=")
                              
                              Select aktion
                                Case "del"
                                  GadgetState.l = Val(item)
                                  RemoveGadgetItem(#Playlist, GadgetState)
                                Case "select"
                                  GadgetState.l = Val(item)
                                  SetGadgetState(#Playlist, GadgetState)
                              EndSelect 
                              html_output$ = html_output$+"<meta http-equiv='refresh' content='0; URL=index'> "+ #CRLF$
                            Case "play"
                              Play()
                            Case "stop"
                              Stop()
                            Case "resume"
                              Resume()
                            Case "pause"
                              Pause()
                            Case "close"
                              End
                          EndSelect 
                        EndIf 
                        html_output$ = html_output$+"<table align='center' cellpadding='1' cellspacing='1' border='1'>" + #CRLF$
                        If CountGadgetItems(#Playlist) <> 0
                          html_output$ = html_output$+"<form action='"+Abschnitt+"' method='Post'>"+ #CRLF$
                          html_output$ = html_output$+"<tr bgcolor='#cccccc'><td><Select name='item'>"+ #CRLF$
                          For zaehler=0 To CountGadgetItems(#Playlist)
                            option$ = GetGadgetItemText(#Playlist,zaehler,0)
                            If option$
                              If option$ = Lied
                                html_output$ = html_output$+"<option value='"+Str(zaehler)+"' selected>"+option$+"</option>"+ #CRLF$
                              Else
                                html_output$ = html_output$+"<option value='"+Str(zaehler)+"'>"+option$+"</option>"+ #CRLF$
                              EndIf
                            EndIf 
                          Next 
                          html_output$ = html_output$+"</select>"+ #CRLF$
                          html_output$ = html_output$+"<input type='submit' name='select' Value='Auswählen'><input type='submit' name='del' Value='Delete'></td></tr></form>"+ #CRLF$
                        EndIf 
                        If Play
                          ;lied$ = GetGadgetItemText(#Playlist,CurrentPlayLied,0)
                          doppelt$ = Chr(34)
                          ;html_output$ = html_output$+"Zurzeit wird ist das Lied: "+lied$+" gespielt."+br$
                          html_output$ = html_output$+"<tr bgcolor='#cccccc'><td align='center'><input type='text' size='9' readonly value='"+PositionAudioZTime(Current)+"'><input type='text' size='9' readonly value='"+PositionAudioZTime(Total)+"'></td></tr>"+ #CRLF$
                        EndIf
                        If CountGadgetItems(#Playlist) <> 0
                          html_output$ = html_output$+"<form action='"+Abschnitt+"' method='post'><tr bgcolor='#cccccc'><td align='center'>"+ #CRLF$
                          html_output$ = html_output$+"<input type='submit' value='Play' name='play'><input type='submit' value='Pause' name='pause'><input name='resume' value='Resume' type='submit'><input name='stop' value='Stop' type='submit'>"+ #CRLF$
                          html_output$ = html_output$+"</td></tr></table></form>"+ #CRLF$
                        EndIf 
                        If CountGadgetItems(#Playlist) = 0
                          html_output$ = html_output$+"<tr bgcolor='#cccccc'><td align='center'>Sie müssen erst mindestens ein Lied laden.</td></tr></table>"+ #CRLF$
                        EndIf
                    EndSelect 
                    
                    ;SEND$ = Str(1)
                    ;EndIf
                  EndIf
                EndIf 
              Next 
              StringLength.l = Len(html_output$)
              
              *FileBuffer   = AllocateMemory(StringLength+200) 
              *BufferOffset = BuildRequestHeader(*FileBuffer, StringLength, "text/html") 
              PokeS(*BufferOffset,html_output$,StringLength)
              
              SendNetworkData(ClientID, *FileBuffer, *BufferOffset-*FileBuffer+StringLength) 
              FreeMemory(*FileBuffer) 
            EndIf 
            
        EndSelect 
      EndIf 
    EndIf
wäre cool wenn da einer den fehler findet.....

Verfasst: 12.08.2005 00:18
von Green Snake
@MVXA

cooles tut, ich gebe dir da 6 daumen hoch ;)
:allright: :allright: :allright: :allright: :allright: :allright:



zum thema
ömmmm
das is ja ein relativ "grosser" code......aber er intressiert mich
*gleichmalanschau*